feat: trigger loading states immediately upon navigation
This commit is contained in:
@@ -1,7 +1,22 @@
|
|||||||
|
import { Suspense } from "react"
|
||||||
|
|
||||||
|
import ChildrenWrapper from "@/components/ChildrenWrapper"
|
||||||
|
|
||||||
import styles from "./layout.module.css"
|
import styles from "./layout.module.css"
|
||||||
|
|
||||||
export default function HotelReservationLayout({
|
export default function AlternativeHotelsLayout({
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren) {
|
}: React.PropsWithChildren) {
|
||||||
return <div className={styles.layout}>{children}</div>
|
return (
|
||||||
|
<div className={styles.layout}>
|
||||||
|
{/*
|
||||||
|
This Suspense is only needed to prevent useSearchParams from
|
||||||
|
making everything rendered client-side
|
||||||
|
https://nextjs.org/docs/14/app/api-reference/functions/use-search-params#static-rendering
|
||||||
|
*/}
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<ChildrenWrapper>{children}</ChildrenWrapper>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { SelectHotelSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelSkeleton"
|
||||||
|
|
||||||
|
export default function AlternativeHotelsLoading() {
|
||||||
|
return <SelectHotelSkeleton />
|
||||||
|
}
|
||||||
@@ -1,30 +1,131 @@
|
|||||||
|
import stringify from "json-stable-stringify-without-jsonify"
|
||||||
|
import { cookies } from "next/headers"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
import { FamilyAndFriendsCodes } from "@/constants/booking"
|
||||||
import { SelectHotelSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelSkeleton"
|
import { alternativeHotelsMap } from "@/constants/routes/hotelReservation"
|
||||||
|
|
||||||
import type { AlternativeHotelsSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
|
||||||
|
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
||||||
|
import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers"
|
||||||
|
import { getTracking } from "@/components/HotelReservation/SelectHotel/tracking"
|
||||||
|
import TrackingSDK from "@/components/TrackingSDK"
|
||||||
|
import { getIntl } from "@/i18n"
|
||||||
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||||
|
|
||||||
|
import type {
|
||||||
|
AlternativeHotelsSearchParams,
|
||||||
|
SelectHotelSearchParams,
|
||||||
|
} from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||||
import type { LangParams, PageArgs } from "@/types/params"
|
import type { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|
||||||
export default async function AlternativeHotelsPage({
|
export default async function AlternativeHotelsPage({
|
||||||
params,
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams, AlternativeHotelsSearchParams>) {
|
}: PageArgs<LangParams, AlternativeHotelsSearchParams>) {
|
||||||
const roomKey = Object.keys(searchParams)
|
setLang(params.lang)
|
||||||
.filter((key) => key.startsWith("room["))
|
const searchDetails = await getHotelSearchDetails({ searchParams }, true)
|
||||||
.map((key) => searchParams[key])
|
|
||||||
.join("-")
|
|
||||||
|
|
||||||
|
if (!searchDetails || !searchDetails.hotel || !searchDetails.city) {
|
||||||
|
return notFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
adultsInRoom,
|
||||||
|
bookingCode,
|
||||||
|
childrenInRoom,
|
||||||
|
city,
|
||||||
|
hotel: isAlternativeFor,
|
||||||
|
noOfRooms,
|
||||||
|
redemption,
|
||||||
|
selectHotelParams,
|
||||||
|
} = searchDetails
|
||||||
|
|
||||||
|
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||||
|
const cookieStore = cookies()
|
||||||
|
const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
|
||||||
|
|
||||||
|
if (isInvalidFNF) {
|
||||||
|
return <FnFNotAllowedAlert />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: This needs to be refactored into its
|
||||||
|
// own functions
|
||||||
|
const hotels = await getHotels(
|
||||||
|
selectHotelParams as SelectHotelSearchParams,
|
||||||
|
isAlternativeFor,
|
||||||
|
bookingCode,
|
||||||
|
city,
|
||||||
|
!!redemption
|
||||||
|
)
|
||||||
|
|
||||||
|
const arrivalDate = new Date(selectHotelParams.fromDate)
|
||||||
|
const departureDate = new Date(selectHotelParams.toDate)
|
||||||
|
|
||||||
|
const isRedemptionAvailability = redemption
|
||||||
|
? hotels.some(
|
||||||
|
(hotel) => hotel.availability.productType?.redemptions?.length
|
||||||
|
)
|
||||||
|
: false
|
||||||
|
|
||||||
|
const isBookingCodeRateAvailable = bookingCode
|
||||||
|
? hotels.some(
|
||||||
|
(hotel) =>
|
||||||
|
hotel.availability.bookingCode &&
|
||||||
|
hotel.availability.status === "Available"
|
||||||
|
)
|
||||||
|
: false
|
||||||
|
|
||||||
|
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||||
|
params.lang,
|
||||||
|
!!isAlternativeFor,
|
||||||
|
arrivalDate,
|
||||||
|
departureDate,
|
||||||
|
adultsInRoom,
|
||||||
|
childrenInRoom,
|
||||||
|
hotels?.length ?? 0,
|
||||||
|
selectHotelParams.hotelId,
|
||||||
|
noOfRooms,
|
||||||
|
hotels?.[0]?.hotel.address.country,
|
||||||
|
hotels?.[0]?.hotel.address.city,
|
||||||
|
selectHotelParams.city,
|
||||||
|
bookingCode,
|
||||||
|
isBookingCodeRateAvailable,
|
||||||
|
redemption,
|
||||||
|
isRedemptionAvailability
|
||||||
|
)
|
||||||
|
|
||||||
|
const mapHref = alternativeHotelsMap(params.lang)
|
||||||
|
|
||||||
|
const intl = await getIntl()
|
||||||
|
const title = intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "Alternatives for {value}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: isAlternativeFor.name,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const suspenseKey = stringify(searchParams)
|
||||||
return (
|
return (
|
||||||
<Suspense
|
<>
|
||||||
key={`${searchParams.hotel}-${searchParams.fromDate}-${searchParams.toDate}-${roomKey}`}
|
|
||||||
fallback={<SelectHotelSkeleton />}
|
|
||||||
>
|
|
||||||
<SelectHotel
|
<SelectHotel
|
||||||
params={params}
|
bookingCode={bookingCode}
|
||||||
searchParams={searchParams}
|
city={city}
|
||||||
isAlternativeHotels
|
hotels={hotels}
|
||||||
|
isAlternative={!!isAlternativeFor}
|
||||||
|
mapHref={mapHref}
|
||||||
|
title={title}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
|
||||||
|
<TrackingSDK
|
||||||
|
pageData={pageTrackingData}
|
||||||
|
hotelInfo={hotelsTrackingData}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import styles from "./layout.module.css"
|
|||||||
|
|
||||||
import type { LangParams, LayoutArgs } from "@/types/params"
|
import type { LangParams, LayoutArgs } from "@/types/params"
|
||||||
|
|
||||||
export default function HotelReservationLayout({
|
export default function StandardHotelReservationLayout({
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,9 +1,22 @@
|
|||||||
|
import { Suspense } from "react"
|
||||||
|
|
||||||
|
import ChildrenWrapper from "@/components/ChildrenWrapper"
|
||||||
|
|
||||||
import styles from "./layout.module.css"
|
import styles from "./layout.module.css"
|
||||||
|
|
||||||
import type { LangParams, LayoutArgs } from "@/types/params"
|
export default function SelectHotelLayout({
|
||||||
|
|
||||||
export default function HotelReservationLayout({
|
|
||||||
children,
|
children,
|
||||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
}: React.PropsWithChildren) {
|
||||||
return <div className={styles.layout}>{children}</div>
|
return (
|
||||||
|
<div className={styles.layout}>
|
||||||
|
{/*
|
||||||
|
This Suspense is only needed to prevent useSearchParams from
|
||||||
|
making everything rendered client-side
|
||||||
|
https://nextjs.org/docs/14/app/api-reference/functions/use-search-params#static-rendering
|
||||||
|
*/}
|
||||||
|
<Suspense fallback={null}>
|
||||||
|
<ChildrenWrapper>{children}</ChildrenWrapper>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { SelectHotelSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelSkeleton"
|
||||||
|
|
||||||
|
export default function SelectHotelLoading() {
|
||||||
|
return <SelectHotelSkeleton />
|
||||||
|
}
|
||||||
@@ -1,8 +1,18 @@
|
|||||||
import stringify from "json-stable-stringify-without-jsonify"
|
import stringify from "json-stable-stringify-without-jsonify"
|
||||||
|
import { cookies } from "next/headers"
|
||||||
|
import { notFound } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
|
import { FamilyAndFriendsCodes } from "@/constants/booking"
|
||||||
|
import { selectHotelMap } from "@/constants/routes/hotelReservation"
|
||||||
|
|
||||||
|
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
|
||||||
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
||||||
import { SelectHotelSkeleton } from "@/components/HotelReservation/SelectHotel/SelectHotelSkeleton"
|
import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers"
|
||||||
|
import { getTracking } from "@/components/HotelReservation/SelectHotel/tracking"
|
||||||
|
import TrackingSDK from "@/components/TrackingSDK"
|
||||||
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||||
|
|
||||||
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||||
import type { LangParams, PageArgs } from "@/types/params"
|
import type { LangParams, PageArgs } from "@/types/params"
|
||||||
@@ -11,11 +21,91 @@ export default async function SelectHotelPage({
|
|||||||
params,
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams, SelectHotelSearchParams>) {
|
}: PageArgs<LangParams, SelectHotelSearchParams>) {
|
||||||
const suspenseKey = stringify(searchParams)
|
setLang(params.lang)
|
||||||
|
const searchDetails = await getHotelSearchDetails({ searchParams })
|
||||||
|
|
||||||
|
if (!searchDetails || !searchDetails.city) return notFound()
|
||||||
|
|
||||||
|
const {
|
||||||
|
adultsInRoom,
|
||||||
|
bookingCode,
|
||||||
|
childrenInRoom,
|
||||||
|
city,
|
||||||
|
noOfRooms,
|
||||||
|
redemption,
|
||||||
|
selectHotelParams,
|
||||||
|
} = searchDetails
|
||||||
|
|
||||||
|
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||||
|
const cookieStore = cookies()
|
||||||
|
const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
|
||||||
|
|
||||||
|
if (isInvalidFNF) {
|
||||||
|
return <FnFNotAllowedAlert />
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hotels = await getHotels(
|
||||||
|
selectHotelParams,
|
||||||
|
null,
|
||||||
|
bookingCode,
|
||||||
|
city,
|
||||||
|
!!redemption
|
||||||
|
)
|
||||||
|
|
||||||
|
const arrivalDate = new Date(selectHotelParams.fromDate)
|
||||||
|
const departureDate = new Date(selectHotelParams.toDate)
|
||||||
|
|
||||||
|
const isRedemptionAvailability = redemption
|
||||||
|
? hotels.some(
|
||||||
|
(hotel) => hotel.availability.productType?.redemptions?.length
|
||||||
|
)
|
||||||
|
: false
|
||||||
|
|
||||||
|
const isBookingCodeRateAvailable = bookingCode
|
||||||
|
? hotels.some(
|
||||||
|
(hotel) =>
|
||||||
|
hotel.availability.bookingCode &&
|
||||||
|
hotel.availability.status === "Available"
|
||||||
|
)
|
||||||
|
: false
|
||||||
|
|
||||||
|
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||||
|
params.lang,
|
||||||
|
false,
|
||||||
|
arrivalDate,
|
||||||
|
departureDate,
|
||||||
|
adultsInRoom,
|
||||||
|
childrenInRoom,
|
||||||
|
hotels?.length ?? 0,
|
||||||
|
selectHotelParams.hotelId,
|
||||||
|
noOfRooms,
|
||||||
|
hotels?.[0]?.hotel.address.country,
|
||||||
|
hotels?.[0]?.hotel.address.city,
|
||||||
|
selectHotelParams.city,
|
||||||
|
bookingCode,
|
||||||
|
isBookingCodeRateAvailable,
|
||||||
|
redemption,
|
||||||
|
isRedemptionAvailability
|
||||||
|
)
|
||||||
|
|
||||||
|
const mapHref = selectHotelMap(params.lang)
|
||||||
|
const suspenseKey = stringify(searchParams)
|
||||||
return (
|
return (
|
||||||
<Suspense key={suspenseKey} fallback={<SelectHotelSkeleton />}>
|
<>
|
||||||
<SelectHotel params={params} searchParams={searchParams} />
|
<SelectHotel
|
||||||
</Suspense>
|
bookingCode={bookingCode}
|
||||||
|
city={city}
|
||||||
|
hotels={hotels}
|
||||||
|
mapHref={mapHref}
|
||||||
|
title={city.name}
|
||||||
|
/>
|
||||||
|
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
|
||||||
|
<TrackingSDK
|
||||||
|
pageData={pageTrackingData}
|
||||||
|
hotelInfo={hotelsTrackingData}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { HotelInfoCardSkeleton } from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
||||||
|
import { RoomsContainerSkeleton } from "@/components/HotelReservation/SelectRate/RoomsContainer/RoomsContainerSkeleton"
|
||||||
|
|
||||||
|
// Select Rate loading doesn't need a layout and wrapper
|
||||||
|
// to force loading.tsx to show again since refetch of
|
||||||
|
// availability happens client-side and only the RoomCards
|
||||||
|
// display a loading state since we already have the hotel
|
||||||
|
// data
|
||||||
|
export default function LoadingSelectRate() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<HotelInfoCardSkeleton />
|
||||||
|
<RoomsContainerSkeleton />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
import stringify from "json-stable-stringify-without-jsonify"
|
|
||||||
import { notFound } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
|
||||||
|
|
||||||
import { combineRegExps, rateTypeRegex, REDEMPTION } from "@/constants/booking"
|
import { combineRegExps, rateTypeRegex, REDEMPTION } from "@/constants/booking"
|
||||||
|
|
||||||
import SelectRate from "@/components/HotelReservation/SelectRate"
|
import SelectRate from "@/components/HotelReservation/SelectRate"
|
||||||
import { HotelInfoCardSkeleton } from "@/components/HotelReservation/SelectRate/HotelInfoCard"
|
|
||||||
import { RoomsContainerSkeleton } from "@/components/HotelReservation/SelectRate/RoomsContainer/RoomsContainerSkeleton"
|
|
||||||
import { convertSearchParamsToObj } from "@/utils/url"
|
import { convertSearchParamsToObj } from "@/utils/url"
|
||||||
|
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
@@ -21,7 +17,6 @@ export default async function SelectRatePage({
|
|||||||
params,
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
||||||
const suspenseKey = stringify(searchParams)
|
|
||||||
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
|
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
|
||||||
|
|
||||||
const isMultiRoom = booking.rooms.length > 1
|
const isMultiRoom = booking.rooms.length > 1
|
||||||
@@ -40,17 +35,5 @@ export default async function SelectRatePage({
|
|||||||
delete searchParams.bookingCode
|
delete searchParams.bookingCode
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <SelectRate params={params} searchParams={searchParams} />
|
||||||
<Suspense
|
|
||||||
key={suspenseKey}
|
|
||||||
fallback={
|
|
||||||
<>
|
|
||||||
<HotelInfoCardSkeleton />
|
|
||||||
<RoomsContainerSkeleton />
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<SelectRate params={params} searchParams={searchParams} />
|
|
||||||
</Suspense>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { BookingWidgetSkeleton } from "@/components/BookingWidget/Client"
|
||||||
|
|
||||||
|
// This file is crucial for displaying a loading
|
||||||
|
// state immediately in the booking flow.
|
||||||
|
// Next doesn't recognize manually added Suspense
|
||||||
|
// boundaries during page navigation (Server->Client)
|
||||||
|
// thus making it seem as the page is frozen during
|
||||||
|
// the time it takes for `BookingWidget` to resolve.
|
||||||
|
export default function BookingWidgetLoading() {
|
||||||
|
return <BookingWidgetSkeleton />
|
||||||
|
}
|
||||||
@@ -186,14 +186,6 @@ export default function BookingWidgetClient({
|
|||||||
}
|
}
|
||||||
}, [methods, selectedBookingCode])
|
}, [methods, selectedBookingCode])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!selectedLocation) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
methods.setValue("search", selectedLocation.name)
|
|
||||||
}, [selectedLocation, methods])
|
|
||||||
|
|
||||||
if (shouldShowSkeleton) {
|
if (shouldShowSkeleton) {
|
||||||
return <BookingWidgetSkeleton type={type} />
|
return <BookingWidgetSkeleton type={type} />
|
||||||
}
|
}
|
||||||
|
|||||||
11
apps/scandic-web/components/ChildrenWrapper.tsx
Normal file
11
apps/scandic-web/components/ChildrenWrapper.tsx
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
"use client"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
|
import { Fragment } from "react"
|
||||||
|
|
||||||
|
// Solution derived from leerobs example
|
||||||
|
// https://github.com/vercel/next.js/issues/53543#issuecomment-2327883526
|
||||||
|
// Ensure children are re-rendered when the search query changes
|
||||||
|
export default function ChildrenWrapper({ children }: React.PropsWithChildren) {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
return <Fragment key={searchParams.toString()}>{children}</Fragment>
|
||||||
|
}
|
||||||
@@ -11,7 +11,10 @@ import type {
|
|||||||
} from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
} from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
||||||
import type { CategorizedFilters } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
import type { CategorizedFilters } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
|
||||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||||
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
import type {
|
||||||
|
AlternativeHotelsSearchParams,
|
||||||
|
SelectHotelSearchParams,
|
||||||
|
} from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||||
import type { AdditionalData, DetailedFacility, Hotel } from "@/types/hotel"
|
import type { AdditionalData, DetailedFacility, Hotel } from "@/types/hotel"
|
||||||
import type { HotelsAvailabilityItem } from "@/types/trpc/routers/hotel/availability"
|
import type { HotelsAvailabilityItem } from "@/types/trpc/routers/hotel/availability"
|
||||||
import type {
|
import type {
|
||||||
@@ -155,7 +158,7 @@ function sortAndFilterHotelsByAvailability(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getHotels(
|
export async function getHotels(
|
||||||
booking: SelectHotelSearchParams,
|
booking: SelectHotelSearchParams | AlternativeHotelsSearchParams,
|
||||||
isAlternativeFor: HotelLocation | null,
|
isAlternativeFor: HotelLocation | null,
|
||||||
bookingCode: string | undefined,
|
bookingCode: string | undefined,
|
||||||
city: Location,
|
city: Location,
|
||||||
|
|||||||
@@ -1,163 +1,82 @@
|
|||||||
import stringify from "json-stable-stringify-without-jsonify"
|
|
||||||
import { cookies } from "next/headers"
|
|
||||||
import { notFound } from "next/navigation"
|
|
||||||
import { Suspense } from "react"
|
|
||||||
|
|
||||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
||||||
|
|
||||||
import { FamilyAndFriendsCodes } from "@/constants/booking"
|
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
|
||||||
import {
|
import BookingCodeFilter from "@/components/HotelReservation/SelectHotel/BookingCodeFilter"
|
||||||
alternativeHotelsMap,
|
import HotelCount from "@/components/HotelReservation/SelectHotel/HotelCount"
|
||||||
selectHotelMap,
|
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
|
||||||
} from "@/constants/routes/hotelReservation"
|
import HotelSorter from "@/components/HotelReservation/SelectHotel/HotelSorter"
|
||||||
|
import MobileMapButtonContainer from "@/components/HotelReservation/SelectHotel/MobileMapButtonContainer"
|
||||||
|
import NoAvailabilityAlert from "@/components/HotelReservation/SelectHotel/NoAvailabilityAlert"
|
||||||
import StaticMap from "@/components/Maps/StaticMap"
|
import StaticMap from "@/components/Maps/StaticMap"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||||
import TrackingSDK from "@/components/TrackingSDK"
|
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
|
||||||
|
|
||||||
import FnFNotAllowedAlert from "../FnFNotAllowedAlert/FnFNotAllowedAlert"
|
import { getFiltersFromHotels, type HotelResponse } from "./helpers"
|
||||||
import HotelCardListing from "../HotelCardListing"
|
|
||||||
import BookingCodeFilter from "./BookingCodeFilter"
|
|
||||||
import { getFiltersFromHotels, getHotels } from "./helpers"
|
|
||||||
import HotelCount from "./HotelCount"
|
|
||||||
import HotelFilter from "./HotelFilter"
|
|
||||||
import HotelSorter from "./HotelSorter"
|
|
||||||
import MobileMapButtonContainer from "./MobileMapButtonContainer"
|
|
||||||
import NoAvailabilityAlert from "./NoAvailabilityAlert"
|
|
||||||
import { getTracking } from "./tracking"
|
|
||||||
|
|
||||||
import styles from "./selectHotel.module.css"
|
import styles from "./selectHotel.module.css"
|
||||||
|
|
||||||
import type { SelectHotelProps } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
import type { Location } from "@/types/trpc/routers/hotel/locations"
|
||||||
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
|
||||||
|
interface SelectHotelProps {
|
||||||
|
isAlternative?: boolean
|
||||||
|
bookingCode?: string
|
||||||
|
city: Location
|
||||||
|
hotels: HotelResponse[]
|
||||||
|
mapHref: string
|
||||||
|
title: string
|
||||||
|
}
|
||||||
|
|
||||||
export default async function SelectHotel({
|
export default async function SelectHotel({
|
||||||
params,
|
bookingCode,
|
||||||
searchParams,
|
city,
|
||||||
isAlternativeHotels,
|
hotels,
|
||||||
|
isAlternative = false,
|
||||||
|
mapHref,
|
||||||
|
title,
|
||||||
}: SelectHotelProps) {
|
}: SelectHotelProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const searchDetails = await getHotelSearchDetails(
|
const isAllUnavailable = !hotels.length
|
||||||
{
|
|
||||||
searchParams: searchParams as SelectHotelSearchParams & {
|
|
||||||
[key: string]: string
|
|
||||||
},
|
|
||||||
},
|
|
||||||
isAlternativeHotels
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!searchDetails) return notFound()
|
|
||||||
|
|
||||||
const {
|
|
||||||
adultsInRoom,
|
|
||||||
bookingCode,
|
|
||||||
childrenInRoom,
|
|
||||||
city,
|
|
||||||
hotel: isAlternativeFor,
|
|
||||||
noOfRooms,
|
|
||||||
redemption,
|
|
||||||
selectHotelParams,
|
|
||||||
} = searchDetails
|
|
||||||
|
|
||||||
if (!city) return notFound()
|
|
||||||
|
|
||||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
|
||||||
const cookieStore = cookies()
|
|
||||||
const isInValidFNF = cookieStore.get("sc")?.value !== "1"
|
|
||||||
|
|
||||||
if (isInValidFNF) {
|
|
||||||
return <FnFNotAllowedAlert />
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const hotels = await getHotels(
|
|
||||||
selectHotelParams,
|
|
||||||
isAlternativeFor,
|
|
||||||
bookingCode,
|
|
||||||
city,
|
|
||||||
!!redemption
|
|
||||||
)
|
|
||||||
|
|
||||||
const arrivalDate = new Date(selectHotelParams.fromDate)
|
|
||||||
const departureDate = new Date(selectHotelParams.toDate)
|
|
||||||
|
|
||||||
const isCityWithCountry = (city: any): city is { country: string } =>
|
const isCityWithCountry = (city: any): city is { country: string } =>
|
||||||
"country" in city
|
"country" in city
|
||||||
const filterList = getFiltersFromHotels(hotels)
|
|
||||||
|
|
||||||
const isAllUnavailable = !hotels.length
|
const isBookingCodeRateAvailable = bookingCode
|
||||||
const isRedemptionAvailability = redemption
|
|
||||||
? hotels.some(
|
? hotels.some(
|
||||||
(hotel) => hotel.availability.productType?.redemptions?.length
|
(hotel) =>
|
||||||
)
|
hotel.availability.bookingCode &&
|
||||||
|
hotel.availability.status === "Available"
|
||||||
|
)
|
||||||
: false
|
: false
|
||||||
|
|
||||||
const suspenseKey = stringify(searchParams)
|
|
||||||
|
|
||||||
const isFullPriceHotelAvailable = bookingCode
|
const isFullPriceHotelAvailable = bookingCode
|
||||||
? hotels?.some(
|
? hotels?.some(
|
||||||
(hotel) =>
|
(hotel) =>
|
||||||
!hotel.availability.bookingCode &&
|
!hotel.availability.bookingCode &&
|
||||||
hotel.availability.status === "Available"
|
hotel.availability.status === "Available"
|
||||||
)
|
)
|
||||||
: false
|
: false
|
||||||
|
|
||||||
const isBookingCodeRateAvailable = bookingCode
|
|
||||||
? hotels?.some(
|
|
||||||
(hotel) =>
|
|
||||||
hotel.availability.bookingCode &&
|
|
||||||
hotel.availability.status === "Available"
|
|
||||||
)
|
|
||||||
: false
|
|
||||||
|
|
||||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
|
||||||
params.lang,
|
|
||||||
!!isAlternativeFor,
|
|
||||||
arrivalDate,
|
|
||||||
departureDate,
|
|
||||||
adultsInRoom,
|
|
||||||
childrenInRoom,
|
|
||||||
hotels?.length ?? 0,
|
|
||||||
selectHotelParams.hotelId,
|
|
||||||
noOfRooms,
|
|
||||||
hotels?.[0]?.hotel.address.country,
|
|
||||||
hotels?.[0]?.hotel.address.city,
|
|
||||||
selectHotelParams.city,
|
|
||||||
bookingCode,
|
|
||||||
isBookingCodeRateAvailable ? "true" : "false",
|
|
||||||
redemption,
|
|
||||||
isRedemptionAvailability
|
|
||||||
)
|
|
||||||
|
|
||||||
// Special rates (corporate cheque, voucher and reward nights) will not have regular rate hotels availability
|
// Special rates (corporate cheque, voucher and reward nights) will not have regular rate hotels availability
|
||||||
const isSpecialRate = hotels?.some(
|
const isSpecialRate = hotels.some(
|
||||||
(hotel) =>
|
(hotel) =>
|
||||||
hotel.availability.productType?.bonusCheque ||
|
hotel.availability.productType?.bonusCheque ||
|
||||||
hotel.availability.productType?.voucher ||
|
hotel.availability.productType?.voucher ||
|
||||||
hotel.availability.productType?.redemptions
|
hotel.availability.productType?.redemptions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const filterList = getFiltersFromHotels(hotels)
|
||||||
|
|
||||||
|
const showBookingCodeFilter =
|
||||||
|
isBookingCodeRateAvailable && isFullPriceHotelAvailable && !isSpecialRate
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<header className={styles.header}>
|
<header className={styles.header}>
|
||||||
<div className={styles.headerContent}>
|
<div className={styles.headerContent}>
|
||||||
<div className={styles.title}>
|
<div className={styles.title}>
|
||||||
<div className={styles.cityInformation}>
|
<div className={styles.cityInformation}>
|
||||||
<Subtitle>
|
<Subtitle>{title}</Subtitle>
|
||||||
{isAlternativeFor
|
|
||||||
? intl.formatMessage(
|
|
||||||
{
|
|
||||||
defaultMessage: "Alternatives for {value}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: isAlternativeFor.name,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: city.name}
|
|
||||||
</Subtitle>
|
|
||||||
<HotelCount />
|
<HotelCount />
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.sorter}>
|
<div className={styles.sorter}>
|
||||||
@@ -168,21 +87,13 @@ export default async function SelectHotel({
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
{isBookingCodeRateAvailable &&
|
{showBookingCodeFilter ? <BookingCodeFilter /> : null}
|
||||||
isFullPriceHotelAvailable &&
|
|
||||||
!isSpecialRate ? (
|
|
||||||
<BookingCodeFilter />
|
|
||||||
) : null}
|
|
||||||
<div className={styles.sideBar}>
|
<div className={styles.sideBar}>
|
||||||
{hotels.length ? (
|
{hotels.length ? (
|
||||||
<Link
|
<Link
|
||||||
className={styles.link}
|
className={styles.link}
|
||||||
color="burgundy"
|
color="burgundy"
|
||||||
href={
|
href={mapHref}
|
||||||
isAlternativeFor
|
|
||||||
? alternativeHotelsMap(params.lang)
|
|
||||||
: selectHotelMap(params.lang)
|
|
||||||
}
|
|
||||||
keepSearchParams
|
keepSearchParams
|
||||||
>
|
>
|
||||||
<div className={styles.mapContainer}>
|
<div className={styles.mapContainer}>
|
||||||
@@ -224,7 +135,7 @@ export default async function SelectHotel({
|
|||||||
<div className={styles.hotelList}>
|
<div className={styles.hotelList}>
|
||||||
<NoAvailabilityAlert
|
<NoAvailabilityAlert
|
||||||
hotelsLength={hotels.length}
|
hotelsLength={hotels.length}
|
||||||
isAlternative={!!isAlternativeFor}
|
isAlternative={isAlternative}
|
||||||
isAllUnavailable={isAllUnavailable}
|
isAllUnavailable={isAllUnavailable}
|
||||||
operaId={hotels?.[0]?.hotel.operaId}
|
operaId={hotels?.[0]?.hotel.operaId}
|
||||||
bookingCode={bookingCode}
|
bookingCode={bookingCode}
|
||||||
@@ -233,12 +144,6 @@ export default async function SelectHotel({
|
|||||||
<HotelCardListing hotelData={hotels} />
|
<HotelCardListing hotelData={hotels} />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<Suspense key={`${suspenseKey}-tracking`} fallback={null}>
|
|
||||||
<TrackingSDK
|
|
||||||
pageData={pageTrackingData}
|
|
||||||
hotelInfo={hotelsTrackingData}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@
|
|||||||
.headerContent {
|
.headerContent {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
background-color: var(--Base-Surface-Subtle-Normal);
|
background-color: var(--Base-Surface-Subtle-Normal);
|
||||||
padding: var(--Spacing-x4) 0 var(--Spacing-x3);
|
padding: var(--Spacing-x4) 0 var(--Spacing-x3);
|
||||||
@@ -107,9 +108,11 @@
|
|||||||
.sideBar {
|
.sideBar {
|
||||||
max-width: 340px;
|
max-width: 340px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sideBarItem {
|
.sideBarItem {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter {
|
.filter {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
@@ -118,6 +121,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
margin-bottom: var(--Space-x6);
|
margin-bottom: var(--Space-x6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mapContainer {
|
.mapContainer {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -125,12 +129,15 @@
|
|||||||
border-radius: var(--Corner-radius-md);
|
border-radius: var(--Corner-radius-md);
|
||||||
border: 1px solid var(--Base-Border-Subtle);
|
border: 1px solid var(--Base-Border-Subtle);
|
||||||
}
|
}
|
||||||
|
|
||||||
.buttonContainer {
|
.buttonContainer {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.skeletonContainer .title {
|
.skeletonContainer .title {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.skeletonContainer .sideBar {
|
.skeletonContainer .sideBar {
|
||||||
gap: var(--Spacing-x3);
|
gap: var(--Spacing-x3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ export function getTracking(
|
|||||||
hotelCity: string | undefined,
|
hotelCity: string | undefined,
|
||||||
paramCity: string | undefined,
|
paramCity: string | undefined,
|
||||||
bookingCode?: string,
|
bookingCode?: string,
|
||||||
isBookingCodeRateAvailable?: string,
|
isBookingCodeRateAvailable = false,
|
||||||
isRedemption?: boolean,
|
isRedemption?: boolean,
|
||||||
isRedemptionAvailable?: boolean
|
isRedemptionAvailable = false
|
||||||
) {
|
) {
|
||||||
const pageTrackingData: TrackingSDKPageData = {
|
const pageTrackingData: TrackingSDKPageData = {
|
||||||
channel: TrackingChannelEnum["hotelreservation"],
|
channel: TrackingChannelEnum["hotelreservation"],
|
||||||
@@ -63,10 +63,10 @@ export function getTracking(
|
|||||||
searchType: "destination",
|
searchType: "destination",
|
||||||
bookingCode: bookingCode ?? "n/a",
|
bookingCode: bookingCode ?? "n/a",
|
||||||
bookingCodeAvailability: bookingCode
|
bookingCodeAvailability: bookingCode
|
||||||
? isBookingCodeRateAvailable
|
? isBookingCodeRateAvailable.toString()
|
||||||
: undefined,
|
: undefined,
|
||||||
rewardNight: isRedemption ? "yes" : "no",
|
rewardNight: isRedemption ? "yes" : "no",
|
||||||
rewardNightAvailability: isRedemptionAvailable ? "true" : "false",
|
rewardNightAvailability: isRedemptionAvailable.toString(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user