Merged in feat/SW-1997-tracking-gla-my-stay-ancillaries (pull request #1657)
Feat/SW-1997 tracking gla my stay ancillaries * feat(SW-1996): tracking gla my stay * feat(SW-1996): update gla tracking * feat(SW-1996): fix comment * feat(SW-1997): add tracking for gla my stay and ancillaries * feat(SW-1997): rebase master * feat(SW-1997): fix duplicate import * feat(SW-1997): add hotelId and category for ancillaries, and add more tracking * feat(SW-1997): remove commments and fix spelling mistake * feat(SW-1997): if addAncillary failed, but guarantee is successful, default to card in booking Approved-by: Niclas Edenvin
This commit is contained in:
@@ -6,8 +6,16 @@ import { useEffect } from "react"
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import {
|
||||
trackAncillaryFailed,
|
||||
trackAncillarySuccess,
|
||||
} from "@/utils/tracking/myStay"
|
||||
|
||||
import { clearAncillarySessionData, getAncillarySessionData } from "../utils"
|
||||
import {
|
||||
buildAncillaryPackages,
|
||||
clearAncillarySessionData,
|
||||
getAncillarySessionData,
|
||||
} from "../utils"
|
||||
|
||||
import type { Lang } from "@/constants/languages"
|
||||
|
||||
@@ -22,15 +30,7 @@ export default function GuaranteeAncillaryHandler({
|
||||
}) {
|
||||
const router = useRouter()
|
||||
|
||||
const addAncillary = trpc.booking.packages.useMutation({
|
||||
onSuccess: () => {
|
||||
clearAncillarySessionData()
|
||||
router.replace(returnUrl)
|
||||
},
|
||||
onError: () => {
|
||||
router.replace(`${returnUrl}&errorCode=AncillaryFailed`)
|
||||
},
|
||||
})
|
||||
const addAncillary = trpc.booking.packages.useMutation()
|
||||
|
||||
useEffect(() => {
|
||||
if (addAncillary.isPending || addAncillary.submittedAt) {
|
||||
@@ -44,33 +44,49 @@ export default function GuaranteeAncillaryHandler({
|
||||
}
|
||||
|
||||
const { formData, selectedAncillary } = sessionData
|
||||
const packages = []
|
||||
const packages = buildAncillaryPackages(formData, selectedAncillary)
|
||||
|
||||
if (selectedAncillary?.id && formData.quantityWithCard) {
|
||||
packages.push({
|
||||
code: selectedAncillary.id,
|
||||
quantity: formData.quantityWithCard,
|
||||
comment: formData.optionalText || undefined,
|
||||
})
|
||||
}
|
||||
|
||||
if (selectedAncillary?.loyaltyCode && formData.quantityWithPoints) {
|
||||
packages.push({
|
||||
code: selectedAncillary.loyaltyCode,
|
||||
quantity: formData.quantityWithPoints,
|
||||
comment: formData.optionalText || undefined,
|
||||
})
|
||||
}
|
||||
|
||||
addAncillary.mutate({
|
||||
confirmationNumber,
|
||||
ancillaryComment: formData.optionalText,
|
||||
ancillaryDeliveryTime: selectedAncillary.requiresDeliveryTime
|
||||
? formData.deliveryTime
|
||||
: undefined,
|
||||
packages,
|
||||
language: lang,
|
||||
})
|
||||
addAncillary.mutate(
|
||||
{
|
||||
confirmationNumber,
|
||||
ancillaryComment: formData.optionalText,
|
||||
ancillaryDeliveryTime: selectedAncillary.requiresDeliveryTime
|
||||
? formData.deliveryTime
|
||||
: undefined,
|
||||
packages,
|
||||
language: lang,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if (data) {
|
||||
trackAncillarySuccess(
|
||||
confirmationNumber,
|
||||
packages,
|
||||
formData.deliveryTime,
|
||||
"room + ancillary",
|
||||
selectedAncillary
|
||||
)
|
||||
clearAncillarySessionData()
|
||||
router.replace(returnUrl)
|
||||
} else {
|
||||
trackAncillaryFailed(
|
||||
packages,
|
||||
formData.deliveryTime,
|
||||
selectedAncillary
|
||||
)
|
||||
router.replace(`${returnUrl}&errorCode=AncillaryFailed`)
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
trackAncillaryFailed(
|
||||
packages,
|
||||
formData.deliveryTime,
|
||||
selectedAncillary
|
||||
)
|
||||
router.replace(`${returnUrl}&errorCode=AncillaryFailed`)
|
||||
},
|
||||
}
|
||||
)
|
||||
}, [confirmationNumber, returnUrl, addAncillary, lang, router])
|
||||
|
||||
return <LoadingSpinner />
|
||||
|
||||
Reference in New Issue
Block a user