feat(LOY-484): Change toast to alert for Profiling Consent * feat(LOY-484): change toast to alert using context * refactor(LOY-484): remove uneccesary code * chore(LOY-484): small UI fixes Approved-by: Chuma Mcphoy (We Ahead)
39 lines
1011 B
TypeScript
39 lines
1011 B
TypeScript
"use client"
|
|
|
|
import { useRouter } from "next/navigation"
|
|
|
|
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
|
import { trpc } from "@scandic-hotels/trpc/client"
|
|
|
|
import { useProfilingConsentAlert } from "@/components/MyPages/ProfilingConsent/Alert/AlertContext"
|
|
|
|
export function useUpdateProfilingConsent() {
|
|
const utils = trpc.useUtils()
|
|
const router = useRouter()
|
|
|
|
const { setAlertType } = useProfilingConsentAlert()
|
|
|
|
const updateConsent = trpc.user.profilingConsent.update.useMutation({
|
|
onSuccess: async () => {
|
|
await utils.user.get.invalidate()
|
|
router.refresh()
|
|
setAlertType(AlertTypeEnum.Success)
|
|
},
|
|
|
|
onError: () => {
|
|
setAlertType(AlertTypeEnum.Alarm)
|
|
},
|
|
})
|
|
|
|
const initiateUpdateConsent = (consent: boolean) => {
|
|
updateConsent.mutate({ profilingConsent: consent })
|
|
}
|
|
|
|
return {
|
|
initiateUpdateConsent,
|
|
isLoading: updateConsent.isPending,
|
|
isSuccess: updateConsent.isSuccess,
|
|
isError: updateConsent.isError,
|
|
}
|
|
}
|