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:
committed by
Linus Flood
parent
8d6f4b82f3
commit
4a06162f79
@@ -64,6 +64,8 @@ export const roomRate: RoomRate = {
|
|||||||
pricePerStay: 132,
|
pricePerStay: 132,
|
||||||
currency: CurrencyEnum.EUR,
|
currency: CurrencyEnum.EUR,
|
||||||
},
|
},
|
||||||
|
oldRateCode: "",
|
||||||
|
rate: "",
|
||||||
},
|
},
|
||||||
publicRate: {
|
publicRate: {
|
||||||
rateCode: "SAVEEU",
|
rateCode: "SAVEEU",
|
||||||
@@ -77,6 +79,8 @@ export const roomRate: RoomRate = {
|
|||||||
pricePerStay: 133,
|
pricePerStay: 133,
|
||||||
currency: CurrencyEnum.EUR,
|
currency: CurrencyEnum.EUR,
|
||||||
},
|
},
|
||||||
|
oldRateCode: "",
|
||||||
|
rate: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,15 +108,15 @@ export default function RoomCard({
|
|||||||
|
|
||||||
const rates = useMemo(
|
const rates = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
save: rateDefinitions.filter(
|
|
||||||
(rate) => rate.cancellationRule === "NotCancellable"
|
|
||||||
),
|
|
||||||
change: rateDefinitions.filter(
|
change: rateDefinitions.filter(
|
||||||
(rate) => rate.cancellationRule === "Changeable"
|
(rate) => rate.cancellationRule === "Changeable"
|
||||||
),
|
),
|
||||||
flex: rateDefinitions.filter(
|
flex: rateDefinitions.filter(
|
||||||
(rate) => rate.cancellationRule === "CancellableBefore6PM"
|
(rate) => rate.cancellationRule === "CancellableBefore6PM"
|
||||||
),
|
),
|
||||||
|
save: rateDefinitions.filter(
|
||||||
|
(rate) => rate.cancellationRule === "NotCancellable"
|
||||||
|
),
|
||||||
}),
|
}),
|
||||||
[rateDefinitions]
|
[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(
|
const getRateInfo = useCallback(
|
||||||
(product: Product) => {
|
(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) =>
|
const publicRate = Object.keys(rates).find((k) =>
|
||||||
rates[k as keyof typeof rates].find(
|
rates[k as keyof typeof rates].find(
|
||||||
(a) => a.rateCode === product.productType.public.rateCode
|
(a) => a.rateCode === product.productType.public.rateCode
|
||||||
@@ -183,30 +230,9 @@ export default function RoomCard({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const key = isUserLoggedIn ? memberRate : publicRate
|
const key = isUserLoggedIn ? memberRate : publicRate
|
||||||
|
return getRate(key)
|
||||||
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}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[freeBooking, freeCancelation, isUserLoggedIn, nonRefundable, rates]
|
[getRate, isUserLoggedIn, rates]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handle URL-based preselection
|
// Handle URL-based preselection
|
||||||
@@ -372,7 +398,7 @@ export default function RoomCard({
|
|||||||
isUserLoggedIn={isUserLoggedIn}
|
isUserLoggedIn={isUserLoggedIn}
|
||||||
paymentTerm={rate.isFlex ? payLater : payNow}
|
paymentTerm={rate.isFlex ? payLater : payNow}
|
||||||
petRoomPackage={petRoomPackage}
|
petRoomPackage={petRoomPackage}
|
||||||
product={product}
|
product={rate?.notAvailable ? undefined : product}
|
||||||
roomTypeCode={roomConfiguration.roomTypeCode}
|
roomTypeCode={roomConfiguration.roomTypeCode}
|
||||||
title={rate.title}
|
title={rate.title}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -109,6 +109,23 @@ function everyRateHasBreakfastIncluded(
|
|||||||
return rateDefinition.breakfastIncluded
|
return rateDefinition.breakfastIncluded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRate(rate: RateDefinition | undefined) {
|
||||||
|
if (!rate) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
switch (rate.cancellationRule) {
|
||||||
|
case "CancellableBefore6PM":
|
||||||
|
return "flex"
|
||||||
|
case "Changeable":
|
||||||
|
return "change"
|
||||||
|
case "NotCancellable":
|
||||||
|
return "save"
|
||||||
|
default:
|
||||||
|
console.info(`Should never happen!`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used for custom sorting further down
|
* This is used for custom sorting further down
|
||||||
* to guarantee correct order of rates
|
* to guarantee correct order of rates
|
||||||
@@ -164,6 +181,32 @@ export const roomsAvailabilitySchema = z
|
|||||||
"public"
|
"public"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
room.products = room.products.map((product) => {
|
||||||
|
const publicRateDefinition = o.data.attributes.rateDefinitions.find(
|
||||||
|
(rate) =>
|
||||||
|
product.productType.public.rateCode
|
||||||
|
? rate.rateCode === product.productType.public.rateCode
|
||||||
|
: rate.rateCode === product.productType.public.oldRateCode
|
||||||
|
)
|
||||||
|
const publicRate = getRate(publicRateDefinition)
|
||||||
|
const memberRateDefinition = o.data.attributes.rateDefinitions.find(
|
||||||
|
(rate) =>
|
||||||
|
product.productType.member?.rateCode
|
||||||
|
? rate.rateCode === product.productType.member?.rateCode
|
||||||
|
: rate.rateCode === product.productType.member?.oldRateCode
|
||||||
|
)
|
||||||
|
const memberRate = getRate(memberRateDefinition)
|
||||||
|
|
||||||
|
if (publicRate) {
|
||||||
|
product.productType.public.rate = publicRate
|
||||||
|
}
|
||||||
|
if (memberRate && product.productType.member) {
|
||||||
|
product.productType.member.rate = memberRate
|
||||||
|
}
|
||||||
|
|
||||||
|
return product
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CancellationRule is the same for public and member per product
|
// CancellationRule is the same for public and member per product
|
||||||
|
|||||||
@@ -13,4 +13,10 @@ export const productTypePriceSchema = z.object({
|
|||||||
rateCode: z.string(),
|
rateCode: z.string(),
|
||||||
rateType: z.string().optional(),
|
rateType: z.string().optional(),
|
||||||
requestedPrice: priceSchema.optional(),
|
requestedPrice: priceSchema.optional(),
|
||||||
|
// This is only used when a product is filtered out
|
||||||
|
// so that we can still map out the correct titles a.so.
|
||||||
|
oldRateCode: z.string().default(""),
|
||||||
|
// Used to set the rate that we use to chose
|
||||||
|
// titles etc.
|
||||||
|
rate: z.string().default(""),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -53,9 +53,11 @@ export const roomConfigurationSchema = z
|
|||||||
productType: {
|
productType: {
|
||||||
member: {
|
member: {
|
||||||
rateCode: "",
|
rateCode: "",
|
||||||
|
oldRateCode: product.productType.member?.rateCode,
|
||||||
},
|
},
|
||||||
public: {
|
public: {
|
||||||
rateCode: "",
|
rateCode: "",
|
||||||
|
oldRateCode: product.productType.public.rateCode,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user