From b5b59329f48077c1f9cdd64b67b592313a634373 Mon Sep 17 00:00:00 2001 From: Niclas Edenvin Date: Tue, 7 Jan 2025 08:35:42 +0000 Subject: [PATCH] Merged in fix/sw-1248-sort-unavailable-rooms (pull request #1126) fix(SW-1248): show unavailable rooms last * fix(SW-1248): show unavailable rooms last Approved-by: Hrishikesh Vaipurkar --- .../SelectRate/Rooms/index.tsx | 23 +++++++++++++++++-- .../SelectRate/Rooms/utils.ts | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) 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