Fix: refactor booking flow search params * wip: apply codemod and upgrade swc plugin * wip: design-system to react 19, fix issues from async (search)params * Prepare new parse function for booking flow search params * Prepare serialize function for booking flow search params * Improve handling of comma separated arrays * Slightly refactor for readability * Next abstracts URLSearchParams so handle the abstraction instead * Refactor booking widget to use new search params parsing * Rename search param functions * Refactor select-hotel to use new search param parser * Use new search params parser in select-rate and details * Fix hotelId type * Avoid passing down search params into BookingWidget components * More updates to use new types instead of SearchParams<T> * Remove types SelectHotelSearchParams and AlternativeSelectHotelSearchParams * Fix parseBookingWidgetSearchParams return type * Add error handling to booking search param parsers * Fix modifyRateIndex handling in details page * Clean up * Refactor booking widget search param serializing to util function * Move start page booking widget search param parsing to page * Use new search param serializer in HandleErrorCallback * Delete convertSearchParamsToObj & convertObjToSearchParams Approved-by: Michael Zetterberg
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import type {
|
|
Rate,
|
|
Room as SelectRateRoom,
|
|
} from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
import type { Room } from "@/components/HotelReservation/PriceDetailsModal/PriceDetailsTable"
|
|
|
|
export function mapToPrice(
|
|
rooms: (Rate | null)[],
|
|
bookingRooms: SelectRateRoom[],
|
|
isUserLoggedIn: boolean
|
|
) {
|
|
return rooms
|
|
.map((room, idx) => {
|
|
if (!room) {
|
|
return null
|
|
}
|
|
|
|
let price = null
|
|
if ("corporateCheque" in room.product) {
|
|
price = {
|
|
corporateCheque: room.product.corporateCheque.localPrice,
|
|
}
|
|
} else if ("redemption" in room.product) {
|
|
price = {
|
|
redemption: room.product.redemption.localPrice,
|
|
}
|
|
} else if ("voucher" in room.product) {
|
|
price = {
|
|
voucher: room.product.voucher,
|
|
}
|
|
} else {
|
|
const isMainRoom = idx === 0
|
|
const memberRate = room.product.member
|
|
const onlyMemberRate = !room.product.public && memberRate
|
|
if ((isUserLoggedIn && isMainRoom && memberRate) || onlyMemberRate) {
|
|
price = {
|
|
regular: memberRate.localPrice,
|
|
}
|
|
} else if (room.product.public) {
|
|
price = {
|
|
regular: room.product.public.localPrice,
|
|
}
|
|
}
|
|
}
|
|
|
|
const bookingRoom = bookingRooms[idx]
|
|
return {
|
|
adults: bookingRoom.adults,
|
|
bedType: undefined,
|
|
breakfast: undefined,
|
|
breakfastIncluded: room.product.rateDefinition.breakfastIncluded,
|
|
childrenInRoom: bookingRoom.childrenInRoom,
|
|
packages: room.packages,
|
|
price,
|
|
roomType: room.roomType,
|
|
}
|
|
})
|
|
.filter((r) => !!(r && r.price)) as Room[]
|
|
}
|