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
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"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
|
||||
}
|
||||
Reference in New Issue
Block a user