Files
web/apps/scandic-web/components/HotelReservation/SelectRate/AvailabilityError.tsx
Tobias Johansson bf79168216 Merged in fix/SW-2462-room-availability-error (pull request #1920)
Fix/SW-2462 room availability error

* fix: added toast error when availability fails and you get redirect to select-rate

* fix: added support for showing alert when availability error happens

* fix: rename PaymentAlert -> BookingAlert


Approved-by: Erik Tiekstra
2025-05-02 08:35:29 +00:00

39 lines
1.1 KiB
TypeScript

"use client"
import { usePathname, useSearchParams } from "next/navigation"
import { useEffect } from "react"
import { useIntl } from "react-intl"
import { BookingErrorCodeEnum } from "@/constants/booking"
import { toast } from "@/components/TempDesignSystem/Toasts"
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) {
return
}
toast.error(errorMessage)
const newParams = new URLSearchParams(searchParams.toString())
newParams.delete("errorCode")
window.history.replaceState({}, "", `${pathname}?${newParams.toString()}`)
}, [errorMessage, hasAvailabilityError, pathname, searchParams])
return null
}