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

@@ -13,6 +13,7 @@ import type { Child } from "@/types/components/hotelReservation/selectRate/selec
interface BreakfastProps {
adults: number
breakfast: Omit<BreakfastPackage, "requestedPrice"> | false | undefined | null
breakfastChildren: Omit<BreakfastPackage, "requestedPrice"> | null | undefined
breakfastIncluded: boolean
childrenInRoom: Child[] | undefined
currency: string
@@ -22,8 +23,9 @@ interface BreakfastProps {
export default function Breakfast({
adults,
breakfast,
breakfastChildren,
breakfastIncluded,
childrenInRoom,
childrenInRoom = [],
currency,
nights,
}: BreakfastProps) {
@@ -70,17 +72,56 @@ export default function Breakfast({
return null
}
const adultPricePerNight = breakfast.localPrice.price * adults
const breakfastAdultsPricePerNight = formatPrice(
intl,
breakfast.localPrice.price * adults,
adultPricePerNight,
breakfast.localPrice.currency
)
const breakfastAdultsTotalPrice = formatPrice(
const { payingChildren, freeChildren } = childrenInRoom.reduce(
(total, child) => {
if (child.age >= 4) {
total.payingChildren = total.payingChildren + 1
} else {
total.freeChildren = total.freeChildren + 1
}
return total
},
{ payingChildren: 0, freeChildren: 0 }
)
const childrenPrice = breakfastChildren?.localPrice.price || 0
const childrenPricePerNight = childrenPrice * payingChildren
const childCurrency =
breakfastChildren?.localPrice.currency ?? breakfast.localPrice.currency
const breakfastChildrenPricePerNight = formatPrice(
intl,
breakfast.localPrice.price * adults * nights,
childrenPricePerNight,
childCurrency
)
const totalAdultsPrice = adultPricePerNight * nights
const totalChildrenPrice = childrenPricePerNight * nights
const breakfastTotalPrice = formatPrice(
intl,
totalAdultsPrice + totalChildrenPrice,
breakfast.localPrice.currency
)
const freeChildrenMsg = intl.formatMessage(
{
defaultMessage:
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
},
{
totalChildren: freeChildren,
totalBreakfasts: nights,
}
)
return (
<Tbody border>
<RegularRow
@@ -93,7 +134,28 @@ export default function Breakfast({
)}
value={breakfastAdultsPricePerNight}
/>
{childrenInRoom?.length ? (
{breakfastChildren ? (
<RegularRow
label={intl.formatMessage(
{
defaultMessage:
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
},
{
totalChildren: payingChildren,
totalBreakfasts: nights,
}
)}
value={breakfastChildrenPricePerNight}
/>
) : null}
{breakfastChildren && freeChildren ? (
<RegularRow
label={`${freeChildrenMsg} (0-3)`}
value={formatPrice(intl, 0, breakfast.localPrice.currency)}
/>
) : null}
{childrenInRoom?.length && !breakfastChildren ? (
<RegularRow
label={intl.formatMessage(
{
@@ -110,7 +172,7 @@ export default function Breakfast({
) : null}
<BoldRow
label={intl.formatMessage({ defaultMessage: "Breakfast charge" })}
value={breakfastAdultsTotalPrice}
value={breakfastTotalPrice}
/>
</Tbody>
)

View File

@@ -43,6 +43,7 @@ export interface Room {
adults: number
bedType: BedTypeSchema | undefined
breakfast: Omit<BreakfastPackage, "requestedPrice"> | false | undefined | null
breakfastChildren?: Omit<BreakfastPackage, "requestedPrice"> | null
breakfastIncluded: boolean
childrenInRoom: Child[] | undefined
packages: Packages | null
@@ -182,6 +183,7 @@ export default function PriceDetailsTable({
<Breakfast
adults={room.adults}
breakfast={room.breakfast}
breakfastChildren={room.breakfastChildren}
breakfastIncluded={room.breakfastIncluded}
childrenInRoom={room.childrenInRoom}
currency={currency}