Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)
chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
|
||||
|
||||
import type { AvailabilityWithRoomInfo, SelectedRate } from "./types"
|
||||
|
||||
export function findUnavailableSelectedRooms({
|
||||
selectedRates,
|
||||
roomAvailabilityWithAdjustedRoomCount,
|
||||
}: {
|
||||
selectedRates: SelectedRate[]
|
||||
roomAvailabilityWithAdjustedRoomCount: (AvailabilityWithRoomInfo | null)[][]
|
||||
}): number[] {
|
||||
const roomIndexesToDeselect: number[] = []
|
||||
for (let roomIndex = selectedRates.length - 1; roomIndex >= 0; roomIndex--) {
|
||||
const rate = selectedRates[roomIndex]
|
||||
if (!rate) continue
|
||||
|
||||
const room = roomAvailabilityWithAdjustedRoomCount[roomIndex].find(
|
||||
(x) => x?.roomTypeCode === rate.roomInfo.roomTypeCode
|
||||
)
|
||||
|
||||
if (!room || room.status === AvailabilityEnum.NotAvailable) {
|
||||
roomIndexesToDeselect.push(roomIndex)
|
||||
}
|
||||
}
|
||||
return roomIndexesToDeselect
|
||||
}
|
||||
Reference in New Issue
Block a user