selectAncillary(ancillary)}>
+
{
+ selectAncillary(ancillary)
+ trackViewAncillary(ancillary)
+ }}
+ >
)
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema.ts b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema.ts
index c22cc48b5..0e5e0300b 100644
--- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema.ts
+++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/schema.ts
@@ -6,6 +6,7 @@ const quantitySchemaWithoutRefine = z.object({
quantityWithPoints: z.number().nullable(),
quantityWithCard: z.number().nullable(),
})
+
export const quantitySchema = z
.object({})
.merge(quantitySchemaWithoutRefine)
@@ -35,4 +36,7 @@ export const ancillaryFormSchema = z
}
)
+export type AncillaryQuantityFormData = z.output<
+ typeof quantitySchemaWithoutRefine
+>
export type AncillaryFormData = z.output
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx
index a0fe351e8..53dba4495 100644
--- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx
+++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx
@@ -9,6 +9,7 @@ import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem
import Divider from "@/components/TempDesignSystem/Divider"
import Body from "@/components/TempDesignSystem/Text/Body"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
+import { trackRemoveAncillary } from "@/utils/tracking/myStay"
import { getBreakfastPackagesFromAncillaryFlow } from "../../utils/hasBreakfastPackage"
import RemoveButton from "./RemoveButton"
@@ -180,7 +181,14 @@ export function AddedAncillaries({
confirmationNumber={booking.confirmationNumber}
code={ancillary.code}
title={ancillaryTitle}
- onSuccess={router.refresh}
+ onSuccess={() => {
+ trackRemoveAncillary(
+ ancillary,
+ booking.hotelId,
+ booking.ancillary?.deliveryTime
+ )
+ router.refresh()
+ }}
/>
) : null}
diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx
index 2385a6791..e82f7e339 100644
--- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx
+++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/GuaranteeCallback/index.tsx
@@ -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