From e082bf2e507e1d06b377351fc53ec24501458063 Mon Sep 17 00:00:00 2001 From: Simon Emanuelsson Date: Wed, 14 May 2025 16:01:49 +0200 Subject: [PATCH] feat: make sure correct data is sent to tracking --- .../BookingConfirmation/Tracking/tracking.ts | 6 ++-- .../Ancillaries/AddedAncillaries/index.tsx | 1 - .../MyStay/Ancillaries/index.tsx | 9 ++---- .../server/routers/booking/output.ts | 29 +++++++++---------- apps/scandic-web/utils/tracking/myStay.ts | 6 ++-- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts index 022e3a9ae..afa68e1d9 100644 --- a/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/BookingConfirmation/Tracking/tracking.ts @@ -15,6 +15,7 @@ import { type TrackingSDKPaymentInfo, } from "@/types/components/tracking" import { BreakfastPackageEnum } from "@/types/enums/breakfast" +import { CurrencyEnum } from "@/types/enums/currency" import { RateEnum } from "@/types/enums/rate" import type { Room } from "@/types/stores/booking-confirmation" import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation" @@ -38,13 +39,14 @@ function mapAncillaryPackage( ancillaryPackage: BookingConfirmation["booking"]["packages"][number], operaId: string ) { + const isPoints = ancillaryPackage.currency === CurrencyEnum.POINTS return { hotelid: operaId, productCategory: "", // TODO: Add category productId: ancillaryPackage.code, productName: ancillaryPackage.description, - productPoints: ancillaryPackage.points, - productPrice: ancillaryPackage.totalPrice, + productPoints: isPoints ? ancillaryPackage.totalPrice : 0, + productPrice: isPoints ? 0 : ancillaryPackage.totalPrice, productType: ancillaryPackage.code === BreakfastPackageEnum.REGULAR_BREAKFAST ? "food" 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 fe7079e83..4a83a0680 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx @@ -236,7 +236,6 @@ function getAddedAncillaries( const combinedBreakfastPackageAsAncillary: PackageSchema = { code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST, unitPrice: 0, - points: 0, currency: addedBreakfastPackages[0].currency, type: addedBreakfastPackages[0].type, description: addedBreakfastPackages[0].description, diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx index 5e1c6b5d9..c83ab786b 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx @@ -125,7 +125,6 @@ export function Ancillaries({ currency: breakfastPackageAdults.localPrice.currency, total: breakfastPackageAdults.localPrice.totalPrice, }, - // TODO: Change this to the correct URL, whatever that is imageUrl: "https://images.scandichotels.com/publishedmedia/inyre69evkpzgtygjnvp/Breakfast_-_Scandic_Sweden_-_Free_to_use.jpg", requiresDeliveryTime: false, @@ -146,12 +145,8 @@ export function Ancillaries({ ]) const allAncillaries = useMemo(() => { - if (!ancillaries?.length) { - return [] - } - const withBreakfastPopular = addBreakfastPackage( - ancillaries, + ancillaries ?? [], breakfastAncillary, "Popular" ) @@ -164,7 +159,7 @@ export function Ancillaries({ return filtered }, [ancillaries, breakfastAncillary, user]) - if (!ancillaries?.length) { + if (!allAncillaries.length) { return null } diff --git a/apps/scandic-web/server/routers/booking/output.ts b/apps/scandic-web/server/routers/booking/output.ts index b03cbc081..5c2e88887 100644 --- a/apps/scandic-web/server/routers/booking/output.ts +++ b/apps/scandic-web/server/routers/booking/output.ts @@ -4,7 +4,6 @@ import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking" import { calculateRefId } from "@/utils/refId" import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator" -import { nullableIntValidator } from "@/utils/zod/numberValidator" import { nullableStringEmailValidator, nullableStringValidator, @@ -97,30 +96,30 @@ const childBedPreferencesSchema = z.object({ code: z.string().nullable().default(""), }) +const priceSchema = z.object({ + currency: z.nativeEnum(CurrencyEnum).default(CurrencyEnum.Unknown), + totalPrice: z.number().nullish(), + totalUnit: z.number().int().nullish(), + unit: z.number().int().nullish(), + unitPrice: z.number(), +}) + export const packageSchema = z .object({ - type: z.string().nullish(), - description: nullableStringValidator, code: nullableStringValidator, - price: z.object({ - unit: z.number().int().nullish(), - unitPrice: z.number(), - totalPrice: z.number().nullish(), - totalUnit: z.number().int().nullish(), - currency: z.nativeEnum(CurrencyEnum).default(CurrencyEnum.Unknown), - points: nullableIntValidator, - }), comment: z.string().nullish(), + description: nullableStringValidator, + price: priceSchema, + type: z.string().nullish(), }) .transform((packageData) => ({ - type: packageData.type, - description: packageData.description, - comment: packageData.comment, code: packageData.code, + comment: packageData.comment, currency: packageData.price.currency, - points: packageData.price.points ?? null, + description: packageData.description, totalPrice: packageData.price.totalPrice ?? 0, totalUnit: packageData.price.totalUnit ?? 0, + type: packageData.type, unit: packageData.price.unit ?? 0, unitPrice: packageData.price.unitPrice, })) diff --git a/apps/scandic-web/utils/tracking/myStay.ts b/apps/scandic-web/utils/tracking/myStay.ts index fec04eacf..27d0d6395 100644 --- a/apps/scandic-web/utils/tracking/myStay.ts +++ b/apps/scandic-web/utils/tracking/myStay.ts @@ -1,6 +1,7 @@ import { trackEvent } from "./base" import type { SelectedAncillary } from "@/types/components/myPages/myStay/ancillaries" +import { CurrencyEnum } from "@/types/enums/currency" import type { PackageSchema } from "@/types/trpc/routers/booking/confirmation" import type { CreditCard } from "@/types/user" @@ -167,14 +168,15 @@ export function trackRemoveAncillary( hotelId: string, deliveryTime?: string ) { + const isPoints = ancillary.currency === CurrencyEnum.POINTS trackEvent({ event: "removeAncillary", ancillaries: [ { hotelId, productId: ancillary.code, - productPrice: ancillary.totalPrice, - productPoints: ancillary.points, + productPrice: isPoints ? 0 : ancillary.totalPrice, + productPoints: isPoints ? ancillary.totalPrice : 0, productUnits: ancillary.totalUnit, productType: ancillary.type, productDeliveryTime: deliveryTime,