Files
web/apps/scandic-web/hooks/useUpdateProfilingConsent.ts
Matilda Landström 26f3b5bdd0 Merged in feat/LOY-484-consent-alert (pull request #3184)
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)
2025-11-26 12:13:04 +00:00

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,
}
}