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:
@@ -7,6 +7,7 @@ import { trpc } from "@/lib/trpc/client"
|
||||
|
||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||
import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus"
|
||||
import { trackEvent } from "@/utils/tracking/base"
|
||||
|
||||
const maxRetries = 15
|
||||
const retryInterval = 2000
|
||||
@@ -14,22 +15,39 @@ const retryInterval = 2000
|
||||
export function useGuaranteeBooking({
|
||||
confirmationNumber,
|
||||
handleBookingCompleted = () => {},
|
||||
isAncillaryFlow,
|
||||
}: {
|
||||
confirmationNumber: string
|
||||
handleBookingCompleted?: () => void
|
||||
isAncillaryFlow?: boolean
|
||||
}) {
|
||||
const intl = useIntl()
|
||||
const router = useRouter()
|
||||
const [isPollingForBookingStatus, setIsPollingForBookingStatus] =
|
||||
useState(false)
|
||||
|
||||
const handlePaymentError = useCallback(() => {
|
||||
toast.error(
|
||||
intl.formatMessage({
|
||||
id: "We had an issue guaranteeing your booking. Please try again.",
|
||||
const handleGuaranteeError = useCallback(
|
||||
(errorMessage?: string) => {
|
||||
trackEvent({
|
||||
event: "glaCardSaveFailed",
|
||||
hotelInfo: {
|
||||
lateArrivalGuarantee: "yes",
|
||||
guaranteedProduct: isAncillaryFlow ? "room + ancillary" : "room",
|
||||
},
|
||||
paymentInfo: {
|
||||
status: "glacardsavefailed",
|
||||
errorMessage,
|
||||
},
|
||||
})
|
||||
)
|
||||
}, [intl])
|
||||
toast.error(
|
||||
intl.formatMessage({
|
||||
id: "We had an issue guaranteeing your booking. Please try again.",
|
||||
})
|
||||
)
|
||||
},
|
||||
[intl, isAncillaryFlow]
|
||||
)
|
||||
|
||||
const utils = trpc.useUtils()
|
||||
const guaranteeBooking = trpc.booking.guarantee.useMutation({
|
||||
onSuccess: (result, variables) => {
|
||||
@@ -43,15 +61,11 @@ export function useGuaranteeBooking({
|
||||
})
|
||||
}
|
||||
} else {
|
||||
handlePaymentError()
|
||||
handleGuaranteeError()
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(
|
||||
intl.formatMessage({
|
||||
id: "Something went wrong!",
|
||||
})
|
||||
)
|
||||
onError: (error) => {
|
||||
handleGuaranteeError(error.message)
|
||||
},
|
||||
})
|
||||
|
||||
@@ -68,12 +82,12 @@ export function useGuaranteeBooking({
|
||||
router.push(bookingStatus.data.paymentUrl)
|
||||
setIsPollingForBookingStatus(false)
|
||||
} else if (bookingStatus.isTimeout) {
|
||||
handlePaymentError()
|
||||
handleGuaranteeError("Timeout")
|
||||
}
|
||||
}, [
|
||||
bookingStatus,
|
||||
router,
|
||||
handlePaymentError,
|
||||
handleGuaranteeError,
|
||||
setIsPollingForBookingStatus,
|
||||
isPollingForBookingStatus,
|
||||
])
|
||||
@@ -84,5 +98,9 @@ export function useGuaranteeBooking({
|
||||
!bookingStatus.data?.paymentUrl &&
|
||||
!bookingStatus.isTimeout)
|
||||
|
||||
return { guaranteeBooking, isLoading }
|
||||
return {
|
||||
guaranteeBooking,
|
||||
isLoading,
|
||||
handleGuaranteeError,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user