diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx index 653a560a9..57474186d 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx @@ -11,12 +11,12 @@ import useLang from "@/hooks/useLang" export default function RemoveButton({ confirmationNumber, - code, + codes, title, onSuccess, }: { confirmationNumber: string - code: string + codes: string[] title?: string onSuccess: () => void }) { @@ -44,7 +44,7 @@ export default function RemoveButton({ { language: lang, confirmationNumber, - codes: [code], + codes, }, { onSuccess: (data) => { diff --git a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx index 53dba4495..cc647b30f 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx @@ -1,5 +1,4 @@ import { useRouter } from "next/navigation" -import { useMemo } from "react" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons" @@ -18,7 +17,10 @@ import styles from "./addedAncillaries.module.css" import type { AddedAncillariesProps } from "@/types/components/myPages/myStay/ancillaries" import { BreakfastPackageEnum } from "@/types/enums/breakfast" -import type { PackageSchema } from "@/types/trpc/routers/booking/confirmation" +import type { + BookingConfirmation, + PackageSchema, +} from "@/types/trpc/routers/booking/confirmation" export function AddedAncillaries({ ancillaries, @@ -27,42 +29,11 @@ export function AddedAncillaries({ const intl = useIntl() const router = useRouter() - /** - * All ancillaries that are added to the booking - * - * Adding a special ancillary for breakfast, calculated from - * all breakfast packages that has been added as ancillaries, - * not in the booking flow. - */ - const addedAncillaries = useMemo(() => { - const addedBreakfastPackages = getBreakfastPackagesFromAncillaryFlow( - booking.packages - ) - if (!addedBreakfastPackages?.length) { - return booking.ancillaries - } + const addedBreakfastPackages = getBreakfastPackagesFromAncillaryFlow( + booking.packages + ) - const combinedBreakfastPackageAsAncillary: PackageSchema = { - code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST, - unitPrice: 0, - points: 0, - currency: addedBreakfastPackages[0].currency, - type: addedBreakfastPackages[0].type, - description: addedBreakfastPackages[0].description, - comment: addedBreakfastPackages[0].comment, - totalPrice: addedBreakfastPackages.reduce( - (acc, curr) => acc + curr.totalPrice, - 0 - ), - unit: addedBreakfastPackages.reduce((acc, curr) => acc + curr.unit, 0), - totalUnit: addedBreakfastPackages.reduce( - (acc, curr) => acc + curr.totalUnit, - 0 - ), - } - - return [combinedBreakfastPackageAsAncillary, ...booking.ancillaries] - }, [booking.ancillaries, booking.packages]) + const addedAncillaries = getAddedAncillaries(booking, addedBreakfastPackages) if (addedAncillaries.length === 0) { return null @@ -133,7 +104,12 @@ export function AddedAncillaries({
p.code) + : [ancillary.code] + } title={ancillaryTitle} onSuccess={router.refresh} /> @@ -179,7 +155,12 @@ export function AddedAncillaries({
p.code) + : [ancillary.code] + } title={ancillaryTitle} onSuccess={() => { trackRemoveAncillary( @@ -200,3 +181,40 @@ export function AddedAncillaries({
) } + +/** + * All ancillaries that are added to the booking + * + * Adding a special ancillary for breakfast, calculated from + * all breakfast packages that has been added as ancillaries, + * not in the booking flow. + */ +function getAddedAncillaries( + booking: BookingConfirmation["booking"], + addedBreakfastPackages: PackageSchema[] | undefined +) { + if (!addedBreakfastPackages?.length) { + return booking.ancillaries + } + + const combinedBreakfastPackageAsAncillary: PackageSchema = { + code: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST, + unitPrice: 0, + points: 0, + currency: addedBreakfastPackages[0].currency, + type: addedBreakfastPackages[0].type, + description: addedBreakfastPackages[0].description, + comment: addedBreakfastPackages[0].comment, + totalPrice: addedBreakfastPackages.reduce( + (acc, curr) => acc + curr.totalPrice, + 0 + ), + unit: addedBreakfastPackages.reduce((acc, curr) => acc + curr.unit, 0), + totalUnit: addedBreakfastPackages.reduce( + (acc, curr) => acc + curr.totalUnit, + 0 + ), + } + + return [combinedBreakfastPackageAsAncillary, ...booking.ancillaries] +} diff --git a/apps/scandic-web/server/routers/booking/mutation.ts b/apps/scandic-web/server/routers/booking/mutation.ts index b079a169f..d4e42f585 100644 --- a/apps/scandic-web/server/routers/booking/mutation.ts +++ b/apps/scandic-web/server/routers/booking/mutation.ts @@ -576,7 +576,7 @@ export const bookingMutationRouter = router({ { headers, } as RequestInit, - { language, codes } + [["language", language], ...codes.map((code) => ["codes", code])] ) if (!apiResponse.ok) {