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