import { useRouter } from "next/navigation" import { useIntl } from "react-intl" import { Button } from "@scandic-hotels/design-system/Button" import { toast } from "@scandic-hotels/design-system/Toast" import { trpc } from "@scandic-hotels/trpc/client" import Dialog from "@/components/Dialog" import useLang from "@/hooks/useLang" import { trackRemoveAncillary } from "@/utils/tracking/myStay" import type { PackageSchema } from "@scandic-hotels/trpc/types/bookingConfirmation" import type { Room } from "@/types/stores/my-stay" export default function RemoveButton({ refId, codes, title, booking, ancillary, addedBreakfastPackages, }: { refId: string codes: string[] title?: string booking: Room ancillary: PackageSchema addedBreakfastPackages: PackageSchema[] | undefined }) { const lang = useLang() const intl = useIntl() const utils = trpc.useUtils() const router = useRouter() const removePackage = trpc.booking.removePackage.useMutation() return ( {intl.formatMessage({ id: "common.remove", defaultMessage: "Remove", })} } proceedOnClick={(close) => { removePackage.mutate( { language: lang, refId, codes, }, { onSuccess: (data) => { if (!data) { throw new Error() } toast.success( intl.formatMessage({ id: "myStay.removeAncillary.success", defaultMessage: "The product has now been removed from your booking.", }) ) utils.booking.get.invalidate({ refId: refId, }) trackRemoveAncillary( ancillary, booking.hotelId, booking.ancillary?.deliveryTime, addedBreakfastPackages ) router.refresh() close() }, onError: () => { toast.error( intl.formatMessage({ id: "errorMessage.somethingWentWrong", defaultMessage: "Something went wrong!", }) ) }, } ) }} /> ) }