e372b91356
Feat/SW-1517 booking codes tracking * feat: SW-1517 Updated tracking to inlcude booking code info * feat: SW-1517 Tracking booking codes * feat: SW-1517 booking code multiroom tracking * feat: SW-1517 booking code tracking select-hotel map view * feat: SW-1517 Updated to optional param * feat: SW-1517 Optimized with map * feat: SW-1517 Typings update * feat: SW-1517 Replaced reduce with map and join * feat: SW-1517 Updated typings Approved-by: Christian Andolf
100 lines
2.7 KiB
TypeScript
100 lines
2.7 KiB
TypeScript
import stringify from "json-stable-stringify-without-jsonify"
|
|
import { notFound } from "next/navigation"
|
|
import { Suspense } from "react"
|
|
|
|
import { getHotel } from "@/lib/trpc/memoizedRequests"
|
|
|
|
import { auth } from "@/auth"
|
|
import HotelInfoCard from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
|
import { RoomsContainer } from "@/components/HotelReservation/SelectRate/RoomsContainer"
|
|
import TrackingSDK from "@/components/TrackingSDK"
|
|
import { setLang } from "@/i18n/serverContext"
|
|
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
|
import { isValidSession } from "@/utils/session"
|
|
import { convertSearchParamsToObj } from "@/utils/url"
|
|
|
|
import { getValidDates } from "./getValidDates"
|
|
import { getTracking } from "./tracking"
|
|
|
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
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 {
|
|
adultsInRoom,
|
|
childrenInRoom,
|
|
hotel,
|
|
noOfRooms,
|
|
selectHotelParams,
|
|
bookingCode,
|
|
} = searchDetails
|
|
|
|
const hotelData = await getHotel({
|
|
hotelId: hotel.id,
|
|
isCardOnlyPayment: false,
|
|
language: params.lang,
|
|
})
|
|
|
|
if (!hotelData) {
|
|
return notFound()
|
|
}
|
|
|
|
const { fromDate, toDate } = getValidDates(
|
|
selectHotelParams.fromDate,
|
|
selectHotelParams.toDate
|
|
)
|
|
|
|
const session = await auth()
|
|
const isUserLoggedIn = isValidSession(session)
|
|
|
|
const arrivalDate = fromDate.toDate()
|
|
const departureDate = toDate.toDate()
|
|
|
|
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
|
params.lang,
|
|
arrivalDate,
|
|
departureDate,
|
|
adultsInRoom,
|
|
childrenInRoom,
|
|
hotel.id,
|
|
hotel.name,
|
|
noOfRooms,
|
|
hotelData.hotel.address.country,
|
|
hotelData.hotel.address.city,
|
|
selectHotelParams.city,
|
|
bookingCode
|
|
)
|
|
|
|
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
|
|
|
|
const suspenseKey = stringify(searchParams)
|
|
return (
|
|
<>
|
|
<HotelInfoCard hotel={hotelData.hotel} />
|
|
|
|
<RoomsContainer
|
|
booking={booking}
|
|
hotelType={hotelData.hotel.hotelType}
|
|
isUserLoggedIn={isUserLoggedIn}
|
|
roomCategories={hotelData.roomCategories}
|
|
vat={hotelData.hotel.vat}
|
|
/>
|
|
|
|
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
|
|
<TrackingSDK
|
|
pageData={pageTrackingData}
|
|
hotelInfo={hotelsTrackingData}
|
|
/>
|
|
</Suspense>
|
|
</>
|
|
)
|
|
}
|