Merged in feat/sw-3207-refactor-select-hotel-tracking (pull request #2587)
feat(SW-3207): Refactor select-hotel tracking * Refactor select-hotel tracking Approved-by: Bianca Widstam
This commit is contained in:
@@ -13,24 +13,16 @@ import TrackingSDK from "@/components/TrackingSDK"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
import { getValidDates } from "../getValidDates"
|
||||
import { getTracking } from "./tracking"
|
||||
|
||||
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
||||
import { getSelectRateTracking } from "./tracking"
|
||||
|
||||
export default function Tracking({
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotelId,
|
||||
hotelName,
|
||||
noOfRooms,
|
||||
country,
|
||||
city,
|
||||
}: {
|
||||
adultsInRoom: number[]
|
||||
childrenInRoom: ChildrenInRoom
|
||||
hotelId: string
|
||||
hotelName: string
|
||||
noOfRooms: number
|
||||
country: string
|
||||
city: string
|
||||
}) {
|
||||
@@ -47,22 +39,19 @@ export default function Tracking({
|
||||
const arrivalDate = fromDate.toDate()
|
||||
const departureDate = toDate.toDate()
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||
const { hotelsTrackingData, pageTrackingData } = getSelectRateTracking({
|
||||
lang,
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotelId,
|
||||
hotelName,
|
||||
noOfRooms,
|
||||
country,
|
||||
city,
|
||||
hotelCity: city,
|
||||
paramCity,
|
||||
bookingCode,
|
||||
searchType === SEARCH_TYPE_REDEMPTION,
|
||||
rooms
|
||||
)
|
||||
isRedemption: searchType === SEARCH_TYPE_REDEMPTION,
|
||||
rooms,
|
||||
})
|
||||
|
||||
return (
|
||||
<TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} />
|
||||
|
||||
@@ -13,22 +13,33 @@ import {
|
||||
} from "@/types/components/tracking"
|
||||
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
||||
|
||||
export function getTracking(
|
||||
lang: Lang,
|
||||
arrivalDate: Date,
|
||||
departureDate: Date,
|
||||
adultsInRoom: number[],
|
||||
childrenInRoom: ChildrenInRoom,
|
||||
hotelId: string,
|
||||
hotelName: string,
|
||||
noOfRooms: number,
|
||||
country: string | undefined,
|
||||
hotelCity: string | undefined,
|
||||
paramCity: string | undefined,
|
||||
bookingCode?: string,
|
||||
isRedemption?: boolean,
|
||||
type SelectRateTrackingInput = {
|
||||
lang: Lang
|
||||
arrivalDate: Date
|
||||
departureDate: Date
|
||||
hotelId: string
|
||||
hotelName: string
|
||||
country: string | undefined
|
||||
hotelCity: string | undefined
|
||||
paramCity: string | undefined
|
||||
bookingCode?: string
|
||||
isRedemption?: boolean
|
||||
rooms?: Room[]
|
||||
) {
|
||||
}
|
||||
|
||||
export function getSelectRateTracking({
|
||||
lang,
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
hotelId,
|
||||
hotelName,
|
||||
country,
|
||||
hotelCity,
|
||||
paramCity,
|
||||
bookingCode,
|
||||
isRedemption = false,
|
||||
rooms = [],
|
||||
}: SelectRateTrackingInput) {
|
||||
const pageTrackingData: TrackingSDKPageData = {
|
||||
channel: TrackingChannelEnum.hotelreservation,
|
||||
domainLanguage: lang,
|
||||
@@ -39,6 +50,13 @@ export function getTracking(
|
||||
siteVersion: "new-web",
|
||||
}
|
||||
|
||||
let adultsInRoom: number[] = []
|
||||
let childrenInRoom: ChildrenInRoom = null
|
||||
if (rooms?.length) {
|
||||
adultsInRoom = rooms.map((room) => room.adults ?? 0)
|
||||
childrenInRoom = rooms.map((room) => room.childrenInRoom ?? null)
|
||||
}
|
||||
|
||||
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
||||
ageOfChildren: childrenInRoom
|
||||
?.map((c) => c?.map((k) => k.age).join(",") ?? "")
|
||||
@@ -55,7 +73,7 @@ export function getTracking(
|
||||
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
||||
noOfAdults: adultsInRoom.join(","),
|
||||
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
|
||||
noOfRooms,
|
||||
noOfRooms: rooms?.length ?? 0,
|
||||
region: hotelCity,
|
||||
searchTerm: paramCity ?? hotelName,
|
||||
searchType: "hotel",
|
||||
|
||||
@@ -28,11 +28,8 @@ export default async function SelectRatePage({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const { adultsInRoom, childrenInRoom, hotel, noOfRooms, bookingCode } =
|
||||
searchDetails
|
||||
|
||||
const hotelData = await getHotel({
|
||||
hotelId: hotel.id,
|
||||
hotelId: searchDetails.hotel.id,
|
||||
isCardOnlyPayment: false,
|
||||
language: lang,
|
||||
})
|
||||
@@ -42,10 +39,14 @@ export default async function SelectRatePage({
|
||||
}
|
||||
|
||||
let isInValidFNF = false
|
||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||
if (
|
||||
booking.bookingCode &&
|
||||
FamilyAndFriendsCodes.includes(booking.bookingCode)
|
||||
) {
|
||||
const cookieStore = await cookies()
|
||||
isInValidFNF = cookieStore.get("sc")?.value !== "1"
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<HotelInfoCard booking={booking} hotel={hotelData.hotel} />
|
||||
@@ -61,11 +62,8 @@ export default async function SelectRatePage({
|
||||
)}
|
||||
|
||||
<Tracking
|
||||
adultsInRoom={adultsInRoom}
|
||||
childrenInRoom={childrenInRoom}
|
||||
hotelId={hotel.id}
|
||||
hotelName={hotel.name}
|
||||
noOfRooms={noOfRooms}
|
||||
hotelId={searchDetails.hotel.id}
|
||||
hotelName={searchDetails.hotel.name}
|
||||
country={hotelData.hotel.address.country}
|
||||
city={hotelData.hotel.address.city}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user