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

@@ -53,13 +53,62 @@ export default function PriceDetails() {
total.local.price = total.local.price + room.totalPrice
}
if (
(room.cheques || room.roomPoints || room.vouchers) &&
room.roomPrice
) {
// Corporate Cheque
if (room.cheques) {
if (room.roomPrice) {
total.local.additionalPrice =
(total.local.additionalPrice || 0) + room.totalPrice
total.local.additionalPriceCurrency = currency
} else {
const pkgsSum = room.packages.reduce(
(total, pkg) => total + pkg.totalPrice,
0
)
total.local.additionalPrice =
(total.local.additionalPrice || 0) + pkgsSum
const pkgsCurrency = room.packages.find(
(pkg) => pkg.currency
)?.currency
if (!total.local.additionalPriceCurrency) {
total.local.additionalPriceCurrency = pkgsCurrency ?? currency
}
}
}
// Redemption
if (room.roomPoints) {
if (room.roomPrice) {
total.local.additionalPrice =
(total.local.additionalPrice || 0) + room.totalPrice
total.local.additionalPriceCurrency = currency
} else {
const pkgsSum = room.packages.reduce(
(total, pkg) => total + pkg.totalPrice,
0
)
total.local.additionalPrice =
(total.local.additionalPrice || 0) + pkgsSum
const pkgsCurrency = room.packages.find(
(pkg) => pkg.currency
)?.currency
if (!total.local.additionalPriceCurrency) {
total.local.additionalPriceCurrency = pkgsCurrency ?? currency
}
}
}
// Voucher
if (room.vouchers && room.packages) {
const pkgsSum = room.packages.reduce(
(total, pkg) => total + pkg.totalPrice,
0
)
total.local.additionalPrice =
(total.local.additionalPrice || 0) + room.totalPrice
total.local.additionalPriceCurrency = currency
(total.local.additionalPrice || 0) + pkgsSum
const pkgsCurrency = room.packages.find((pkg) => pkg.currency)?.currency
if (!total.local.additionalPriceCurrency) {
total.local.additionalPriceCurrency = pkgsCurrency ?? currency
}
}
return total

View File

@@ -17,20 +17,16 @@ export function mapToPrice(rooms: (Room | null)[], nights: number) {
if (room.cheques) {
price = {
corporateCheque: {
additionalPricePerStay: room.totalPrice
? room.totalPrice
: undefined,
currency: room.totalPrice ? room.currencyCode : undefined,
additionalPricePerStay: room.roomPrice ? room.roomPrice : undefined,
currency: room.roomPrice ? room.currencyCode : undefined,
numberOfCheques: room.cheques,
},
}
} else if (room.roomPoints) {
price = {
redemption: {
additionalPricePerStay: room.totalPrice
? room.totalPrice
: undefined,
currency: room.totalPrice ? room.currencyCode : undefined,
additionalPricePerStay: room.roomPrice ? room.roomPrice : undefined,
currency: room.roomPrice ? room.currencyCode : undefined,
pointsPerNight: room.roomPoints / nights,
pointsPerStay: room.roomPoints,
},
@@ -46,7 +42,7 @@ export function mapToPrice(rooms: (Room | null)[], nights: number) {
regular: {
currency: room.currencyCode,
pricePerNight: room.roomPrice / nights,
pricePerStay: room.totalPrice,
pricePerStay: room.roomPrice,
},
}
}