feat: make sure correct data is sent to tracking
This commit is contained in:
committed by
Simon.Emanuelsson
parent
1a28bcdc4c
commit
e082bf2e50
@@ -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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}))
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user