From ed052dbfa43b454335cc443acefd1e6a69f865a6 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Mon, 13 May 2024 16:41:50 +0200 Subject: [PATCH] fix: change optional to nullable in validation --- components/TempDesignSystem/Card/card.ts | 4 +-- lib/graphql/Query/LoyaltyPage.graphql | 1 + .../contentstack/contactConfig/output.ts | 2 +- .../contentstack/loyaltyPage/output.ts | 35 ++++++++++--------- .../routers/contentstack/loyaltyPage/query.ts | 6 ++-- types/components/myPages/myPage/shortcuts.ts | 2 +- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/components/TempDesignSystem/Card/card.ts b/components/TempDesignSystem/Card/card.ts index 3c346f423..d226e3c8f 100644 --- a/components/TempDesignSystem/Card/card.ts +++ b/components/TempDesignSystem/Card/card.ts @@ -3,7 +3,7 @@ export type CardProps = { href: string title: string } - title?: string - subtitle?: string + title?: string | null + subtitle?: string | null openInNewTab?: boolean } diff --git a/lib/graphql/Query/LoyaltyPage.graphql b/lib/graphql/Query/LoyaltyPage.graphql index c1bb19cc7..b71b62c71 100644 --- a/lib/graphql/Query/LoyaltyPage.graphql +++ b/lib/graphql/Query/LoyaltyPage.graphql @@ -91,6 +91,7 @@ query GetLoyaltyPage($locale: String!, $url: String!) { } } title + heading sidebar { __typename ... on LoyaltyPageSidebarJoinLoyaltyContact { diff --git a/server/routers/contentstack/contactConfig/output.ts b/server/routers/contentstack/contactConfig/output.ts index c42a19dc9..5247f2475 100644 --- a/server/routers/contentstack/contactConfig/output.ts +++ b/server/routers/contentstack/contactConfig/output.ts @@ -55,6 +55,6 @@ export type ContactConfigData = z.infer export type ContactConfig = ContactConfigData["all_contact_config"]["items"][0] export type ContactFields = { - display_text?: string + display_text: string | null contact_field: string } diff --git a/server/routers/contentstack/loyaltyPage/output.ts b/server/routers/contentstack/loyaltyPage/output.ts index 251230d97..17f422477 100644 --- a/server/routers/contentstack/loyaltyPage/output.ts +++ b/server/routers/contentstack/loyaltyPage/output.ts @@ -15,18 +15,19 @@ import { RTEDocument } from "@/types/rte/node" const loyaltyPageBlockCardGrid = z.object({ __typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid), card_grid: z.object({ - title: z.string().optional(), - subtitle: z.string().optional(), + title: z.string().nullable(), + subtitle: z.string().nullable(), cards: z.array( z.object({ - title: z.string().optional(), - subtitle: z.string().optional(), + title: z.string().nullable(), + subtitle: z.string().nullable(), referenceConnection: z.object({ edges: z.array( z.object({ node: z.object({ system: z.object({ uid: z.string(), + locale: z.nativeEnum(Lang), }), url: z.string(), title: z.string(), @@ -37,7 +38,7 @@ const loyaltyPageBlockCardGrid = z.object({ totalCount: z.number(), }), open_in_new_tab: z.boolean(), - cta_text: z.string().optional(), + cta_text: z.string().nullable(), }) ), }), @@ -47,11 +48,11 @@ const loyaltyPageDynamicContent = z.object({ LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent ), dynamic_content: z.object({ - title: z.string().optional(), - subtitle: z.string().optional(), + title: z.string().nullable(), + subtitle: z.string().nullable(), component: z.nativeEnum(LoyaltyComponentEnum), link: z.object({ - text: z.string().optional(), + text: z.string().nullable(), pageConnection: z.object({ edges: z.array( z.object({ @@ -74,8 +75,8 @@ const loyaltyPageDynamicContent = z.object({ const loyaltyPageShortcuts = z.object({ __typename: z.literal(LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksShortcuts), shortcuts: z.object({ - title: z.string().optional(), - preamble: z.string().optional(), + title: z.string().nullable(), + preamble: z.string().nullable(), shortcuts: z.array( z.object({ linkConnection: z.object({ @@ -89,16 +90,16 @@ const loyaltyPageShortcuts = z.object({ url: z.string(), web: z .object({ - original_url: z.string().optional(), + original_url: z.string().nullable(), }) - .optional(), + .nullable(), title: z.string(), }), }) ), totalCount: z.number(), }), - text: z.string().optional(), + text: z.string().nullable(), open_in_new_tab: z.boolean(), }) ), @@ -143,15 +144,15 @@ const loyaltyPageJoinLoyaltyContact = z.object({ SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact ), join_loyalty_contact: z.object({ - title: z.string().optional(), - preamble: z.string().optional(), + title: z.string().nullable(), + preamble: z.string().nullable(), contact: z.array( z.object({ __typename: z.literal( JoinLoyaltyContactTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact ), contact: z.object({ - display_text: z.string().optional(), + display_text: z.string().nullable(), contact_field: z.string(), }), @@ -170,8 +171,10 @@ export const validateLoyaltyPageSchema = z.object({ items: z.array( z.object({ title: z.string(), + heading: z.string().nullable(), blocks: z.array(loyaltyPageBlockItem).nullable(), sidebar: z.array(loyaltyPageSidebarItem).nullable(), + system: z.object({ uid: z.string() }), }) ), }), diff --git a/server/routers/contentstack/loyaltyPage/query.ts b/server/routers/contentstack/loyaltyPage/query.ts index cf437d57d..70c14ba2f 100644 --- a/server/routers/contentstack/loyaltyPage/query.ts +++ b/server/routers/contentstack/loyaltyPage/query.ts @@ -80,8 +80,7 @@ export const loyaltyPageQueryRouter = router({ ...card, link: card.referenceConnection.totalCount ? { - href: card.referenceConnection.edges[0].node - .url, + href: `/${card.referenceConnection.edges[0].node.system.locale}${card.referenceConnection.edges[0].node.url}`, title: card.cta_text || _("Read more"), } : undefined, @@ -97,8 +96,7 @@ export const loyaltyPageQueryRouter = router({ link: block.dynamic_content.link.pageConnection.totalCount ? { text: block.dynamic_content.link.text, - href: block.dynamic_content.link.pageConnection - .edges[0].node.url, + href: `/${block.dynamic_content.link.pageConnection.edges[0].node.system.locale}${block.dynamic_content.link.pageConnection.edges[0].node.url}`, title: block.dynamic_content.link.pageConnection.edges[0] .node.title, diff --git a/types/components/myPages/myPage/shortcuts.ts b/types/components/myPages/myPage/shortcuts.ts index 3f98546a0..323b6fd8b 100644 --- a/types/components/myPages/myPage/shortcuts.ts +++ b/types/components/myPages/myPage/shortcuts.ts @@ -8,6 +8,6 @@ export type ShortcutsProps = { text?: string }[] title: string | ReactNode - subtitle?: string + subtitle?: string | null openInNewTab?: boolean }