From a34951e0754211fe19e8dcc7cd16016dba0e068c Mon Sep 17 00:00:00 2001 From: Niclas Edenvin Date: Wed, 2 Apr 2025 16:03:50 +0000 Subject: [PATCH] Merged in fix/add-multinight-breakfast (pull request #1705) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The number of breakfasts and total sums weren’t correctly calculated. This fixes that. Also changes display logic of when the ancillaries sections are shown Approved-by: Bianca Widstam --- .../PriceDetails/index.tsx | 16 +++-- .../AddAncillaryFlowModal/index.tsx | 12 +++- .../MyStay/Ancillaries/index.tsx | 61 +++++++++++-------- .../server/routers/booking/output.ts | 15 +++-- .../stores/my-stay/add-ancillary-flow.ts | 1 + 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/PriceDetails/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/PriceDetails/index.tsx index a618f6ce9..ba23d6cdd 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/PriceDetails/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/PriceDetails/index.tsx @@ -46,8 +46,12 @@ export default function PriceDetails({ } const totalPrice = isBreakfast - ? breakfastData!.priceAdult * breakfastData!.nrOfAdults + - breakfastData!.priceChild * breakfastData!.nrOfPayingChildren + ? breakfastData!.priceAdult * + breakfastData!.nrOfAdults * + breakfastData!.nrOfNights + + breakfastData!.priceChild * + breakfastData!.nrOfPayingChildren * + breakfastData!.nrOfNights : quantityWithCard && selectedAncillary ? selectedAncillary.price.total * quantityWithCard : null @@ -73,7 +77,7 @@ export default function PriceDetails({ title: `${selectedAncillary.title} / ${intl.formatMessage({ id: "Adult" })}`, totalPrice: breakfastData.priceAdult, currency: breakfastData.currency, - quantityWithCard: breakfastData.nrOfAdults, + quantityWithCard: breakfastData.nrOfAdults * breakfastData.nrOfNights, }, ] @@ -82,7 +86,8 @@ export default function PriceDetails({ title: `${selectedAncillary.title} / ${intl.formatMessage({ id: "Children" })} 4-12`, totalPrice: breakfastData.priceChild, currency: breakfastData.currency, - quantityWithCard: breakfastData.nrOfPayingChildren, + quantityWithCard: + breakfastData.nrOfPayingChildren * breakfastData.nrOfNights, }) } @@ -91,7 +96,8 @@ export default function PriceDetails({ title: `${selectedAncillary.title} / ${intl.formatMessage({ id: "Children under {age}" }, { age: 4 })}`, totalPrice: 0, currency: breakfastData.currency, - quantityWithCard: breakfastData.nrOfFreeChildren, + quantityWithCard: + breakfastData.nrOfFreeChildren * breakfastData.nrOfNights, }) } diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/index.tsx index ca5318ddc..477fc668d 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddAncillaryFlow/AddAncillaryFlowModal/index.tsx @@ -11,6 +11,7 @@ import { Typography } from "@scandic-hotels/design-system/Typography" import { PaymentMethodEnum } from "@/constants/booking" import { guaranteeCallback } from "@/constants/routes/hotelReservation" import { env } from "@/env/client" +import { dt } from "@/lib/dt" import { trpc } from "@/lib/trpc/client" import { AncillaryStepEnum, @@ -300,11 +301,16 @@ export default function AddAncillaryFlowModal({ isBreakfast, packages, booking.adults, - booking.childrenAges + booking.childrenAges, + dt(booking.checkOutDate) + .startOf("day") + .diff(dt(booking.checkInDate).startOf("day"), "days") ) ) }, [ booking.adults, + booking.checkInDate, + booking.checkOutDate, booking.childrenAges, isBreakfast, packages, @@ -471,7 +477,8 @@ function calculateBreakfastData( isBreakfast: boolean, packages: Packages | null, nrOfAdults: number, - childrenAges: number[] + childrenAges: number[], + nrOfNights: number ): BreakfastData | null { if (!isBreakfast) { return null @@ -503,6 +510,7 @@ function calculateBreakfastData( nrOfAdults, nrOfPayingChildren, nrOfFreeChildren, + nrOfNights, priceAdult, priceChild, currency, diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx index 86b8e1a3d..a85373909 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/index.tsx @@ -168,35 +168,42 @@ export function Ancillaries({ return (
-
- - {intl.formatMessage({ id: "Upgrade your stay" })} - - -
+ {uniqueAncillaries.length > 0 && ( + <> +
+ + {intl.formatMessage({ id: "Upgrade your stay" })} + + +
-
- {uniqueAncillaries.slice(0, 4).map((ancillary) => ( - - ))} -
+
+ {uniqueAncillaries.slice(0, 4).map((ancillary) => ( + + ))} +
-
- - - {uniqueAncillaries.map((ancillary) => { - return ( - - - - ) - })} - - - - - -
+
+ + + {uniqueAncillaries.map((ancillary) => { + return ( + + + + ) + })} + + + + + +
+ + )} diff --git a/apps/scandic-web/server/routers/booking/output.ts b/apps/scandic-web/server/routers/booking/output.ts index d490e5c5f..130538d72 100644 --- a/apps/scandic-web/server/routers/booking/output.ts +++ b/apps/scandic-web/server/routers/booking/output.ts @@ -9,6 +9,7 @@ import { nullableStringValidator, } from "@/utils/zod/stringValidator" +import { BreakfastPackageEnum } from "@/types/enums/breakfast" import { CurrencyEnum } from "@/types/enums/currency" const guestSchema = z.object({ @@ -250,11 +251,15 @@ export const bookingConfirmationSchema = z packages: data.attributes.packages.filter((p) => p.type !== "Ancillary"), ancillaries: data.attributes.packages.filter((p) => p.type === "Ancillary"), extraBedTypes: data.attributes.childBedPreferences, - showAncillaries: !!( - data.links.addAncillary || - data.attributes.packages.some((p) => p.type === "Ancillary") || - data.attributes.reservationStatus === BookingStatusEnum.Cancelled - ), + showAncillaries: + !!( + data.links.addAncillary || + data.attributes.packages.some( + (p) => + p.type === "Ancillary" || + p.code === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST + ) + ) && data.attributes.reservationStatus !== BookingStatusEnum.Cancelled, isCancelable: !!data.links.cancel, isModifiable: !!data.links.modify, })) diff --git a/apps/scandic-web/stores/my-stay/add-ancillary-flow.ts b/apps/scandic-web/stores/my-stay/add-ancillary-flow.ts index ebdff19e7..bed6f315e 100644 --- a/apps/scandic-web/stores/my-stay/add-ancillary-flow.ts +++ b/apps/scandic-web/stores/my-stay/add-ancillary-flow.ts @@ -34,6 +34,7 @@ export type BreakfastData = { nrOfAdults: number nrOfPayingChildren: number nrOfFreeChildren: number + nrOfNights: number priceAdult: number priceChild: number currency: string