Files
web/apps/scandic-web/components/HotelReservation/SelectRate/AvailabilityError.tsx
Joakim Jäderberg 72f4f72a17 Merged in SW-3317-move-toast-to-design-system (pull request #2716)
SW-3317 move toast to design system

* chore: Move toast to design-system and add interaction tests

* Move toast to design-system and add storybook tests

* Merge branch 'master' of bitbucket.org:scandic-swap/web into SW-3317-move-toast-to-design-system

* merge

* move sonner dependency to @scandic-hotels/design-system


Approved-by: Anton Gunnarsson
2025-08-27 13:03:17 +00:00

36 lines
1.1 KiB
TypeScript

"use client"
import { usePathname, useSearchParams } from "next/navigation"
import { useEffect } from "react"
import { useIntl } from "react-intl"
import { toast } from "@scandic-hotels/design-system/Toast"
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
export default function AvailabilityError() {
const intl = useIntl()
const pathname = usePathname()
const searchParams = useSearchParams()
const errorCode = searchParams.get("errorCode")
const hasAvailabilityError =
errorCode === BookingErrorCodeEnum.AvailabilityError
const errorMessage = intl.formatMessage({
defaultMessage:
"Unfortunately, one of the rooms you selected is sold out. Please choose another room to proceed.",
})
useEffect(() => {
if (hasAvailabilityError) {
toast.error(errorMessage)
const newParams = new URLSearchParams(searchParams.toString())
newParams.delete("errorCode")
window.history.replaceState({}, "", `${pathname}?${newParams.toString()}`)
}
}, [errorMessage, hasAvailabilityError, pathname, searchParams])
return null
}