feat(BOOK-530): fixed noAvailableRooms tracking on select rate page * feat(BOOK-530): fixed noAvailableRooms tracking on select rate page Approved-by: Bianca Widstam
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
"use client"
|
|
|
|
import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK"
|
|
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
|
|
|
import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext"
|
|
import useLang from "../../../hooks/useLang"
|
|
import { mapPackageToLabel } from "../../../utils/getRoomFeatureDescription"
|
|
import { getValidDates } from "../getValidDates"
|
|
import { getSelectRateTracking } from "./tracking"
|
|
|
|
import type { RouterOutput } from "@scandic-hotels/trpc/client"
|
|
|
|
import type { SelectRateBooking } from "../../../types/components/selectRate/selectRate"
|
|
|
|
interface TrackingProps {
|
|
hotelData: NonNullable<RouterOutput["hotel"]["get"]>
|
|
booking: SelectRateBooking
|
|
}
|
|
|
|
export function SelectRateTracking({ hotelData, booking }: TrackingProps) {
|
|
const lang = useLang()
|
|
const { input } = useSelectRateContext()
|
|
|
|
const { fromDate, toDate } = getValidDates(booking.fromDate, booking.toDate)
|
|
|
|
const { rooms, searchType, bookingCode } = booking
|
|
|
|
const arrivalDate = fromDate.toDate()
|
|
const departureDate = toDate.toDate()
|
|
|
|
const specialRoomType = input.data?.booking.rooms
|
|
?.map((room) => {
|
|
const packages = room.packages
|
|
?.map((pkg) => mapPackageToLabel(pkg))
|
|
.join(",")
|
|
return packages ?? ""
|
|
})
|
|
.join("|")
|
|
|
|
const { hotelsTrackingData, pageTrackingData } = getSelectRateTracking({
|
|
lang,
|
|
arrivalDate,
|
|
departureDate,
|
|
hotelId: hotelData.hotel.id,
|
|
hotelName: hotelData.hotel.name,
|
|
country: hotelData.hotel.address.country,
|
|
hotelCity: hotelData.hotel.address.city,
|
|
bookingCode,
|
|
isRedemption: searchType === SEARCH_TYPE_REDEMPTION,
|
|
specialRoomType,
|
|
rooms,
|
|
})
|
|
|
|
return (
|
|
<TrackingSDK hotelInfo={hotelsTrackingData} pageData={pageTrackingData} />
|
|
)
|
|
}
|