import { useRouter } from "next/navigation" import { useIntl } from "react-intl" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton" import { trpc } from "@scandic-hotels/trpc/client" import Dialog from "@/components/Dialog" import { toast } from "@/components/TempDesignSystem/Toasts" 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({ 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, addedBreakfastPackages ) router.refresh() close() }, onError: () => { toast.error( intl.formatMessage({ defaultMessage: "Something went wrong!", }) ) }, } ) }} /> ) }