import { useRouter } from "next/navigation" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { trpc } from "@/lib/trpc/client" 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, booking, ancillary, }: { refId: string codes: string[] title?: string 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 ( {intl.formatMessage({ defaultMessage: "Remove", })} } proceedOnClick={(close) => { removePackage.mutate( { language: lang, refId, codes, }, { onSuccess: (data) => { if (!data) { throw new Error() } utils.booking.get.invalidate({ refId: refId, }) trackRemoveAncillary( ancillary, booking.hotelId, booking.ancillary?.deliveryTime ) router.refresh() close() }, onError: () => { toast.error( intl.formatMessage({ defaultMessage: "Something went wrong!", }) ) }, } ) }} /> ) }