feat: move room charge to top in price details modal

This commit is contained in:
Simon Emanuelsson
2025-05-08 11:28:22 +02:00
committed by Michael Zetterberg
parent 194a401a56
commit a99e434d84
28 changed files with 264 additions and 136 deletions

View File

@@ -12,6 +12,7 @@ import type { Price } from "@/types/components/hotelReservation/price"
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
import { CurrencyEnum } from "@/types/enums/currency"
import { StepEnum } from "@/types/enums/step"
import type { Package } from "@/types/requests/packages"
import type { PersistedState, RoomState } from "@/types/stores/enter-details"
import type { SafeUser } from "@/types/user"
@@ -368,15 +369,22 @@ export function getTotalPrice(roomRates: RoomRate[], isMember: boolean) {
return totalPrice
}
export function calculateVoucherPrice(roomRates: RoomRate[]) {
export function calculateVoucherPrice(
roomRates: RoomRate[],
packages: Package[]
) {
return roomRates.reduce<Price>(
(total, room) => {
if (!("voucher" in room)) {
return total
}
const pkgsSum = sumPackages(packages)
return {
local: {
additionalPrice: pkgsSum.price,
additionalPriceCurrency: pkgsSum.currency,
currency: total.local.currency,
price: total.local.price + room.voucher.numberOfVouchers,
},

View File

@@ -85,7 +85,8 @@ export function createDetailsStore(
roomOneRoomRate.redemption.localPrice.additionalPricePerStay
}
} else if (isVoucher) {
initialTotalPrice = calculateVoucherPrice(initialRoomRates)
const pkgs = initialState.rooms.flatMap((room) => room.roomFeatures || [])
initialTotalPrice = calculateVoucherPrice(initialRoomRates, pkgs)
} else if (isCorpChq) {
initialTotalPrice = calculateCorporateChequePrice(initialRoomRates)
} else {

View File

@@ -26,7 +26,9 @@ export function calculateTotalPrice(
if (room.totalPoints) {
total.points = total.points + room.totalPoints
}
if (room.totalPrice) {
// room.totalPrice is a negative value when
// its a vouchers booking (╯°□°)╯︵ ┻━┻
if (room.totalPrice && !room.vouchers) {
total.cash = total.cash + room.totalPrice
}
return total