Merge branch 'master' into feature/tracking
This commit is contained in:
@@ -36,14 +36,6 @@ export default function BookingWidgetClient({
|
||||
name: StickyElementNameEnum.BOOKING_WIDGET,
|
||||
})
|
||||
|
||||
const sessionStorageSearchData =
|
||||
typeof window !== "undefined"
|
||||
? sessionStorage.getItem("searchData")
|
||||
: undefined
|
||||
const initialSelectedLocation: Location | undefined = sessionStorageSearchData
|
||||
? JSON.parse(sessionStorageSearchData)
|
||||
: undefined
|
||||
|
||||
const bookingWidgetSearchData: BookingWidgetSearchParams | undefined =
|
||||
searchParams
|
||||
? (getFormattedUrlQueryParams(new URLSearchParams(searchParams), {
|
||||
@@ -85,21 +77,17 @@ export default function BookingWidgetClient({
|
||||
|
||||
const methods = useForm<BookingWidgetSchema>({
|
||||
defaultValues: {
|
||||
search: selectedLocation?.name ?? initialSelectedLocation?.name ?? "",
|
||||
location: selectedLocation
|
||||
? JSON.stringify(selectedLocation)
|
||||
: sessionStorageSearchData
|
||||
? encodeURIComponent(sessionStorageSearchData)
|
||||
: undefined,
|
||||
search: selectedLocation?.name ?? "",
|
||||
location: selectedLocation ? JSON.stringify(selectedLocation) : undefined,
|
||||
date: {
|
||||
// UTC is required to handle requests from far away timezones https://scandichotels.atlassian.net/browse/SWAP-6375 & PET-507
|
||||
// This is specifically to handle timezones falling in different dates.
|
||||
fromDate: isDateParamValid
|
||||
? bookingWidgetSearchData?.fromDate?.toString()
|
||||
: dt().utc().format("YYYY-MM-DD"),
|
||||
? dt(bookingWidgetSearchData?.fromDate).format("YYYY-M-D")
|
||||
: dt().utc().format("YYYY-M-D"),
|
||||
toDate: isDateParamValid
|
||||
? bookingWidgetSearchData?.toDate?.toString()
|
||||
: dt().utc().add(1, "day").format("YYYY-MM-DD"),
|
||||
? dt(bookingWidgetSearchData?.toDate).format("YYYY-M-D")
|
||||
: dt().utc().add(1, "day").format("YYYY-M-D"),
|
||||
},
|
||||
bookingCode: "",
|
||||
redemption: false,
|
||||
@@ -146,6 +134,24 @@ export default function BookingWidgetClient({
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const sessionStorageSearchData =
|
||||
typeof window !== "undefined"
|
||||
? sessionStorage.getItem("searchData")
|
||||
: undefined
|
||||
const initialSelectedLocation: Location | undefined =
|
||||
sessionStorageSearchData
|
||||
? JSON.parse(sessionStorageSearchData)
|
||||
: undefined
|
||||
|
||||
!selectedLocation?.name &&
|
||||
initialSelectedLocation?.name &&
|
||||
methods.setValue("search", initialSelectedLocation.name)
|
||||
!selectedLocation &&
|
||||
sessionStorageSearchData &&
|
||||
methods.setValue("location", encodeURIComponent(sessionStorageSearchData))
|
||||
}, [methods, selectedLocation])
|
||||
|
||||
return (
|
||||
<FormProvider {...methods}>
|
||||
<section ref={bookingWidgetRef} className={styles.containerDesktop}>
|
||||
|
||||
Reference in New Issue
Block a user