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,
|
||||
})
|
||||
|
||||
const sessionStorageSearchData =
|
||||
typeof window !== "undefined"
|
||||
? sessionStorage.getItem("searchData")
|
||||
: undefined
|
||||
const initialSelectedLocation: Location | undefined = sessionStorageSearchData
|
||||
? JSON.parse(sessionStorageSearchData)
|
||||
: undefined
|
||||
|
||||
const bookingWidgetSearchData: BookingWidgetSearchParams | undefined =
|
||||
searchParams
|
||||
@@ -85,12 +78,10 @@ export default function BookingWidgetClient({
|
||||
|
||||
const methods = useForm<BookingWidgetSchema>({
|
||||
defaultValues: {
|
||||
search: selectedLocation?.name ?? initialSelectedLocation?.name ?? "",
|
||||
search: selectedLocation?.name ?? "",
|
||||
location: selectedLocation
|
||||
? JSON.stringify(selectedLocation)
|
||||
: sessionStorageSearchData
|
||||
? encodeURIComponent(sessionStorageSearchData)
|
||||
: undefined,
|
||||
: 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.
|
||||
@@ -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 (
|
||||
<FormProvider {...methods}>
|
||||
<section ref={bookingWidgetRef} className={styles.containerDesktop}>
|
||||
|
||||
Reference in New Issue
Block a user