feat(SW-977): Add more controls if Json is valid
This commit is contained in:
@@ -34,9 +34,10 @@ export default function Search({ locations, handlePressEnter }: SearchProps) {
|
||||
const intl = useIntl()
|
||||
const value = useWatch({ name })
|
||||
const locationString = getValues("location")
|
||||
const location = locationString
|
||||
? JSON.parse(decodeURIComponent(locationString))
|
||||
: null
|
||||
const location =
|
||||
locationString && isValidJson(locationString)
|
||||
? JSON.parse(decodeURIComponent(locationString))
|
||||
: null
|
||||
const [state, dispatch] = useReducer(
|
||||
reducer,
|
||||
{ defaultLocations: locations },
|
||||
|
||||
@@ -45,7 +45,10 @@ export const bookingWidgetSchema = z
|
||||
}),
|
||||
location: z.string().refine(
|
||||
(value) => {
|
||||
if (value) {
|
||||
if (!value) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const parsedValue: Location = JSON.parse(decodeURIComponent(value))
|
||||
switch (parsedValue?.type) {
|
||||
case "cities":
|
||||
@@ -54,6 +57,8 @@ export const bookingWidgetSchema = z
|
||||
default:
|
||||
return false
|
||||
}
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
{ message: "Required" }
|
||||
|
||||
Reference in New Issue
Block a user