From d45487a3c777d91c762d034a9fcd48e78abb6cfc Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Sat, 8 Mar 2025 07:53:39 +0000 Subject: [PATCH] fix(SW-1830): Adjusted schemas for city and country pages to accept less data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(SW-1830): Adjusted schemas for city and country pages to accept less data Approved-by: Fredrik Thorsson Approved-by: Matilda Landström --- .../DestinationCityPage/index.tsx | 6 +- .../DestinationCountryPage/index.tsx | 9 ++- .../DestinationPage/Sidepeek/index.tsx | 6 +- .../DestinationPage/TopImages/index.tsx | 2 +- .../destinationCityPage/output.ts | 68 ++++++++++--------- .../destinationCountryPage/output.ts | 43 ++++++------ 6 files changed, 76 insertions(+), 58 deletions(-) diff --git a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx index 782264645..b72ebfd23 100644 --- a/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx +++ b/apps/scandic-web/components/ContentType/DestinationPage/DestinationCityPage/index.tsx @@ -51,7 +51,9 @@ export default async function DestinationCityPage() {
- + {images?.length && ( + + )}
@@ -61,7 +63,7 @@ export default async function DestinationCityPage() { {preamble} - {has_sidepeek && ( + {has_sidepeek && sidepeek_content && ( - + {images?.length && ( + + )}
@@ -65,7 +70,7 @@ export default async function DestinationCountryPage() { {preamble} - {has_sidepeek && ( + {has_sidepeek && sidepeek_content && ( - {buttonText} + {buttonText || intl.formatMessage({ id: "Read more" })} destination_experiences), + .nullish() + .transform((experiences) => experiences?.destination_experiences ?? []), images: z .array(z.object({ image: tempImageVaultAssetSchema })) .transform((images) => images .map((image) => image.image) .filter((image): image is ImageVaultAsset => !!image) - ), + ) + .nullish(), has_sidepeek: z.boolean().default(false), - sidepeek_button_text: z.string().default(""), - sidepeek_content: z.object({ - heading: z.string(), - content: z.object({ - json: z.any(), - embedded_itemsConnection: z.object({ - edges: z.array( - z.object({ - node: linkUnionSchema.transform((data) => { - const link = transformPageLink(data) - if (link) { - return link - } - return data - }), - }) - ), + sidepeek_button_text: z.string().nullish().default(""), + sidepeek_content: z + .object({ + heading: z.string(), + content: z.object({ + json: z.any(), + embedded_itemsConnection: z.object({ + edges: z.array( + z.object({ + node: linkUnionSchema.transform((data) => { + const link = transformPageLink(data) + if (link) { + return link + } + return data + }), + }) + ), + }), }), - }), - }), + }) + .nullish(), blocks: discriminatedUnionArray(blocksSchema.options).nullable(), system: systemSchema.merge( z.object({ @@ -228,17 +232,19 @@ const blocksRefsSchema = z.discriminatedUnion("__typename", [ export const destinationCityPageRefsSchema = z.object({ destination_city_page: z.object({ - sidepeek_content: z.object({ - content: z.object({ - embedded_itemsConnection: z.object({ - edges: z.array( - z.object({ - node: linkRefsUnionSchema, - }) - ), + sidepeek_content: z + .object({ + content: z.object({ + embedded_itemsConnection: z.object({ + edges: z.array( + z.object({ + node: linkRefsUnionSchema, + }) + ), + }), }), - }), - }), + }) + .nullish(), blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(), system: systemSchema, }), diff --git a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/output.ts b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/output.ts index 553f8f4a6..551b0450b 100644 --- a/apps/scandic-web/server/routers/contentstack/destinationCountryPage/output.ts +++ b/apps/scandic-web/server/routers/contentstack/destinationCountryPage/output.ts @@ -63,28 +63,31 @@ export const destinationCountryPageSchema = z.object({ images .map((image) => image.image) .filter((image): image is ImageVaultAsset => !!image) - ), + ) + .nullish(), has_sidepeek: z.boolean().default(false), - sidepeek_button_text: z.string().default(""), - sidepeek_content: z.object({ - heading: z.string(), - content: z.object({ - json: z.any(), - embedded_itemsConnection: z.object({ - edges: z.array( - z.object({ - node: linkUnionSchema.transform((data) => { - const link = transformPageLink(data) - if (link) { - return link - } - return data - }), - }) - ), + sidepeek_button_text: z.string().nullish(), + sidepeek_content: z + .object({ + heading: z.string(), + content: z.object({ + json: z.any(), + embedded_itemsConnection: z.object({ + edges: z.array( + z.object({ + node: linkUnionSchema.transform((data) => { + const link = transformPageLink(data) + if (link) { + return link + } + return data + }), + }) + ), + }), }), - }), - }), + }) + .nullish(), blocks: discriminatedUnionArray(blocksSchema.options).nullable(), system: systemSchema.merge( z.object({