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,
|
type TrackingSDKPaymentInfo,
|
||||||
} from "@/types/components/tracking"
|
} from "@/types/components/tracking"
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
|
import { CurrencyEnum } from "@/types/enums/currency"
|
||||||
import { RateEnum } from "@/types/enums/rate"
|
import { RateEnum } from "@/types/enums/rate"
|
||||||
import type { Room } from "@/types/stores/booking-confirmation"
|
import type { Room } from "@/types/stores/booking-confirmation"
|
||||||
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
|
||||||
@@ -38,13 +39,14 @@ function mapAncillaryPackage(
|
|||||||
ancillaryPackage: BookingConfirmation["booking"]["packages"][number],
|
ancillaryPackage: BookingConfirmation["booking"]["packages"][number],
|
||||||
operaId: string
|
operaId: string
|
||||||
) {
|
) {
|
||||||
|
const isPoints = ancillaryPackage.currency === CurrencyEnum.POINTS
|
||||||
return {
|
return {
|
||||||
hotelid: operaId,
|
hotelid: operaId,
|
||||||
productCategory: "", // TODO: Add category
|
productCategory: "", // TODO: Add category
|
||||||
productId: ancillaryPackage.code,
|
productId: ancillaryPackage.code,
|
||||||
productName: ancillaryPackage.description,
|
productName: ancillaryPackage.description,
|
||||||
productPoints: ancillaryPackage.points,
|
productPoints: isPoints ? ancillaryPackage.totalPrice : 0,
|
||||||
productPrice: ancillaryPackage.totalPrice,
|
productPrice: isPoints ? 0 : ancillaryPackage.totalPrice,
|
||||||
productType:
|
productType:
|
||||||
ancillaryPackage.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
ancillaryPackage.code === BreakfastPackageEnum.REGULAR_BREAKFAST
|
||||||
? "food"
|
? "food"
|
||||||
|
|||||||
@@ -236,7 +236,6 @@ function getAddedAncillaries(
|
|||||||
const combinedBreakfastPackageAsAncillary: PackageSchema = {
|
const combinedBreakfastPackageAsAncillary: PackageSchema = {
|
||||||
code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
|
code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
|
||||||
unitPrice: 0,
|
unitPrice: 0,
|
||||||
points: 0,
|
|
||||||
currency: addedBreakfastPackages[0].currency,
|
currency: addedBreakfastPackages[0].currency,
|
||||||
type: addedBreakfastPackages[0].type,
|
type: addedBreakfastPackages[0].type,
|
||||||
description: addedBreakfastPackages[0].description,
|
description: addedBreakfastPackages[0].description,
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ export function Ancillaries({
|
|||||||
currency: breakfastPackageAdults.localPrice.currency,
|
currency: breakfastPackageAdults.localPrice.currency,
|
||||||
total: breakfastPackageAdults.localPrice.totalPrice,
|
total: breakfastPackageAdults.localPrice.totalPrice,
|
||||||
},
|
},
|
||||||
// TODO: Change this to the correct URL, whatever that is
|
|
||||||
imageUrl:
|
imageUrl:
|
||||||
"https://images.scandichotels.com/publishedmedia/inyre69evkpzgtygjnvp/Breakfast_-_Scandic_Sweden_-_Free_to_use.jpg",
|
"https://images.scandichotels.com/publishedmedia/inyre69evkpzgtygjnvp/Breakfast_-_Scandic_Sweden_-_Free_to_use.jpg",
|
||||||
requiresDeliveryTime: false,
|
requiresDeliveryTime: false,
|
||||||
@@ -146,12 +145,8 @@ export function Ancillaries({
|
|||||||
])
|
])
|
||||||
|
|
||||||
const allAncillaries = useMemo(() => {
|
const allAncillaries = useMemo(() => {
|
||||||
if (!ancillaries?.length) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
const withBreakfastPopular = addBreakfastPackage(
|
const withBreakfastPopular = addBreakfastPackage(
|
||||||
ancillaries,
|
ancillaries ?? [],
|
||||||
breakfastAncillary,
|
breakfastAncillary,
|
||||||
"Popular"
|
"Popular"
|
||||||
)
|
)
|
||||||
@@ -164,7 +159,7 @@ export function Ancillaries({
|
|||||||
return filtered
|
return filtered
|
||||||
}, [ancillaries, breakfastAncillary, user])
|
}, [ancillaries, breakfastAncillary, user])
|
||||||
|
|
||||||
if (!ancillaries?.length) {
|
if (!allAncillaries.length) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { BookingStatusEnum, ChildBedTypeEnum } from "@/constants/booking"
|
|||||||
|
|
||||||
import { calculateRefId } from "@/utils/refId"
|
import { calculateRefId } from "@/utils/refId"
|
||||||
import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
|
import { nullableArrayObjectValidator } from "@/utils/zod/arrayValidator"
|
||||||
import { nullableIntValidator } from "@/utils/zod/numberValidator"
|
|
||||||
import {
|
import {
|
||||||
nullableStringEmailValidator,
|
nullableStringEmailValidator,
|
||||||
nullableStringValidator,
|
nullableStringValidator,
|
||||||
@@ -97,30 +96,30 @@ const childBedPreferencesSchema = z.object({
|
|||||||
code: z.string().nullable().default(""),
|
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
|
export const packageSchema = z
|
||||||
.object({
|
.object({
|
||||||
type: z.string().nullish(),
|
|
||||||
description: nullableStringValidator,
|
|
||||||
code: 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(),
|
comment: z.string().nullish(),
|
||||||
|
description: nullableStringValidator,
|
||||||
|
price: priceSchema,
|
||||||
|
type: z.string().nullish(),
|
||||||
})
|
})
|
||||||
.transform((packageData) => ({
|
.transform((packageData) => ({
|
||||||
type: packageData.type,
|
|
||||||
description: packageData.description,
|
|
||||||
comment: packageData.comment,
|
|
||||||
code: packageData.code,
|
code: packageData.code,
|
||||||
|
comment: packageData.comment,
|
||||||
currency: packageData.price.currency,
|
currency: packageData.price.currency,
|
||||||
points: packageData.price.points ?? null,
|
description: packageData.description,
|
||||||
totalPrice: packageData.price.totalPrice ?? 0,
|
totalPrice: packageData.price.totalPrice ?? 0,
|
||||||
totalUnit: packageData.price.totalUnit ?? 0,
|
totalUnit: packageData.price.totalUnit ?? 0,
|
||||||
|
type: packageData.type,
|
||||||
unit: packageData.price.unit ?? 0,
|
unit: packageData.price.unit ?? 0,
|
||||||
unitPrice: packageData.price.unitPrice,
|
unitPrice: packageData.price.unitPrice,
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { trackEvent } from "./base"
|
import { trackEvent } from "./base"
|
||||||
|
|
||||||
import type { SelectedAncillary } from "@/types/components/myPages/myStay/ancillaries"
|
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 { PackageSchema } from "@/types/trpc/routers/booking/confirmation"
|
||||||
import type { CreditCard } from "@/types/user"
|
import type { CreditCard } from "@/types/user"
|
||||||
|
|
||||||
@@ -167,14 +168,15 @@ export function trackRemoveAncillary(
|
|||||||
hotelId: string,
|
hotelId: string,
|
||||||
deliveryTime?: string
|
deliveryTime?: string
|
||||||
) {
|
) {
|
||||||
|
const isPoints = ancillary.currency === CurrencyEnum.POINTS
|
||||||
trackEvent({
|
trackEvent({
|
||||||
event: "removeAncillary",
|
event: "removeAncillary",
|
||||||
ancillaries: [
|
ancillaries: [
|
||||||
{
|
{
|
||||||
hotelId,
|
hotelId,
|
||||||
productId: ancillary.code,
|
productId: ancillary.code,
|
||||||
productPrice: ancillary.totalPrice,
|
productPrice: isPoints ? 0 : ancillary.totalPrice,
|
||||||
productPoints: ancillary.points,
|
productPoints: isPoints ? ancillary.totalPrice : 0,
|
||||||
productUnits: ancillary.totalUnit,
|
productUnits: ancillary.totalUnit,
|
||||||
productType: ancillary.type,
|
productType: ancillary.type,
|
||||||
productDeliveryTime: deliveryTime,
|
productDeliveryTime: deliveryTime,
|
||||||
|
|||||||
Reference in New Issue
Block a user