feat(SW-717) Multiple requests if adult differ between rooms
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user