Merged in fix/rateCodes (pull request #1315)

fix: taking care of missing rateDefinitions

* fix: taking care of missing rateDefinitions


Approved-by: Linus Flood
This commit is contained in:
Simon.Emanuelsson
2025-02-12 08:52:08 +00:00
committed by Linus Flood
parent 8d6f4b82f3
commit 4a06162f79
5 changed files with 108 additions and 27 deletions

View File

@@ -108,15 +108,15 @@ export default function RoomCard({
const rates = useMemo(
() => ({
save: rateDefinitions.filter(
(rate) => rate.cancellationRule === "NotCancellable"
),
change: rateDefinitions.filter(
(rate) => rate.cancellationRule === "Changeable"
),
flex: rateDefinitions.filter(
(rate) => rate.cancellationRule === "CancellableBefore6PM"
),
save: rateDefinitions.filter(
(rate) => rate.cancellationRule === "NotCancellable"
),
}),
[rateDefinitions]
)
@@ -162,8 +162,55 @@ export default function RoomCard({
}
}
const getRate = useCallback(
(rateCode: string) => {
switch (rateCode) {
case "change":
return {
isFlex: false,
notAvailable: false,
title: freeBooking,
}
case "flex":
return {
isFlex: true,
notAvailable: false,
title: freeCancelation,
}
case "save":
return {
isFlex: false,
notAvailable: false,
title: nonRefundable,
}
default:
throw new Error(
`Unknown key for rate, should be "change", "flex" or "save", but got ${rateCode}`
)
}
},
[freeBooking, freeCancelation, nonRefundable]
)
const getRateInfo = useCallback(
(product: Product) => {
if (
!product.productType.public.rateCode &&
!product.productType.member?.rateCode
) {
const possibleRate = getRate(product.productType.public.rate)
if (possibleRate) {
return {
...possibleRate,
notAvailable: true,
}
}
return {
isFlex: false,
notAvailable: true,
title: "",
}
}
const publicRate = Object.keys(rates).find((k) =>
rates[k as keyof typeof rates].find(
(a) => a.rateCode === product.productType.public.rateCode
@@ -183,30 +230,9 @@ export default function RoomCard({
}
const key = isUserLoggedIn ? memberRate : publicRate
switch (key) {
case "change":
return {
isFlex: false,
title: freeBooking,
}
case "flex":
return {
isFlex: true,
title: freeCancelation,
}
case "save":
return {
isFlex: false,
title: nonRefundable,
}
default:
throw new Error(
`Unknown key for rate, should be "change", "flex" or "save", but got ${key}`
)
}
return getRate(key)
},
[freeBooking, freeCancelation, isUserLoggedIn, nonRefundable, rates]
[getRate, isUserLoggedIn, rates]
)
// Handle URL-based preselection
@@ -372,7 +398,7 @@ export default function RoomCard({
isUserLoggedIn={isUserLoggedIn}
paymentTerm={rate.isFlex ? payLater : payNow}
petRoomPackage={petRoomPackage}
product={product}
product={rate?.notAvailable ? undefined : product}
roomTypeCode={roomConfiguration.roomTypeCode}
title={rate.title}
/>