Merged in feat/sw-2874-move-select-rate (pull request #2750)
Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
import { HotelInfoCardSkeleton } from "@scandic-hotels/design-system/HotelInfoCard"
|
||||
|
||||
import { RoomsContainerSkeleton } from "@/components/HotelReservation/SelectRate/RoomsContainer/RoomsContainerSkeleton"
|
||||
import { SelectRateSkeleton } from "@scandic-hotels/booking-flow/components/SelectRate"
|
||||
|
||||
export default function LoadingSelectRate() {
|
||||
return (
|
||||
<>
|
||||
<HotelInfoCardSkeleton />
|
||||
<RoomsContainerSkeleton />
|
||||
</>
|
||||
)
|
||||
return <SelectRateSkeleton />
|
||||
}
|
||||
|
||||
@@ -1,68 +1,30 @@
|
||||
import { notFound } from "next/navigation"
|
||||
import { SelectRatePage as SelectRatePagePrimitive } from "@scandic-hotels/booking-flow/pages/SelectRatePage"
|
||||
|
||||
import { SelectRateProvider } from "@scandic-hotels/booking-flow/contexts/SelectRate/SelectRateContext"
|
||||
import { parseSelectRateSearchParams } from "@scandic-hotels/booking-flow/utils/url"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
||||
import TrackingSDK from "@/components/TrackingSDK"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import { combineRegExps, rateTypeRegex } from "@/constants/booking"
|
||||
import { getHotel } from "@/lib/trpc/memoizedRequests"
|
||||
|
||||
import SelectRate from "@/components/HotelReservation/SelectRate"
|
||||
|
||||
import type { LangParams, NextSearchParams, PageArgs } from "@/types/params"
|
||||
|
||||
const singleRoomRateTypes = combineRegExps(
|
||||
[rateTypeRegex.ARB, rateTypeRegex.VOUCHER],
|
||||
"i"
|
||||
)
|
||||
import {
|
||||
type LangParams,
|
||||
type NextSearchParams,
|
||||
type PageArgs,
|
||||
} from "@/types/params"
|
||||
|
||||
export default async function SelectRatePage(
|
||||
props: PageArgs<LangParams & { section: string }, NextSearchParams>
|
||||
props: PageArgs<LangParams, NextSearchParams>
|
||||
) {
|
||||
const params = await props.params
|
||||
const searchParams = await props.searchParams
|
||||
const booking = parseSelectRateSearchParams(searchParams)
|
||||
|
||||
if (!booking) {
|
||||
logger.debug("Invalid search params", searchParams)
|
||||
notFound()
|
||||
}
|
||||
|
||||
const isMultiRoom = booking.rooms.length > 1
|
||||
const isRedemption = booking.searchType === SEARCH_TYPE_REDEMPTION
|
||||
const isArbOrVoucher = booking.bookingCode
|
||||
? singleRoomRateTypes.test(booking.bookingCode)
|
||||
: false
|
||||
|
||||
if ((isMultiRoom && isRedemption) || (isMultiRoom && isArbOrVoucher)) {
|
||||
logger.debug(
|
||||
"Invalid search params, can't have multiroom and redemption/voucher",
|
||||
{ isMultiRoom, isRedemption, isArbOrVoucher }
|
||||
)
|
||||
notFound()
|
||||
}
|
||||
|
||||
// If someone tries to update the url with
|
||||
// a bookingCode also, then we need to remove it
|
||||
if (isRedemption && searchParams.bookingCode) {
|
||||
delete searchParams.bookingCode
|
||||
}
|
||||
|
||||
const hotelData = await getHotel({
|
||||
hotelId: booking.hotelId,
|
||||
isCardOnlyPayment: false,
|
||||
language: params.lang,
|
||||
})
|
||||
|
||||
if (!hotelData) {
|
||||
logger.debug("Unable to find hotel data")
|
||||
notFound()
|
||||
}
|
||||
const lang = await getLang()
|
||||
|
||||
return (
|
||||
<SelectRateProvider hotelData={hotelData}>
|
||||
<SelectRate hotelData={hotelData} booking={booking} />
|
||||
</SelectRateProvider>
|
||||
<SelectRatePagePrimitive
|
||||
lang={lang}
|
||||
searchParams={searchParams}
|
||||
renderTracking={(props) => (
|
||||
<TrackingSDK
|
||||
hotelInfo={props.hotelsTrackingData}
|
||||
pageData={props.pageTrackingData}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user