fix: display modify dates for already guaranteed changeable rates

This commit is contained in:
Simon Emanuelsson
2025-04-03 15:51:38 +02:00
committed by Michael Zetterberg
parent b8a976db22
commit 2abd4c5c12
17 changed files with 94 additions and 205 deletions

View File

@@ -1,91 +1,42 @@
import { CancellationRuleEnum } from "@/constants/booking"
import { dt } from "@/lib/dt"
import type { Room } from "@/stores/my-stay/myStayRoomDetailsStore"
interface ModificationConditions {
canModify: boolean
isNotPast: boolean
isNotCancelled: boolean
isNotPrePaid: boolean
isNotRewardNight: boolean
export function isDatetimePast(date: Date) {
return dt(date).hour(18).minute(0).second(0).isBefore(dt(), "seconds")
}
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
export function checkDateModifiable(
canChangeDate: boolean,
datetimeIsInThePast: boolean,
isCancelled: boolean,
isRewardNight: boolean
}): boolean {
const conditions: ModificationConditions = {
canModify: canChangeDate,
isNotPast: !datetimeIsInThePast,
isNotCancelled: !isCancelled,
isNotPrePaid: !isPrePaid,
isNotRewardNight: !isRewardNight,
}
return Object.values(conditions).every(Boolean)
) {
return canChangeDate && !datetimeIsInThePast && !isCancelled && !isRewardNight
}
export function checkCancelable({
bookedRoom,
linkedReservationRooms,
datetimeIsInThePast,
}: {
bookedRoom: Room
export function checkCancelable(
isCancelable: boolean,
datetimeIsInThePast: boolean,
linkedReservationRooms: Room[]
datetimeIsInThePast: boolean
}): boolean {
) {
const hasAnyCancelableRoom =
bookedRoom.isCancelable ||
linkedReservationRooms.some((room) => room.isCancelable)
isCancelable || linkedReservationRooms.some((room) => room.isCancelable)
return hasAnyCancelableRoom && !datetimeIsInThePast
}
export function checkGuaranteeable({
bookedRoom,
datetimeIsInThePast,
}: {
bookedRoom: Room
export function checkGuaranteeable(
guaranteeInfo: boolean,
isCancelled: boolean,
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)
) {
return !guaranteeInfo && !isCancelled && !datetimeIsInThePast
}
export function checkCanDownloadInvoice({
isCancelled,
isPrePaid,
}: {
isCancelled: boolean
isPrePaid: boolean
}): boolean {
return !isCancelled && isPrePaid
export function checkCanDownloadInvoice(
isCancelled: boolean,
guaranteeInfo: boolean
) {
return !isCancelled && guaranteeInfo
}