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)
This commit is contained in:
Matilda Landström
2025-11-26 12:13:04 +00:00
parent 086319e8b1
commit 26f3b5bdd0
6 changed files with 173 additions and 38 deletions

View File

@@ -1,38 +1,27 @@
"use client"
import { useRouter } from "next/navigation"
import { useIntl } from "react-intl"
import { toast } from "@scandic-hotels/design-system/Toast"
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 intl = useIntl()
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()
setTimeout(() => {
toast.success(
intl.formatMessage({
id: "profilingConsent.alert.updateConsentSuccessful",
defaultMessage: "Preference saved!",
})
)
})
setAlertType(AlertTypeEnum.Success)
},
onError: () => {
setTimeout(() => {
toast.error(
intl.formatMessage({
id: "profilingConsent.alert.updateConsentFailed",
defaultMessage:
"An error occurred when updating preferences, please try again later.",
})
)
})
setAlertType(AlertTypeEnum.Alarm)
},
})