Merged in fix/SW-2648-remove-ancillary-update-price (pull request #2002)

fix(SW-2648): refresh mystay after removing ancillary

* fix(SW-2648): refresh mystay after removing ancillary


Approved-by: Niclas Edenvin
This commit is contained in:
Bianca Widstam
2025-05-08 06:48:01 +00:00
parent ef2d4a3846
commit 0fd18590c5
2 changed files with 27 additions and 15 deletions

View File

@@ -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(

View File

@@ -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}
/>
</div>
) : 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}
/>
</div>
) : null}