fix: display modify dates for already guaranteed changeable rates
This commit is contained in:
committed by
Michael Zetterberg
parent
b8a976db22
commit
2abd4c5c12
@@ -1,6 +1,4 @@
|
||||
"use client"
|
||||
|
||||
import { useMemo } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { MaterialIcon } from "@scandic-hotels/design-system/Icons"
|
||||
@@ -58,38 +56,34 @@ export default function ActionPanel({ hotel }: ActionPanelProps) {
|
||||
checkOutDate,
|
||||
createDateTime,
|
||||
canChangeDate,
|
||||
isPrePaid,
|
||||
priceType,
|
||||
} = bookedRoom
|
||||
|
||||
const datetimeIsInThePast = useMemo(
|
||||
() => isDatetimePast(checkInDate),
|
||||
[checkInDate]
|
||||
)
|
||||
const datetimeIsInThePast = isDatetimePast(checkInDate)
|
||||
|
||||
const isDateModifyable = checkDateModifiable({
|
||||
const isDateModifyable = checkDateModifiable(
|
||||
canChangeDate,
|
||||
datetimeIsInThePast,
|
||||
isCancelled: bookedRoom.isCancelled,
|
||||
isPrePaid,
|
||||
isRewardNight: priceType === "points",
|
||||
})
|
||||
bookedRoom.isCancelled,
|
||||
priceType === "points"
|
||||
)
|
||||
|
||||
const isCancelable = checkCancelable({
|
||||
bookedRoom,
|
||||
linkedReservationRooms,
|
||||
const isCancelable = checkCancelable(
|
||||
bookedRoom.isCancelable,
|
||||
datetimeIsInThePast,
|
||||
})
|
||||
linkedReservationRooms
|
||||
)
|
||||
|
||||
const isGuaranteeable = checkGuaranteeable({
|
||||
bookedRoom,
|
||||
datetimeIsInThePast,
|
||||
})
|
||||
const isGuaranteeable = checkGuaranteeable(
|
||||
!!bookedRoom.guaranteeInfo,
|
||||
bookedRoom.isCancelled,
|
||||
datetimeIsInThePast
|
||||
)
|
||||
|
||||
const canDownloadInvoice = checkCanDownloadInvoice({
|
||||
isCancelled: bookedRoom.isCancelled,
|
||||
isPrePaid,
|
||||
})
|
||||
const canDownloadInvoice = checkCanDownloadInvoice(
|
||||
bookedRoom.isCancelled,
|
||||
!!bookedRoom.guaranteeInfo
|
||||
)
|
||||
|
||||
const calendarEvent: EventAttributes = {
|
||||
busyStatus: "FREE",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user