diff --git a/components/Forms/BookingWidget/FormContent/Search/index.tsx b/components/Forms/BookingWidget/FormContent/Search/index.tsx index 109af79a3..83e56a222 100644 --- a/components/Forms/BookingWidget/FormContent/Search/index.tsx +++ b/components/Forms/BookingWidget/FormContent/Search/index.tsx @@ -25,14 +25,15 @@ import type { Location } from "@/types/trpc/routers/hotel/locations" const name = "search" export default function Search({ locations }: SearchProps) { - const [state, dispatch] = useReducer( - reducer, - { defaultLocations: locations }, - init - ) const { register, setValue, trigger } = useFormContext() const intl = useIntl() const value = useWatch({ name }) + const searchData = useWatch({ name: "location" }) + const [state, dispatch] = useReducer( + reducer, + { defaultLocations: locations, searchData }, + init + ) const handleMatchLocations = useCallback( function (searchValue: string) { diff --git a/components/Forms/BookingWidget/FormContent/Search/reducer.ts b/components/Forms/BookingWidget/FormContent/Search/reducer.ts index 9771d11b2..088fcf430 100644 --- a/components/Forms/BookingWidget/FormContent/Search/reducer.ts +++ b/components/Forms/BookingWidget/FormContent/Search/reducer.ts @@ -22,27 +22,14 @@ export function getSearchHistoryFromLocalStorage() { } export const sessionStorageKey = "searchData" -export function getSearchDataFromSessionStorage() { - if (typeof window !== "undefined") { - const storageSearchData = window.sessionStorage.getItem(sessionStorageKey) - if (storageSearchData) { - const parsedStorageSearchData: Location = JSON.parse(storageSearchData) - if (parsedStorageSearchData) { - return parsedStorageSearchData - } - } - } - return undefined -} export function init(initState: InitState): State { const searchHistory = getSearchHistoryFromLocalStorage() - const searchData = getSearchDataFromSessionStorage() return { defaultLocations: initState.defaultLocations, locations: [], search: "", - searchData, + searchData: initState.searchData, searchHistory, } } diff --git a/types/components/form/bookingwidget.ts b/types/components/form/bookingwidget.ts index 997890ca3..df6a86030 100644 --- a/types/components/form/bookingwidget.ts +++ b/types/components/form/bookingwidget.ts @@ -60,4 +60,5 @@ export interface State { searchHistory: Locations | null } -export interface InitState extends Pick {} +export interface InitState + extends Pick {}