feat: bedtypes is selectable again

This commit is contained in:
Simon Emanuelsson
2025-04-07 13:43:52 +02:00
committed by Michael Zetterberg
parent f62723c6e5
commit afb37d0cc5
69 changed files with 2135 additions and 2349 deletions

View File

@@ -1,14 +1,12 @@
import { notFound, redirect } from "next/navigation"
import { Suspense } from "react"
import { REDEMPTION } from "@/constants/booking"
import { selectRate } from "@/constants/routes/hotelReservation"
import {
getBreakfastPackages,
getHotel,
getPackages,
getProfileSafely,
getSelectedRoomAvailability,
getSelectedRoomsAvailability,
} from "@/lib/trpc/memoizedRequests"
import HotelHeader from "@/components/HotelReservation/EnterDetails/Header"
@@ -17,7 +15,6 @@ import Multiroom from "@/components/HotelReservation/EnterDetails/Room/Multiroom
import RoomOne from "@/components/HotelReservation/EnterDetails/Room/One"
import DesktopSummary from "@/components/HotelReservation/EnterDetails/Summary/Desktop"
import MobileSummary from "@/components/HotelReservation/EnterDetails/Summary/Mobile"
import { generateChildrenString } from "@/components/HotelReservation/utils"
import Alert from "@/components/TempDesignSystem/Alert"
import TrackingSDK from "@/components/TrackingSDK"
import { getIntl } from "@/i18n"
@@ -29,7 +26,6 @@ import { getTracking } from "./tracking"
import styles from "./page.module.css"
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
import { AlertTypeEnum } from "@/types/enums/alert"
import type { LangParams, PageArgs } from "@/types/params"
@@ -40,92 +36,65 @@ export default async function DetailsPage({
searchParams,
}: PageArgs<LangParams, SelectRateSearchParams>) {
const selectRoomParams = new URLSearchParams(searchParams)
selectRoomParams.delete("modifyRateIndex")
const booking = convertSearchParamsToObj<SelectRateSearchParams>(searchParams)
if ("modifyRateIndex" in booking) {
selectRoomParams.delete("modifyRateIndex")
delete booking.modifyRateIndex
}
void getProfileSafely()
const breakfastInput = {
adults: 1,
fromDate: booking.fromDate,
hotelId: booking.hotelId,
toDate: booking.toDate,
}
const breakfastPackages = await getBreakfastPackages(breakfastInput)
const hotelInput = {
hotelId: booking.hotelId,
// TODO: Remove this from input since it forces
// waterfalls for no other reason than to
// set merchantInformationData.alternatePaymentOptions
// to an empty array
isCardOnlyPayment: false,
language: lang,
}
void getHotel(hotelInput)
void getBreakfastPackages(breakfastInput)
void getProfileSafely()
const roomsAvailability = await getSelectedRoomsAvailability({
booking,
lang,
})
const rooms: Room[] = []
for (let room of booking.rooms) {
const childrenAsString =
room.childrenInRoom && generateChildrenString(room.childrenInRoom)
const packages = room.packages
? await getPackages({
adults: room.adults,
children: room.childrenInRoom?.length,
endDate: booking.toDate,
hotelId: booking.hotelId,
packageCodes: room.packages,
startDate: booking.fromDate,
lang,
})
: null
const roomAvailability = await getSelectedRoomAvailability({
adults: room.adults,
bookingCode: booking.bookingCode,
children: childrenAsString,
counterRateCode: room.counterRateCode,
hotelId: booking.hotelId,
packageCodes: room.packages,
rateCode: room.rateCode,
roomStayEndDate: booking.toDate,
roomStayStartDate: booking.fromDate,
roomTypeCode: room.roomTypeCode,
redemption: booking.searchType === REDEMPTION,
})
if (!roomAvailability) {
for (let room of roomsAvailability) {
if (!room) {
// TODO: This could be done in the route already.
// (possibly also add an error case to url?)
// -------------------------------------------------------
// redirect back to select-rate if availability call fails
redirect(`${selectRate(lang)}?${selectRoomParams.toString()}`)
}
rooms.push({
bedTypes: roomAvailability.bedTypes,
breakfastIncluded: roomAvailability.breakfastIncluded,
cancellationText: roomAvailability.cancellationText,
isFlexRate: roomAvailability.isFlexRate,
mustBeGuaranteed: roomAvailability.mustBeGuaranteed,
memberMustBeGuaranteed: roomAvailability.memberMustBeGuaranteed,
packages,
rate: roomAvailability.rate,
rateDefinitionTitle: roomAvailability.rateDefinitionTitle,
rateDetails: roomAvailability.rateDetails ?? [],
rateTitle: roomAvailability.rateTitle,
rateType: roomAvailability.rateType,
roomType: roomAvailability.selectedRoom.roomType,
roomTypeCode: roomAvailability.selectedRoom.roomTypeCode,
roomRate: roomAvailability.product,
isAvailable:
roomAvailability.selectedRoom.status === AvailabilityEnum.Available,
})
rooms.push(room)
}
const isCardOnlyPayment = rooms.some((room) => room?.mustBeGuaranteed)
const hotelData = await getHotel({
hotelId: booking.hotelId,
isCardOnlyPayment,
language: lang,
})
const user = await getProfileSafely()
const hotelData = await getHotel(hotelInput)
if (!hotelData || !rooms) {
if (!hotelData || !rooms.length) {
return notFound()
}
const breakfastPackages = await getBreakfastPackages(breakfastInput)
const user = await getProfileSafely()
const isCardOnlyPayment = rooms.some((room) => room.mustBeGuaranteed)
const { hotel } = hotelData
// TODO: Temp fix to avoid waterfall fetch and moving this
// logic from the route here for now
if (isCardOnlyPayment) {
hotel.merchantInformationData.alternatePaymentOptions = []
}
const { hotelsTrackingData, pageTrackingData } = getTracking(
booking,

View File

@@ -37,7 +37,7 @@ export default async function SelectRatePage({
// If someone tries to update the url with
// a bookingCode also, then we need to remove it
if (isRedemption && searchParams.bookingCode) {
searchParams.bookingCode = ""
delete searchParams.bookingCode
}
return (