Merged in fix/SW-1335/city-label-missing (pull request #1218)

Fix/SW-1335/city label missing

* fix(SW-1335): add fallback label when missing

* fix(SW-1335): update location if valid


Approved-by: Niclas Edenvin
This commit is contained in:
Bianca Widstam
2025-01-28 12:51:15 +00:00
parent ef22fc4627
commit 8d755071bc

View File

@@ -38,7 +38,7 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
const value = useWatch({ name })
const locationString = getValues("location")
const location =
locationString && isValidJson(locationString)
locationString && isValidJson(decodeURIComponent(locationString))
? JSON.parse(decodeURIComponent(locationString))
: null
const [state, dispatch] = useReducer(
@@ -98,7 +98,6 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
setValue("location", encodeURIComponent(stringified))
sessionStorage.setItem(sessionStorageKey, stringified)
setValue(name, selectedItem.name)
const newHistoryItem: SearchHistoryItem = {
type: selectedItem.type,
id: selectedItem.id,
@@ -178,14 +177,14 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
}, [location])
function getLocationLabel(): string {
const fallbackLabel = intl.formatMessage({ id: "Where to" })
if (location?.type === "hotels") {
return location?.relationships?.city?.name || ""
return location?.relationships?.city?.name || fallbackLabel
}
if (state.searchData?.type === "hotels") {
return state.searchData?.relationships?.city?.name || ""
return state.searchData?.relationships?.city?.name || fallbackLabel
}
return intl.formatMessage({ id: "Where to" })
return fallbackLabel
}
return (