feat(SW-2084) logic to disable Manage stay options * feat(SW-2084) logic to disable Manage stay options * feat(SW-2084) cleanup logic for checks * feat(SW-2084) check if date has passed * feat(SW-2084) change to datetimeIsInThePast Approved-by: Niclas Edenvin
88 lines
2.0 KiB
TypeScript
88 lines
2.0 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
|
|
}
|
|
|
|
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,
|
|
}: {
|
|
canChangeDate: boolean
|
|
datetimeIsInThePast: boolean
|
|
isCancelled: boolean
|
|
isPrePaid: boolean
|
|
}): boolean {
|
|
const conditions: ModificationConditions = {
|
|
canModify: canChangeDate,
|
|
isNotPast: !datetimeIsInThePast,
|
|
isNotCancelled: !isCancelled,
|
|
isNotPrePaid: !isPrePaid,
|
|
}
|
|
|
|
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
|
|
}
|