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 75300af24..4bf3dbf98 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/RemoveButton.tsx @@ -1,3 +1,4 @@ +import { useRouter } from "next/navigation" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" @@ -8,20 +9,31 @@ import Dialog from "@/components/Dialog" import Button from "@/components/TempDesignSystem/Button" import { toast } from "@/components/TempDesignSystem/Toasts" import useLang from "@/hooks/useLang" +import { trackRemoveAncillary } from "@/utils/tracking/myStay" + +import type { + BookingConfirmation, + PackageSchema, +} from "@/types/trpc/routers/booking/confirmation" export default function RemoveButton({ refId, codes, title, - onSuccess, + booking, + ancillary, }: { refId: string codes: string[] title?: string - onSuccess: () => void + booking: BookingConfirmation["booking"] + ancillary: PackageSchema }) { const lang = useLang() const intl = useIntl() + const utils = trpc.useUtils() + const router = useRouter() + const removePackage = trpc.booking.removePackage.useMutation() return ( @@ -59,9 +71,17 @@ export default function RemoveButton({ if (!data) { throw new Error() } + utils.booking.get.invalidate({ + refId: refId, + }) + trackRemoveAncillary( + ancillary, + booking.hotelId, + booking.ancillary?.deliveryTime + ) + router.refresh() close() - onSuccess() }, onError: () => { toast.error( 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 08f8349df..c1ab9af12 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/Ancillaries/AddedAncillaries/index.tsx @@ -1,4 +1,3 @@ -import { useRouter } from "next/navigation" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" @@ -8,7 +7,6 @@ import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem import Divider from "@/components/TempDesignSystem/Divider" import Body from "@/components/TempDesignSystem/Text/Body" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" -import { trackRemoveAncillary } from "@/utils/tracking/myStay" import { getBreakfastPackagesFromAncillaryFlow } from "../../utils/hasBreakfastPackage" import RemoveButton from "./RemoveButton" @@ -27,7 +25,6 @@ export function AddedAncillaries({ booking, }: AddedAncillariesProps) { const intl = useIntl() - const router = useRouter() const addedBreakfastPackages = getBreakfastPackagesFromAncillaryFlow( booking.packages @@ -134,7 +131,8 @@ export function AddedAncillaries({ : [ancillary.code] } title={ancillaryTitle} - onSuccess={router.refresh} + booking={booking} + ancillary={ancillary} /> ) : null} @@ -200,14 +198,8 @@ export function AddedAncillaries({ : [ancillary.code] } title={ancillaryTitle} - onSuccess={() => { - trackRemoveAncillary( - ancillary, - booking.hotelId, - booking.ancillary?.deliveryTime - ) - router.refresh() - }} + booking={booking} + ancillary={ancillary} /> ) : null}