fix: make web and breadcrumbs optional
This commit is contained in:
@@ -13,22 +13,25 @@ export const getBreadcrumbsSchema = z.array(
|
||||
const breadcrumbsRefsItems = z.object({
|
||||
items: z.array(
|
||||
z.object({
|
||||
web: z.object({
|
||||
breadcrumbs: z.object({
|
||||
parentsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
web: z
|
||||
.object({
|
||||
breadcrumbs: z.object({
|
||||
title: z.string(),
|
||||
parentsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
@@ -48,29 +51,33 @@ export const validateLoyaltyPageBreadcrumbsRefsContentstackSchema = z.object({
|
||||
})
|
||||
|
||||
const page = z.object({
|
||||
web: z.object({
|
||||
breadcrumbs: z.object({
|
||||
title: z.string(),
|
||||
parentsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
web: z.object({
|
||||
breadcrumbs: z.object({
|
||||
title: z.string(),
|
||||
web: z
|
||||
.object({
|
||||
breadcrumbs: z
|
||||
.object({
|
||||
title: z.string(),
|
||||
parentsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
web: z.object({
|
||||
breadcrumbs: z.object({
|
||||
title: z.string(),
|
||||
}),
|
||||
}),
|
||||
system: z.object({
|
||||
locale: z.nativeEnum(Lang),
|
||||
uid: z.string(),
|
||||
}),
|
||||
url: z.string(),
|
||||
}),
|
||||
}),
|
||||
system: z.object({
|
||||
locale: z.nativeEnum(Lang),
|
||||
uid: z.string(),
|
||||
}),
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
}),
|
||||
|
||||
@@ -37,6 +37,10 @@ async function getLoyaltyPageBreadcrumbs(variables: Variables) {
|
||||
variables
|
||||
)
|
||||
|
||||
if (!refsResponse.data.all_loyalty_page.items[0].web?.breadcrumbs?.title) {
|
||||
return []
|
||||
}
|
||||
|
||||
const validatedRefsData =
|
||||
validateLoyaltyPageBreadcrumbsRefsContentstackSchema.safeParse(
|
||||
refsResponse.data
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "@/utils/generateTag"
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
import { BreadcrumbsRefsItems, getBreadcrumbsSchema,Page } from "./output"
|
||||
import { BreadcrumbsRefsItems, getBreadcrumbsSchema, Page } from "./output"
|
||||
|
||||
import type { GetBreadcrumbsItems } from "@/types/requests/myPages/breadcrumbs"
|
||||
import type { Edges } from "@/types/requests/utils/edges"
|
||||
@@ -17,8 +17,11 @@ import type { NodeRefs } from "@/types/requests/utils/refs"
|
||||
|
||||
export function getConnections(refs: GetBreadcrumbsItems) {
|
||||
const connections: Edges<NodeRefs>[] = []
|
||||
|
||||
refs.items.forEach((ref) => {
|
||||
connections.push(ref.web.breadcrumbs.parentsConnection)
|
||||
if (ref.web?.breadcrumbs) {
|
||||
connections.push(ref.web.breadcrumbs.parentsConnection)
|
||||
}
|
||||
})
|
||||
return connections
|
||||
}
|
||||
@@ -98,7 +101,7 @@ export async function getResponse<T>(
|
||||
}
|
||||
|
||||
export function getBreadcrumbs(page: Page, lang: Lang) {
|
||||
const parentBreadcrumbs = page.web.breadcrumbs.parentsConnection.edges.map(
|
||||
const parentBreadcrumbs = page.web?.breadcrumbs?.parentsConnection.edges.map(
|
||||
(breadcrumb) => {
|
||||
return {
|
||||
href: removeMultipleSlashes(
|
||||
@@ -111,7 +114,7 @@ export function getBreadcrumbs(page: Page, lang: Lang) {
|
||||
)
|
||||
|
||||
const pageBreadcrumb = {
|
||||
title: page.web.breadcrumbs.title,
|
||||
title: page.web?.breadcrumbs?.title,
|
||||
uid: page.system.uid,
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import type { AllRequestResponse } from "../utils/all"
|
||||
import type { Edges } from "../utils/edges"
|
||||
|
||||
interface MyPagesBreadcrumbs {
|
||||
web: {
|
||||
breadcrumbs: {
|
||||
web?: {
|
||||
breadcrumbs?: {
|
||||
title: string
|
||||
parentsConnection: Edges<{
|
||||
web: {
|
||||
@@ -42,9 +42,10 @@ export interface GetBreadcrumbsItems {
|
||||
}
|
||||
|
||||
interface MyPagesBreadcrumbRefs extends System {
|
||||
web: {
|
||||
breadcrumbs: {
|
||||
web?: {
|
||||
breadcrumbs?: {
|
||||
parentsConnection: Edges<System>
|
||||
title: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user