diff --git a/components/HotelReservation/SelectRate/Rooms/index.tsx b/components/HotelReservation/SelectRate/Rooms/index.tsx index d0fd1fe38..01bfe218c 100644 --- a/components/HotelReservation/SelectRate/Rooms/index.tsx +++ b/components/HotelReservation/SelectRate/Rooms/index.tsx @@ -27,8 +27,27 @@ export default function Rooms({ availablePackages, hotelType, }: SelectRateProps) { - const visibleRooms: RoomConfiguration[] = - filterDuplicateRoomTypesByLowestPrice(roomsAvailability.roomConfigurations) + const visibleRooms: RoomConfiguration[] = useMemo(() => { + const deduped = filterDuplicateRoomTypesByLowestPrice( + roomsAvailability.roomConfigurations + ) + + const separated = deduped.reduce<{ + available: RoomConfiguration[] + notAvailable: RoomConfiguration[] + }>( + (acc, curr) => { + if (curr.status === "NotAvailable") { + return { ...acc, notAvailable: [...acc.notAvailable, curr] } + } + return { ...acc, available: [...acc.available, curr] } + }, + { available: [], notAvailable: [] } + ) + + return [...separated.available, ...separated.notAvailable] + }, [roomsAvailability.roomConfigurations]) + const [selectedRate, setSelectedRate] = useState( undefined ) diff --git a/components/HotelReservation/SelectRate/Rooms/utils.ts b/components/HotelReservation/SelectRate/Rooms/utils.ts index 1f691d102..2044e2dbc 100644 --- a/components/HotelReservation/SelectRate/Rooms/utils.ts +++ b/components/HotelReservation/SelectRate/Rooms/utils.ts @@ -6,7 +6,7 @@ import type { RoomConfiguration } from "@/server/routers/hotels/output" export function filterDuplicateRoomTypesByLowestPrice( roomConfigurations: RoomConfiguration[] -) { +): RoomConfiguration[] { const roomTypeCount = roomConfigurations.reduce( (acc, room) => { acc[room.roomType] = (acc[room.roomType] || 0) + 1