129 lines
3.9 KiB
TypeScript
129 lines
3.9 KiB
TypeScript
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
|
import { notFound } from "next/navigation"
|
|
import { Suspense } from "react"
|
|
|
|
import { getHotel } from "@/lib/trpc/memoizedRequests"
|
|
|
|
import HotelInfoCard, {
|
|
HotelInfoCardSkeleton,
|
|
} from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
|
import {
|
|
preload,
|
|
RoomsContainer,
|
|
} from "@/components/HotelReservation/SelectRate/RoomsContainer"
|
|
import { RoomsContainerSkeleton } from "@/components/HotelReservation/SelectRate/RoomsContainer/RoomsContainerSkeleton"
|
|
import TrackingSDK from "@/components/TrackingSDK"
|
|
import { setLang } from "@/i18n/serverContext"
|
|
import { convertSearchParamsToObj } from "@/utils/url"
|
|
|
|
import { getHotelSearchDetails } from "../utils"
|
|
import { getValidDates } from "./getValidDates"
|
|
|
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
import {
|
|
TrackingChannelEnum,
|
|
type TrackingSDKHotelInfo,
|
|
type TrackingSDKPageData,
|
|
} from "@/types/components/tracking"
|
|
import type { LangParams, PageArgs } from "@/types/params"
|
|
|
|
export default async function SelectRatePage({
|
|
params,
|
|
searchParams,
|
|
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
|
setLang(params.lang)
|
|
const searchDetails = await getHotelSearchDetails({ searchParams })
|
|
if (!searchDetails?.hotel) {
|
|
return notFound()
|
|
}
|
|
const { hotel, adultsInRoom, childrenInRoom, selectHotelParams } =
|
|
searchDetails
|
|
|
|
const { fromDate, toDate } = getValidDates(
|
|
selectHotelParams.fromDate,
|
|
selectHotelParams.toDate
|
|
)
|
|
|
|
preload(
|
|
hotel.id,
|
|
params.lang,
|
|
fromDate.format("YYYY-MM-DD"),
|
|
toDate.format("YYYY-MM-DD"),
|
|
adultsInRoom,
|
|
childrenInRoom
|
|
)
|
|
|
|
const hotelData = await getHotel({
|
|
hotelId: hotel.id,
|
|
isCardOnlyPayment: false,
|
|
language: params.lang,
|
|
})
|
|
|
|
const arrivalDate = fromDate.toDate()
|
|
const departureDate = toDate.toDate()
|
|
|
|
const pageTrackingData: TrackingSDKPageData = {
|
|
pageId: "select-rate",
|
|
domainLanguage: params.lang,
|
|
channel: TrackingChannelEnum["hotelreservation"],
|
|
pageName: "hotelreservation|select-rate",
|
|
siteSections: "hotelreservation|select-rate",
|
|
pageType: "bookingroomsandratespage",
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
|
searchTerm: selectHotelParams.city ?? hotel?.name,
|
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
|
departureDate: format(departureDate, "yyyy-MM-dd"),
|
|
noOfAdults: adultsInRoom[0], // TODO: Handle multiple rooms
|
|
noOfChildren: childrenInRoom?.length,
|
|
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
|
|
childBedPreference: childrenInRoom
|
|
?.map((c) => ChildBedMapEnum[c.bed])
|
|
.join("|"),
|
|
noOfRooms: 1, // // TODO: Handle multiple rooms
|
|
duration: differenceInCalendarDays(departureDate, arrivalDate),
|
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
|
searchType: "hotel",
|
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
|
country: hotelData?.hotel.address.country,
|
|
hotelID: hotel?.id,
|
|
region: hotelData?.hotel.address.city,
|
|
}
|
|
|
|
const hotelId = +hotel.id
|
|
|
|
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
|
|
|
|
return (
|
|
<>
|
|
<Suspense fallback={<HotelInfoCardSkeleton />}>
|
|
<HotelInfoCard hotelData={hotelData} />
|
|
</Suspense>
|
|
|
|
<Suspense
|
|
key={JSON.stringify(searchParams)}
|
|
fallback={<RoomsContainerSkeleton />}
|
|
>
|
|
<RoomsContainer
|
|
adultArray={adultsInRoom}
|
|
booking={booking}
|
|
childArray={childrenInRoom}
|
|
fromDate={arrivalDate}
|
|
hotelId={hotelId}
|
|
lang={params.lang}
|
|
toDate={departureDate}
|
|
/>
|
|
</Suspense>
|
|
<Suspense fallback={null}>
|
|
<TrackingSDK
|
|
pageData={pageTrackingData}
|
|
hotelInfo={hotelsTrackingData}
|
|
/>
|
|
</Suspense>
|
|
</>
|
|
)
|
|
}
|