feat(SW-717) Multiple requests if adult differ between rooms
This commit is contained in:
@@ -61,7 +61,7 @@ export default async function SelectRatePage({
|
||||
searchTerm: selectHotelParams.city ?? hotel?.name,
|
||||
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
||||
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||
noOfAdults: adultsInRoom,
|
||||
noOfAdults: adultsInRoom[0], // TODO: Handle multiple rooms
|
||||
noOfChildren: childrenInRoom?.length,
|
||||
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
|
||||
childBedPreference: childrenInRoom
|
||||
@@ -86,7 +86,7 @@ export default async function SelectRatePage({
|
||||
lang={params.lang}
|
||||
fromDate={fromDate.toDate()}
|
||||
toDate={toDate.toDate()}
|
||||
adultCount={adultsInRoom}
|
||||
adultArray={adultsInRoom}
|
||||
childArray={childrenInRoom}
|
||||
/>
|
||||
|
||||
@@ -99,7 +99,7 @@ export default async function SelectRatePage({
|
||||
lang={params.lang}
|
||||
fromDate={fromDate.toDate()}
|
||||
toDate={toDate.toDate()}
|
||||
adultCount={adultsInRoom}
|
||||
adultArray={adultsInRoom}
|
||||
childArray={childrenInRoom}
|
||||
/>
|
||||
</Suspense>
|
||||
|
||||
@@ -23,7 +23,7 @@ interface HotelSearchDetails<T> {
|
||||
city: Location | null
|
||||
hotel: HotelLocation | null
|
||||
selectHotelParams: SelectHotelParams<T> & { city: string | undefined }
|
||||
adultsInRoom: number
|
||||
adultsInRoom: number[]
|
||||
childrenInRoomString?: string
|
||||
childrenInRoom?: Child[]
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export async function getHotelSearchDetails<
|
||||
if (!city && !hotel) return notFound()
|
||||
if (isAlternativeHotels && (!city || !hotel)) return notFound()
|
||||
|
||||
let adultsInRoom = 1
|
||||
let adultsInRoom: number[] = []
|
||||
let childrenInRoomString: HotelSearchDetails<T>["childrenInRoomString"] =
|
||||
undefined
|
||||
let childrenInRoom: HotelSearchDetails<T>["childrenInRoom"] = undefined
|
||||
@@ -87,7 +87,7 @@ export async function getHotelSearchDetails<
|
||||
const { rooms } = selectHotelParams
|
||||
|
||||
if (rooms && rooms.length > 0) {
|
||||
adultsInRoom = rooms[0].adults // TODO: Handle multiple rooms
|
||||
adultsInRoom = rooms.map((room) => room.adults?.[0] ?? 0)
|
||||
childrenInRoomString = rooms[0].childrenInRoom
|
||||
? generateChildrenString(rooms[0].childrenInRoom)
|
||||
: undefined // TODO: Handle multiple rooms
|
||||
|
||||
@@ -69,7 +69,7 @@ export async function SelectHotelMapContainer({
|
||||
fetchAlternativeHotels(isAlternativeFor.id, {
|
||||
roomStayStartDate: selectHotelParams.fromDate,
|
||||
roomStayEndDate: selectHotelParams.toDate,
|
||||
adults: adultsInRoom,
|
||||
adults: adultsInRoom[0],
|
||||
children: childrenInRoomString,
|
||||
})
|
||||
)
|
||||
@@ -78,7 +78,7 @@ export async function SelectHotelMapContainer({
|
||||
cityId: city.id,
|
||||
roomStayStartDate: selectHotelParams.fromDate,
|
||||
roomStayEndDate: selectHotelParams.toDate,
|
||||
adults: adultsInRoom,
|
||||
adults: adultsInRoom[0],
|
||||
children: childrenInRoomString,
|
||||
})
|
||||
)
|
||||
@@ -118,7 +118,7 @@ export async function SelectHotelMapContainer({
|
||||
: (selectHotelParams.city as string),
|
||||
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
||||
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||
noOfAdults: adultsInRoom,
|
||||
noOfAdults: adultsInRoom[0], // TODO: Handle multiple rooms
|
||||
noOfChildren: childrenInRoom?.length,
|
||||
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
|
||||
childBedPreference: childrenInRoom
|
||||
|
||||
@@ -83,7 +83,7 @@ export default async function SelectHotel({
|
||||
fetchAlternativeHotels(isAlternativeFor.id, {
|
||||
roomStayStartDate: selectHotelParams.fromDate,
|
||||
roomStayEndDate: selectHotelParams.toDate,
|
||||
adults: adultsInRoom,
|
||||
adults: adultsInRoom[0],
|
||||
children: childrenInRoomString,
|
||||
})
|
||||
)
|
||||
@@ -92,7 +92,7 @@ export default async function SelectHotel({
|
||||
cityId: city.id,
|
||||
roomStayStartDate: selectHotelParams.fromDate,
|
||||
roomStayEndDate: selectHotelParams.toDate,
|
||||
adults: adultsInRoom,
|
||||
adults: adultsInRoom[0],
|
||||
children: childrenInRoomString,
|
||||
})
|
||||
)
|
||||
@@ -167,7 +167,7 @@ export default async function SelectHotel({
|
||||
: (selectHotelParams.city as string),
|
||||
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
||||
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||
noOfAdults: adultsInRoom,
|
||||
noOfAdults: adultsInRoom[0], // TODO: Handle multiple rooms,
|
||||
noOfChildren: childrenInRoom?.length,
|
||||
ageOfChildren: childrenInRoom?.map((c) => c.age).join(","),
|
||||
childBedPreference: childrenInRoom
|
||||
|
||||
@@ -16,7 +16,7 @@ import type { Lang } from "@/constants/languages"
|
||||
type Props = {
|
||||
hotelId: number
|
||||
lang: Lang
|
||||
adultCount: number
|
||||
adultArray: number[]
|
||||
childArray?: Child[]
|
||||
fromDate: Date
|
||||
toDate: Date
|
||||
@@ -27,24 +27,53 @@ export async function NoRoomsAlert({
|
||||
fromDate,
|
||||
toDate,
|
||||
childArray,
|
||||
adultCount,
|
||||
adultArray,
|
||||
lang,
|
||||
}: Props) {
|
||||
const [availability, availabilityError] = await safeTry(
|
||||
getRoomsAvailability({
|
||||
hotelId: hotelId,
|
||||
roomStayStartDate: dt(fromDate).format("YYYY-MM-DD"),
|
||||
roomStayEndDate: dt(toDate).format("YYYY-MM-DD"),
|
||||
adults: adultCount,
|
||||
children: childArray ? generateChildrenString(childArray) : undefined, // TODO: Handle multiple rooms,
|
||||
})
|
||||
)
|
||||
const fromDateString = dt(fromDate).format("YYYY-MM-DD")
|
||||
const toDateString = dt(toDate).format("YYYY-MM-DD")
|
||||
|
||||
if (!availability || availabilityError) {
|
||||
const uniqueAdultCounts = [...new Set(adultArray)]
|
||||
const roomsAvailabilityPromises = uniqueAdultCounts.map((adultCount) => {
|
||||
return safeTry(
|
||||
getRoomsAvailability({
|
||||
hotelId: hotelId,
|
||||
roomStayStartDate: fromDateString,
|
||||
roomStayEndDate: toDateString,
|
||||
adults: adultCount,
|
||||
children:
|
||||
childArray && childArray.length > 0
|
||||
? generateChildrenString(childArray)
|
||||
: undefined,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
const roomsAvailabilityResults = await Promise.all(roomsAvailabilityPromises)
|
||||
|
||||
const roomsAvailability = roomsAvailabilityResults.reduce<
|
||||
(typeof roomsAvailabilityResults)[0][0]
|
||||
>((acc, [result, error]) => {
|
||||
if (error) {
|
||||
console.error("[RoomsContainer] unable to fetch room availability")
|
||||
return acc
|
||||
}
|
||||
if (!acc) return result
|
||||
if (!result) return acc
|
||||
return {
|
||||
...result,
|
||||
roomConfigurations: [
|
||||
...acc.roomConfigurations,
|
||||
...result.roomConfigurations,
|
||||
],
|
||||
}
|
||||
}, null)
|
||||
|
||||
if (!roomsAvailability) {
|
||||
return null
|
||||
}
|
||||
|
||||
const noRoomsAvailable = availability.roomConfigurations.reduce(
|
||||
const noRoomsAvailable = roomsAvailability.roomConfigurations.reduce(
|
||||
(acc, room) => {
|
||||
return acc && room.status === "NotAvailable"
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectR
|
||||
import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer"
|
||||
|
||||
export async function RoomsContainer({
|
||||
adultCount,
|
||||
adultArray,
|
||||
childArray,
|
||||
fromDate,
|
||||
hotelId,
|
||||
@@ -42,7 +42,7 @@ export async function RoomsContainer({
|
||||
hotelId: hotelId.toString(),
|
||||
startDate: fromDateString,
|
||||
endDate: toDateString,
|
||||
adults: adultCount,
|
||||
adults: adultArray[0],
|
||||
children: childArray ? childArray.length : undefined,
|
||||
packageCodes: [
|
||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||
@@ -52,35 +52,49 @@ export async function RoomsContainer({
|
||||
})
|
||||
)
|
||||
|
||||
const roomsAvailabilityPromise = safeTry(
|
||||
getRoomsAvailability({
|
||||
hotelId: hotelId,
|
||||
roomStayStartDate: fromDateString,
|
||||
roomStayEndDate: toDateString,
|
||||
adults: adultCount,
|
||||
children:
|
||||
childArray && childArray.length > 0
|
||||
? generateChildrenString(childArray)
|
||||
: undefined,
|
||||
})
|
||||
)
|
||||
const uniqueAdultCounts = [...new Set(adultArray)]
|
||||
const roomsAvailabilityPromises = uniqueAdultCounts.map((adultCount) => {
|
||||
return safeTry(
|
||||
getRoomsAvailability({
|
||||
hotelId: hotelId,
|
||||
roomStayStartDate: fromDateString,
|
||||
roomStayEndDate: toDateString,
|
||||
adults: adultCount,
|
||||
children:
|
||||
childArray && childArray.length > 0
|
||||
? generateChildrenString(childArray)
|
||||
: undefined,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
const [hotelData, hotelDataError] = await hotelDataPromise
|
||||
const [packages, packagesError] = await packagesPromise
|
||||
const [roomsAvailability, roomsAvailabilityError] =
|
||||
await roomsAvailabilityPromise
|
||||
const roomsAvailabilityResults = await Promise.all(roomsAvailabilityPromises)
|
||||
|
||||
const roomsAvailability = roomsAvailabilityResults.reduce<
|
||||
(typeof roomsAvailabilityResults)[0][0]
|
||||
>((acc, [result, error]) => {
|
||||
if (error) {
|
||||
console.error("[RoomsContainer] unable to fetch room availability")
|
||||
return acc
|
||||
}
|
||||
if (!acc) return result
|
||||
if (!result) return acc
|
||||
return {
|
||||
...result,
|
||||
roomConfigurations: [
|
||||
...acc.roomConfigurations,
|
||||
...result.roomConfigurations,
|
||||
],
|
||||
}
|
||||
}, null)
|
||||
|
||||
if (packagesError) {
|
||||
// TODO: Log packages error
|
||||
console.error("[RoomsContainer] unable to fetch packages")
|
||||
}
|
||||
|
||||
if (roomsAvailabilityError) {
|
||||
// TODO: show proper error component
|
||||
console.error("[RoomsContainer] unable to fetch room availability")
|
||||
return null
|
||||
}
|
||||
|
||||
if (!roomsAvailability) {
|
||||
// HotelInfoCard has the logic for displaying when there are no rooms available
|
||||
return null
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Child } from "./selectRate"
|
||||
|
||||
export interface HotelInfoCardProps {
|
||||
adultCount: number
|
||||
adultArray: number[]
|
||||
childArray?: Child[]
|
||||
fromDate: Date
|
||||
hotelId: number
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Child } from "./selectRate"
|
||||
|
||||
export interface RoomsContainerProps {
|
||||
adultCount: number
|
||||
adultArray: number[]
|
||||
childArray?: Child[]
|
||||
fromDate: Date
|
||||
hotelId: number
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface Child {
|
||||
}
|
||||
|
||||
export interface Room {
|
||||
adults: number
|
||||
adults: number[]
|
||||
roomTypeCode: string
|
||||
rateCode: string
|
||||
counterRateCode: string
|
||||
|
||||
Reference in New Issue
Block a user