feat(SW-187): Footer data from contentstack

This commit is contained in:
Pontus Dreij
2024-08-28 08:30:45 +02:00
parent 2fcbaa62e4
commit da51bd88fe
14 changed files with 370 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
import { z } from "zod"
import { Image } from "@/types/image"
import { PageLinkEnum } from "@/types/requests/pageLinks"
// Help me write this zod schema based on the type ContactConfig
export const validateContactConfigSchema = z.object({
@@ -165,7 +166,7 @@ const validateNavigationItem = z.object({
export type NavigationItem = z.infer<typeof validateNavigationItem>
export const validateFooterConfigSchema = z.object({
export const validateCurrentFooterConfigSchema = z.object({
all_current_footer: z.object({
items: z.array(
z.object({
@@ -232,16 +233,18 @@ export const validateFooterConfigSchema = z.object({
}),
})
export type FooterDataRaw = z.infer<typeof validateFooterConfigSchema>
export type CurrentFooterDataRaw = z.infer<
typeof validateCurrentFooterConfigSchema
>
export type FooterData = Omit<
FooterDataRaw["all_current_footer"]["items"][0],
export type CurrentFooterData = Omit<
CurrentFooterDataRaw["all_current_footer"]["items"][0],
"logoConnection"
> & {
logo: Image
}
const validateFooterRefConfigSchema = z.object({
const validateCurrentFooterRefConfigSchema = z.object({
all_current_footer: z.object({
items: z.array(
z.object({
@@ -254,4 +257,106 @@ const validateFooterRefConfigSchema = z.object({
}),
})
export type CurrentFooterRefDataRaw = z.infer<
typeof validateCurrentFooterRefConfigSchema
>
const validateExternalLink = z
.object({
href: z.string(),
title: z.string(),
})
.optional()
const validateInternalLink = z
.object({
edges: z.array(
z.object({
node: z.object({
title: z.string(),
url: z.string(),
}),
})
),
})
.optional()
const validateLinkItem = z.object({
title: z.string(),
open_in_new_tab: z.boolean(),
link: validateExternalLink,
pageConnection: validateInternalLink,
})
export type FooterLinkItem = z.infer<typeof validateLinkItem>
export const validateFooterConfigSchema = z.object({
all_footer: z.object({
items: z.array(
z.object({
main_links: z.array(validateLinkItem),
app_downloads: z.object({
title: z.string(),
links: z.array(
z.object({
type: z.string(),
href: validateExternalLink,
})
),
}),
secondary_links: z.array(
z.object({
title: z.string(),
links: z.array(validateLinkItem),
})
),
})
),
}),
})
export type FooterDataRaw = z.infer<typeof validateFooterConfigSchema>
export type FooterData = FooterDataRaw["all_footer"]["items"][0]
const pageConnectionRefs = z.object({
edges: z.array(
z.object({
node: z.object({
__typename: z.nativeEnum(PageLinkEnum),
system: z.object({
content_type_uid: z.string(),
uid: z.string(),
}),
}),
})
),
})
const validateFooterRefConfigSchema = z.object({
all_footer: z.object({
items: z.array(
z.object({
main_links: z.array(
z.object({
pageConnection: pageConnectionRefs,
})
),
secondary_links: z.array(
z.object({
links: z.array(
z.object({
pageConnection: pageConnectionRefs,
})
),
})
),
system: z.object({
content_type_uid: z.string(),
uid: z.string(),
}),
})
),
}),
})
export type FooterRefDataRaw = z.infer<typeof validateFooterRefConfigSchema>