feat(SW-1259): Enter details multiroom * refactor: remove per-step URLs * WIP: map multiroom data * fix: lint errors in details page * fix: made useEnterDetailsStore tests pass * fix: WIP refactor enter details store * fix: WIP enter details store update * fix: added room index to select correct room * fix: added logic for navigating between steps and rooms * fix: update summary to work with store changes * fix: added room and total price calculation * fix: removed unused code and added test for breakfast included * refactor: move store selectors into helpers * refactor: session storage state for multiroom booking * feat: update enter details accordion navigation * fix: added room index to each form component so they select correct room * fix: added unique id to input to handle case when multiple inputs have same name * fix: update payment step with store changes * fix: rebase issues * fix: now you should only be able to go to a step if previous room is completed * refactor: cleanup * fix: if no availability just skip that room for now * fix: add select-rate Summary and adjust typings Approved-by: Arvid Norlin
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import type { Price } from "@/types/components/hotelReservation/price"
|
|
import {
|
|
type RoomPackage,
|
|
RoomPackageCodeEnum,
|
|
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
import type { Rate } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
|
|
export const calculateTotalPrice = (
|
|
selectedRateSummary: Rate[],
|
|
isUserLoggedIn: boolean,
|
|
petRoomPackage: RoomPackage | undefined
|
|
) => {
|
|
return selectedRateSummary.reduce<Price>(
|
|
(total, room) => {
|
|
const priceToUse =
|
|
isUserLoggedIn && room.member ? room.member : room.public
|
|
const isPetRoom = room.features.some(
|
|
(feature) => feature.code === RoomPackageCodeEnum.PET_ROOM
|
|
)
|
|
const petRoomPrice =
|
|
isPetRoom && petRoomPackage
|
|
? isUserLoggedIn
|
|
? Number(petRoomPackage.localPrice.totalPrice || 0)
|
|
: Number(petRoomPackage.requestedPrice.totalPrice || 0)
|
|
: 0
|
|
|
|
return {
|
|
local: {
|
|
currency: priceToUse.localPrice.currency,
|
|
price:
|
|
total.local.price +
|
|
priceToUse.localPrice.pricePerStay +
|
|
petRoomPrice,
|
|
},
|
|
requested: priceToUse.requestedPrice
|
|
? {
|
|
currency: priceToUse.requestedPrice.currency,
|
|
price:
|
|
(total.requested?.price ?? 0) +
|
|
priceToUse.requestedPrice.pricePerStay +
|
|
petRoomPrice,
|
|
}
|
|
: undefined,
|
|
}
|
|
},
|
|
{
|
|
local: {
|
|
currency: selectedRateSummary[0].public.localPrice.currency,
|
|
price: 0,
|
|
},
|
|
requested: undefined,
|
|
}
|
|
)
|
|
}
|