feat(SW-186): implemented queries and typings for top_link inside header query

This commit is contained in:
Erik Tiekstra
2024-08-26 15:31:40 +02:00
parent 1aff87f1a1
commit 99c0d7976f
4 changed files with 278 additions and 1 deletions
@@ -1,5 +1,7 @@
import { z } from "zod"
import { Lang } from "@/constants/languages"
import { Image } from "@/types/image"
// Help me write this zod schema based on the type ContactConfig
@@ -259,3 +261,79 @@ const validateFooterRefConfigSchema = z.object({
})
export type FooterRefDataRaw = z.infer<typeof validateFooterRefConfigSchema>
const linkConnectionNodeSchema = 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(),
web: z.object({
original_url: z.string().nullable().optional(),
}),
}),
})
),
})
const internalExternalLinkSchema = z.object({
external_link: z.object({
href: z.string(),
title: z.string(),
}),
is_external_link: z.boolean(),
open_in_new_tab: z.boolean(),
page_link: z.object({
link_title: z.string(),
linkConnection: linkConnectionNodeSchema,
}),
})
export type InternalExternalLinkData = z.infer<
typeof internalExternalLinkSchema
>
export const validateHeaderSchema = z.object({
all_header: z.object({
items: z.array(
z.object({
top_link: internalExternalLinkSchema.optional(),
})
),
}),
})
export type HeaderDataRaw = z.infer<typeof validateHeaderSchema>
export type InternalExternalLink = {
href: string
title: string
isExternal: boolean
openInNewTab: boolean
}
export type HeaderData = Omit<
HeaderDataRaw["all_header"]["items"][0],
"top_link"
> & {
topLink: InternalExternalLink | null
}
const validateHeaderRefSchema = z.object({
all_header: z.object({
items: z.array(
z.object({
system: z.object({
content_type_uid: z.string(),
uid: z.string(),
}),
})
),
}),
})
export type HeaderRefDataRaw = z.infer<typeof validateHeaderRefSchema>