fix: improve handling of booking widget params from search params

now we are defensive in parsing the location
if parsing fails the not found is now displayed
This commit is contained in:
Michael Zetterberg
2025-02-25 13:29:39 +01:00
parent 15fa01cbb2
commit 43c25aea95
3 changed files with 66 additions and 55 deletions

View File

@@ -317,12 +317,21 @@ export const locationsSchema = z.object({
},
},
type: location.type,
operaId: location.attributes.operaId ?? "",
}
})
)
.transform((data) =>
data
.filter((node) => !!node)
.filter((node) => {
if (node.type === "hotels") {
if (!node.operaId) {
return false
}
}
return true
})
.sort((a, b) => {
if (a.type === b.type) {
return a.name.localeCompare(b.name)

View File

@@ -13,7 +13,7 @@ export const locationHotelSchema = z.object({
.optional(),
keyWords: z.array(z.string()).optional(),
name: z.string().optional().default(""),
operaId: z.string().optional(),
operaId: z.coerce.string().optional(),
}),
id: z.string().optional().default(""),
relationships: z