feat: add support for bought children breakfast package

This commit is contained in:
Simon Emanuelsson
2025-05-13 11:30:49 +02:00
committed by Simon.Emanuelsson
parent aceb88cb1a
commit b7c78a53b5
9 changed files with 229 additions and 68 deletions

View File

@@ -77,7 +77,7 @@ export default function PriceDetails({
title: `${selectedAncillary.title} / ${intl.formatMessage({
defaultMessage: "Adult",
})}`,
totalPrice: breakfastData.priceAdult * breakfastData.nrOfAdults,
totalPrice: breakfastData.priceAdult,
currency: breakfastData.currency,
quantityWithCard: breakfastData.nrOfAdults * breakfastData.nrOfNights,
},
@@ -88,7 +88,7 @@ export default function PriceDetails({
title: `${selectedAncillary.title} / ${intl.formatMessage({
defaultMessage: "Children",
})} 4-12`,
totalPrice: breakfastData.priceChild * breakfastData.nrOfPayingChildren,
totalPrice: breakfastData.priceChild,
currency: breakfastData.currency,
quantityWithCard:
breakfastData.nrOfPayingChildren * breakfastData.nrOfNights,

View File

@@ -511,20 +511,28 @@ function calculateBreakfastData(
return null
}
const [nrOfPayingChildren, nrOfFreeChildren] = childrenAges.reduce(
(acc, curr) => (curr >= 4 ? [acc[0] + 1, acc[1]] : [acc[0], acc[1] + 1]),
[0, 0]
const { nrOfPayingChildren, nrOfFreeChildren } = childrenAges.reduce(
(total, childAge) => {
if (childAge >= 4) {
total.nrOfPayingChildren = total.nrOfPayingChildren + 1
} else {
total.nrOfFreeChildren = total.nrOfFreeChildren + 1
}
return total
},
{ nrOfPayingChildren: 0, nrOfFreeChildren: 0 }
)
const priceAdult = packages?.find(
const adultPackage = packages?.find(
(p) => p.code === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
)?.localPrice.price
const priceChild = packages?.find(
)
const childPackage = packages?.find(
(p) => p.code === BreakfastPackageEnum.ANCILLARY_CHILD_PAYING_BREAKFAST
)?.localPrice.price
const currency = packages?.find(
(p) => p.code === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
)?.localPrice.currency
)
const priceAdult = adultPackage?.localPrice.price
const priceChild = childPackage?.localPrice.price
const currency =
adultPackage?.localPrice.currency ?? childPackage?.localPrice.currency
if (
typeof priceAdult !== "number" ||

View File

@@ -107,33 +107,34 @@ export function Ancillaries({
return undefined
}
const breakfastPackage = packages?.find(
const breakfastPackageAdults = packages?.find(
(p) => p.code === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
)
const breakfastAncillary: SelectedAncillary | undefined = breakfastPackage
? {
description: intl.formatMessage({
defaultMessage: "Buffet",
}),
id: breakfastPackage.code,
title: intl.formatMessage({
defaultMessage: "Breakfast",
}),
price: {
currency: breakfastPackage.localPrice.currency,
total: breakfastPackage.localPrice.totalPrice,
},
// TODO: Change this to the correct URL, whatever that is
imageUrl:
"https://images.scandichotels.com/publishedmedia/inyre69evkpzgtygjnvp/Breakfast_-_Scandic_Sweden_-_Free_to_use.jpg",
requiresDeliveryTime: false,
loyaltyCode: undefined,
points: undefined,
hotelId: Number(booking.hotelId),
categoryName: "Food",
}
: undefined
const breakfastAncillary: SelectedAncillary | undefined =
breakfastPackageAdults
? {
description: intl.formatMessage({
defaultMessage: "Buffet",
}),
id: breakfastPackageAdults.code,
title: intl.formatMessage({
defaultMessage: "Breakfast",
}),
price: {
currency: breakfastPackageAdults.localPrice.currency,
total: breakfastPackageAdults.localPrice.totalPrice,
},
// TODO: Change this to the correct URL, whatever that is
imageUrl:
"https://images.scandichotels.com/publishedmedia/inyre69evkpzgtygjnvp/Breakfast_-_Scandic_Sweden_-_Free_to_use.jpg",
requiresDeliveryTime: false,
loyaltyCode: undefined,
points: undefined,
hotelId: Number(booking.hotelId),
categoryName: "Food",
}
: undefined
return breakfastAncillary
}, [

View File

@@ -10,10 +10,13 @@ import Row from "./Row"
export default function Breakfast() {
const intl = useIntl()
const { breakfast, rateDefinition } = useMyStayStore((state) => ({
breakfast: state.bookedRoom.breakfast,
rateDefinition: state.bookedRoom.rateDefinition,
}))
const { breakfast, breakfastChildren, rateDefinition } = useMyStayStore(
(state) => ({
breakfast: state.bookedRoom.breakfast,
breakfastChildren: state.bookedRoom.breakfastChildren,
rateDefinition: state.bookedRoom.rateDefinition,
})
)
let breakfastPrice = intl.formatMessage({
defaultMessage: "No breakfast",
@@ -23,9 +26,10 @@ export default function Breakfast() {
defaultMessage: "Included",
})
} else if (breakfast) {
const childPrice = breakfastChildren?.localPrice.totalPrice || 0
breakfastPrice = formatPrice(
intl,
breakfast.localPrice.totalPrice,
breakfast.localPrice.totalPrice + childPrice,
breakfast.localPrice.currency
)
}

View File

@@ -31,30 +31,50 @@ export function mapRoomDetails({
.startOf("day")
.diff(dt(booking.checkInDate).startOf("day"), "days")
const validBreakfastPackages: string[] = [
const validBreakfastPackagesAdults: string[] = [
BreakfastPackageEnum.REGULAR_BREAKFAST,
BreakfastPackageEnum.ANCILLARY_CHILD_PAYING_BREAKFAST,
BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
]
const breakfastPackage = booking.packages.find((pkg) =>
validBreakfastPackages.includes(pkg.code)
const breakfastPackageAdults = booking.packages.find((pkg) =>
validBreakfastPackagesAdults.includes(pkg.code)
)
// We don't get `requestedPrice` in packages
const breakfast: Omit<BreakfastPackage, "requestedPrice"> | null =
breakfastPackage
breakfastPackageAdults
? {
code: breakfastPackage.code,
description: breakfastPackage.description,
code: breakfastPackageAdults.code,
description: breakfastPackageAdults.description,
localPrice: {
currency: breakfastPackage.currency,
price: breakfastPackage.unitPrice,
totalPrice: breakfastPackage.totalPrice,
currency: breakfastPackageAdults.currency,
price: breakfastPackageAdults.unitPrice,
totalPrice: breakfastPackageAdults.totalPrice,
},
packageType: PackageTypeEnum.BreakfastAdult,
}
: null
const validBreakfastPackagesChildren: string[] = [
BreakfastPackageEnum.ANCILLARY_CHILD_PAYING_BREAKFAST,
]
const breakfastPackageChildren = booking.packages.find((pkg) =>
validBreakfastPackagesChildren.includes(pkg.code)
)
// We don't get `requestedPrice` in packages
const breakfastChildren: Omit<BreakfastPackage, "requestedPrice"> | null =
breakfastPackageChildren
? {
code: breakfastPackageChildren.code,
description: breakfastPackageChildren.description,
localPrice: {
currency: breakfastPackageChildren.currency,
price: breakfastPackageChildren.unitPrice,
totalPrice: breakfastPackageChildren.totalPrice,
},
packageType: PackageTypeEnum.BreakfastChildren,
}
: null
const isCancelled = booking.reservationStatus === BookingStatusEnum.Cancelled
const childrenAsString = formatChildBedPreferences({
@@ -120,6 +140,7 @@ export function mapRoomDetails({
},
bookingCode: booking.bookingCode,
breakfast,
breakfastChildren,
canChangeDate: booking.canChangeDate,
cancellationNumber: booking.cancellationNumber,
checkInDate: booking.checkInDate,