fix: unite all price details modals to one and align on ui
This commit is contained in:
committed by
Michael Zetterberg
parent
8152aea649
commit
1f94c581ae
@@ -6,6 +6,10 @@ import { create, useStore } from "zustand"
|
||||
import { REDEMPTION } from "@/constants/booking"
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import {
|
||||
sumPackages,
|
||||
sumPackagesRequestedPrice,
|
||||
} from "@/components/HotelReservation/utils"
|
||||
import { DetailsContext } from "@/contexts/Details"
|
||||
|
||||
import {
|
||||
@@ -64,6 +68,7 @@ export function createDetailsStore(
|
||||
|
||||
let initialTotalPrice: Price
|
||||
const roomOneRoomRate = initialState.rooms[0].roomRate
|
||||
const initialRoomRates = initialState.rooms.map((r) => r.roomRate)
|
||||
if (isRedemption && "redemption" in roomOneRoomRate) {
|
||||
initialTotalPrice = {
|
||||
local: {
|
||||
@@ -80,34 +85,56 @@ export function createDetailsStore(
|
||||
roomOneRoomRate.redemption.localPrice.additionalPricePerStay
|
||||
}
|
||||
} else if (isVoucher) {
|
||||
initialTotalPrice = calculateVoucherPrice(
|
||||
initialState.rooms.map((r) => r.roomRate)
|
||||
)
|
||||
initialTotalPrice = calculateVoucherPrice(initialRoomRates)
|
||||
} else if (isCorpChq) {
|
||||
initialTotalPrice = calculateCorporateChequePrice(
|
||||
initialState.rooms.map((r) => r.roomRate)
|
||||
)
|
||||
initialTotalPrice = calculateCorporateChequePrice(initialRoomRates)
|
||||
} else {
|
||||
initialTotalPrice = getTotalPrice(
|
||||
initialState.rooms.map((r) => r.roomRate),
|
||||
isMember
|
||||
)
|
||||
initialTotalPrice = getTotalPrice(initialRoomRates, isMember)
|
||||
}
|
||||
|
||||
initialState.rooms.forEach((room) => {
|
||||
if (room.roomFeatures) {
|
||||
room.roomFeatures.forEach((pkg) => {
|
||||
const pkgsSum = sumPackages(room.roomFeatures)
|
||||
const pkgsSumRequested = sumPackagesRequestedPrice(room.roomFeatures)
|
||||
|
||||
if ("corporateCheque" in room.roomRate || "redemption" in room.roomRate) {
|
||||
initialTotalPrice.local.additionalPrice = add(
|
||||
initialTotalPrice.local.additionalPrice,
|
||||
pkgsSum.price
|
||||
)
|
||||
if (
|
||||
!initialTotalPrice.local.additionalPriceCurrency &&
|
||||
pkgsSum.currency
|
||||
) {
|
||||
initialTotalPrice.local.additionalPriceCurrency = pkgsSum.currency
|
||||
}
|
||||
|
||||
if (initialTotalPrice.requested) {
|
||||
initialTotalPrice.requested.additionalPrice = add(
|
||||
initialTotalPrice.requested.additionalPrice,
|
||||
pkgsSumRequested.price
|
||||
)
|
||||
if (
|
||||
!initialTotalPrice.requested.additionalPriceCurrency &&
|
||||
pkgsSumRequested.currency
|
||||
) {
|
||||
initialTotalPrice.requested.additionalPriceCurrency =
|
||||
pkgsSumRequested.currency
|
||||
}
|
||||
}
|
||||
} else if ("public" in room.roomRate) {
|
||||
if (initialTotalPrice.requested) {
|
||||
initialTotalPrice.requested.price = add(
|
||||
initialTotalPrice.requested.price,
|
||||
pkg.requestedPrice.totalPrice
|
||||
pkgsSumRequested.price
|
||||
)
|
||||
}
|
||||
|
||||
initialTotalPrice.local.price = add(
|
||||
initialTotalPrice.local.price,
|
||||
pkg.localPrice.totalPrice
|
||||
pkgsSum.price
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user