Merged in chore/move-enter-details (pull request #2778)
Chore/move enter details Approved-by: Anton Gunnarsson
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { PaymentMethodEnum } from "@scandic-hotels/common/constants/paymentMethod"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import type { RoomState } from "../../../stores/enter-details/types"
|
||||
|
||||
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 && "member" in room.roomRate) {
|
||||
const publicPrice = room.roomRate.public?.localPrice.pricePerStay ?? 0
|
||||
const memberPrice = room.roomRate.member?.localPrice.pricePerStay ?? 0
|
||||
const diff = publicPrice - memberPrice
|
||||
comparisonPrice = totalPrice + diff
|
||||
}
|
||||
|
||||
return {
|
||||
totalPrice,
|
||||
comparisonPrice,
|
||||
}
|
||||
}
|
||||
|
||||
export const paymentInfoStorageName = "payment-info-storage"
|
||||
|
||||
type PaymentInfoSessionData = {
|
||||
paymentMethod: string
|
||||
isSavedCreditCard: boolean
|
||||
}
|
||||
|
||||
export function readPaymentInfoFromSessionStorage():
|
||||
| PaymentInfoSessionData
|
||||
| undefined {
|
||||
try {
|
||||
const paymentInfoSessionData = sessionStorage.getItem(
|
||||
paymentInfoStorageName
|
||||
)
|
||||
if (!paymentInfoSessionData) return undefined
|
||||
return JSON.parse(paymentInfoSessionData)
|
||||
} catch (error) {
|
||||
logger.error("Error reading from session storage:", error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export function writePaymentInfoToSessionStorage(
|
||||
paymentMethod: string,
|
||||
isSavedCreditCard: boolean
|
||||
) {
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
paymentInfoStorageName,
|
||||
JSON.stringify({
|
||||
paymentMethod,
|
||||
isSavedCreditCard,
|
||||
})
|
||||
)
|
||||
} catch (error) {
|
||||
logger.error("Error writing to session storage:", error)
|
||||
}
|
||||
}
|
||||
|
||||
export function clearPaymentInfoSessionStorage() {
|
||||
sessionStorage.removeItem(paymentInfoStorageName)
|
||||
}
|
||||
Reference in New Issue
Block a user