feat(SW-977): Scenario 2 & 4

This commit is contained in:
Pontus Dreij
2024-12-11 14:53:51 +01:00
parent 4f92d1da08
commit c635a8b072
3 changed files with 42 additions and 3 deletions

View File

@@ -124,10 +124,12 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
typeof window !== "undefined"
? sessionStorage.getItem(sessionStorageKey)
: undefined
const searchHistory =
typeof window !== "undefined"
? localStorage.getItem(localStorageKey)
: null
if (searchData || searchHistory) {
dispatch({
payload: {
@@ -160,13 +162,18 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
}
}, [stayType, stayValue, unregister, setValue])
useEffect(() => {
sessionStorage.setItem(sessionStorageKey, locationString)
}, [locationString])
function getLocationLabel(): string {
if (state.searchData?.type === "hotels") {
return state.searchData?.relationships?.city?.name || ""
}
if (location?.type === "hotels") {
return location?.relationships?.city?.name || ""
}
if (state.searchData?.type === "hotels") {
return state.searchData?.relationships?.city?.name || ""
}
return intl.formatMessage({ id: "Where to" })
}