fix: make sidebar and blocks nullable
This commit is contained in:
@@ -29,7 +29,7 @@ export default async function LoyaltyPage({
|
||||
{loyaltyPage.sidebar ? <Sidebar blocks={loyaltyPage.sidebar} /> : null}
|
||||
|
||||
<MaxWidth className={styles.blocks} tag="main">
|
||||
<Blocks blocks={loyaltyPage.blocks} />
|
||||
{loyaltyPage.blocks ? <Blocks blocks={loyaltyPage.blocks} /> : null}
|
||||
</MaxWidth>
|
||||
</section>
|
||||
)
|
||||
|
||||
@@ -6,5 +6,5 @@ const langs = Object.keys(Lang) as [keyof typeof Lang]
|
||||
|
||||
export const getLoyaltyPageInput = z.object({
|
||||
href: z.string().min(1, { message: "href is required" }),
|
||||
locale: z.enum(langs),
|
||||
locale: z.nativeEnum(Lang),
|
||||
})
|
||||
|
||||
@@ -170,8 +170,8 @@ export const validateLoyaltyPageSchema = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
title: z.string(),
|
||||
blocks: z.array(loyaltyPageBlockItem),
|
||||
sidebar: z.array(loyaltyPageSidebarItem),
|
||||
blocks: z.array(loyaltyPageBlockItem).nullable(),
|
||||
sidebar: z.array(loyaltyPageSidebarItem).nullable(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -41,11 +41,13 @@ export const loyaltyPageQueryRouter = router({
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
const sidebar =
|
||||
validatedLoyaltyPage.data.all_loyalty_page.items[0].sidebar.map(
|
||||
const sidebar = validatedLoyaltyPage.data.all_loyalty_page.items[0]
|
||||
.sidebar
|
||||
? validatedLoyaltyPage.data.all_loyalty_page.items[0].sidebar.map(
|
||||
(block) => {
|
||||
if (
|
||||
block.__typename == SidebarTypenameEnum.LoyaltyPageSidebarContent
|
||||
block.__typename ==
|
||||
SidebarTypenameEnum.LoyaltyPageSidebarContent
|
||||
) {
|
||||
return {
|
||||
...block,
|
||||
@@ -62,9 +64,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
}
|
||||
}
|
||||
)
|
||||
: null
|
||||
|
||||
const blocks =
|
||||
validatedLoyaltyPage.data.all_loyalty_page.items[0].blocks.map(
|
||||
const blocks = validatedLoyaltyPage.data.all_loyalty_page.items[0].blocks
|
||||
? validatedLoyaltyPage.data.all_loyalty_page.items[0].blocks.map(
|
||||
(block) => {
|
||||
switch (block.__typename) {
|
||||
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid:
|
||||
@@ -77,7 +80,8 @@ export const loyaltyPageQueryRouter = router({
|
||||
...card,
|
||||
link: card.referenceConnection.totalCount
|
||||
? {
|
||||
href: card.referenceConnection.edges[0].node.url,
|
||||
href: card.referenceConnection.edges[0].node
|
||||
.url,
|
||||
title: card.cta_text || _("Read more"),
|
||||
}
|
||||
: undefined,
|
||||
@@ -134,6 +138,7 @@ export const loyaltyPageQueryRouter = router({
|
||||
}
|
||||
}
|
||||
)
|
||||
: null
|
||||
|
||||
const loyaltyPage = {
|
||||
...validatedLoyaltyPage.data.all_loyalty_page.items[0],
|
||||
|
||||
Reference in New Issue
Block a user