fix: SW-693 Moved sessionstorage usage in useEffect
This commit is contained in:
@@ -36,13 +36,6 @@ export default function BookingWidgetClient({
|
|||||||
name: StickyElementNameEnum.BOOKING_WIDGET,
|
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 =
|
const bookingWidgetSearchData: BookingWidgetSearchParams | undefined =
|
||||||
searchParams
|
searchParams
|
||||||
@@ -85,12 +78,10 @@ export default function BookingWidgetClient({
|
|||||||
|
|
||||||
const methods = useForm<BookingWidgetSchema>({
|
const methods = useForm<BookingWidgetSchema>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
search: selectedLocation?.name ?? initialSelectedLocation?.name ?? "",
|
search: selectedLocation?.name ?? "",
|
||||||
location: selectedLocation
|
location: selectedLocation
|
||||||
? JSON.stringify(selectedLocation)
|
? JSON.stringify(selectedLocation)
|
||||||
: sessionStorageSearchData
|
: undefined,
|
||||||
? encodeURIComponent(sessionStorageSearchData)
|
|
||||||
: undefined,
|
|
||||||
date: {
|
date: {
|
||||||
// UTC is required to handle requests from far away timezones https://scandichotels.atlassian.net/browse/SWAP-6375 & PET-507
|
// 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.
|
// This is specifically to handle timezones falling in different dates.
|
||||||
@@ -146,6 +137,22 @@ 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 (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<section ref={bookingWidgetRef} className={styles.containerDesktop}>
|
<section ref={bookingWidgetRef} className={styles.containerDesktop}>
|
||||||
|
|||||||
Reference in New Issue
Block a user