Files
web/apps/scandic-web/components/HotelReservation/MyStay/ManageStay/ActionPanel/utils.ts
Pontus Dreij b48053b8b4 Merged in feat(SW-2083)-missing-booking-codes-scenarios-my-stay (pull request #1680)
Feat(SW-2083) missing booking codes scenarios my stay

* feat(SW-2083) Show points instead of reward nights

* feat(SW-2083) added support for cheque and voucher for totalPrice


Approved-by: Niclas Edenvin
2025-03-31 11:42:47 +00:00

92 lines
2.1 KiB
TypeScript

import { CancellationRuleEnum } from "@/constants/booking"
import type { Room } from "@/stores/my-stay/myStayRoomDetailsStore"
interface ModificationConditions {
canModify: boolean
isNotPast: boolean
isNotCancelled: boolean
isNotPrePaid: boolean
isNotRewardNight: boolean
}
interface GuaranteeConditions {
isCancellableBefore6PM: boolean
hasNoGuaranteeInfo: boolean
isNotCancelled: boolean
isNotPast: boolean
}
export function isDatetimePast(date: Date): boolean {
return new Date(date) < new Date()
}
export function checkDateModifiable({
canChangeDate,
datetimeIsInThePast,
isCancelled,
isPrePaid,
isRewardNight,
}: {
canChangeDate: boolean
datetimeIsInThePast: boolean
isCancelled: boolean
isPrePaid: boolean
isRewardNight: boolean
}): boolean {
const conditions: ModificationConditions = {
canModify: canChangeDate,
isNotPast: !datetimeIsInThePast,
isNotCancelled: !isCancelled,
isNotPrePaid: !isPrePaid,
isNotRewardNight: !isRewardNight,
}
return Object.values(conditions).every(Boolean)
}
export function checkCancelable({
bookedRoom,
linkedReservationRooms,
datetimeIsInThePast,
}: {
bookedRoom: Room
linkedReservationRooms: Room[]
datetimeIsInThePast: boolean
}): boolean {
const hasAnyCancelableRoom =
bookedRoom.isCancelable ||
linkedReservationRooms.some((room) => room.isCancelable)
return hasAnyCancelableRoom && !datetimeIsInThePast
}
export function checkGuaranteeable({
bookedRoom,
datetimeIsInThePast,
}: {
bookedRoom: Room
datetimeIsInThePast: boolean
}): boolean {
const conditions: GuaranteeConditions = {
isCancellableBefore6PM:
bookedRoom.rateDefinition.cancellationRule ===
CancellationRuleEnum.CancellableBefore6PM,
hasNoGuaranteeInfo: !bookedRoom.guaranteeInfo,
isNotCancelled: !bookedRoom.isCancelled,
isNotPast: !datetimeIsInThePast,
}
return Object.values(conditions).every(Boolean)
}
export function checkCanDownloadInvoice({
isCancelled,
isPrePaid,
}: {
isCancelled: boolean
isPrePaid: boolean
}): boolean {
return !isCancelled && isPrePaid
}