Files
web/apps/scandic-web/components/HotelReservation/SelectRate/index.tsx
Hrishikesh Vaipurkar d2bbc59f47 Merged in fix/SW-2602-select-hotel-page-booking-code (pull request #1941)
Fix/SW-2602 select hotel page booking code filtering

* fix: SW-2602 Fixed booking code filtering

* fix: SW-2602 Fixed lint issues


Approved-by: Niclas Edenvin
2025-05-05 09:17:44 +00:00

110 lines
3.1 KiB
TypeScript

import stringify from "json-stable-stringify-without-jsonify"
import { cookies } from "next/headers"
import { notFound } from "next/navigation"
import { Suspense } from "react"
import { FamilyAndFriendsCodes, REDEMPTION } from "@/constants/booking"
import { getHotel } from "@/lib/trpc/memoizedRequests"
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 { convertSearchParamsToObj } from "@/utils/url"
import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert"
import AvailabilityError from "./AvailabilityError"
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 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,
selectHotelParams.searchType === REDEMPTION
)
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
let isInValidFNF = false
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
const cookieStore = cookies()
isInValidFNF = cookieStore.get("sc")?.value !== "1"
}
const suspenseKey = stringify(searchParams)
return (
<>
<HotelInfoCard hotel={hotelData.hotel} />
{isInValidFNF ? (
<FnFNotAllowedAlert />
) : (
<RoomsContainer
booking={booking}
hotelType={hotelData.hotel.hotelType}
roomCategories={hotelData.roomCategories}
vat={hotelData.hotel.vat}
/>
)}
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
<TrackingSDK
pageData={pageTrackingData}
hotelInfo={hotelsTrackingData}
/>
</Suspense>
<AvailabilityError />
</>
)
}