Files
web/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/helpers.ts
Tobias Johansson c0b543f18d Merged in feat/SW-1437-price-change-scenario (pull request #1532)
Feat/SW-1437 price change scenario

* wip price change scenario

* feat(SW-1437): added updated room prices to summary

* fix: spinner not centered on page

* fix: feedback fixes


Approved-by: Arvid Norlin
Approved-by: Simon.Emanuelsson
2025-03-14 12:39:50 +00:00

48 lines
1.2 KiB
TypeScript

import { PaymentMethodEnum } from "@/constants/booking"
import type { RoomState } from "@/types/stores/enter-details"
export function isPaymentMethodEnum(value: string): value is PaymentMethodEnum {
return Object.values<string>(PaymentMethodEnum).includes(value)
}
export function hasFlexibleRate({ room }: RoomState): boolean {
return room.isFlexRate
}
export function hasPrepaidRate({ room }: RoomState): boolean {
return !room.isFlexRate
}
export function calculateTotalRoomPrice(
{ room }: RoomState,
initialRoomPrice?: number
) {
let totalPrice = initialRoomPrice ?? room.roomPrice.perStay.local.price
if (room.breakfast) {
totalPrice += Number(room.breakfast.localPrice.totalPrice) * room.adults
}
if (room.roomFeatures) {
room.roomFeatures.forEach((pkg) => {
totalPrice += Number(pkg.localPrice.price)
})
}
let comparisonPrice = totalPrice
const isMember = room.guest.join || room.guest.membershipNo
if (isMember) {
const publicPrice = room.roomRate.publicRate?.localPrice.pricePerStay ?? 0
const memberPrice = room.roomRate.memberRate?.localPrice.pricePerStay ?? 0
const diff = publicPrice - memberPrice
comparisonPrice = totalPrice + diff
}
return {
totalPrice,
comparisonPrice,
}
}