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