feat(SW-285): Ship support for ContentPageBlocksContent
This commit is contained in:
@@ -4,6 +4,43 @@ import { Lang } from "@/constants/languages"
|
||||
|
||||
import { imageVaultAssetSchema } from "../schemas/imageVault"
|
||||
|
||||
import { ContentBlocksTypenameEnum } from "@/types/components/content/enums"
|
||||
import { ImageVaultAsset } from "@/types/components/imageVault"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import { EdgesWithTotalCount } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
// Block Schema and types
|
||||
const contentPageBlockTextContent = z.object({
|
||||
__typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksContent),
|
||||
content: z.object({
|
||||
content: z.object({
|
||||
embedded_itemsConnection: z.object({
|
||||
edges: z.array(z.any()),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
json: z.any(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
const contentPageBlockItem = z.discriminatedUnion("__typename", [
|
||||
contentPageBlockTextContent,
|
||||
])
|
||||
|
||||
type BlockContentRaw = z.infer<typeof contentPageBlockTextContent>
|
||||
export interface RteBlockContent extends BlockContentRaw {
|
||||
content: {
|
||||
content: {
|
||||
json: RTEDocument
|
||||
embedded_itemsConnection: EdgesWithTotalCount<Embeds>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Block = RteBlockContent
|
||||
|
||||
// Content Page Schema and types
|
||||
export const validateContentPageSchema = z.object({
|
||||
content_page: z.object({
|
||||
title: z.string(),
|
||||
@@ -12,6 +49,7 @@ export const validateContentPageSchema = z.object({
|
||||
preamble: z.string(),
|
||||
}),
|
||||
hero_image: imageVaultAssetSchema.nullable().optional(),
|
||||
blocks: z.array(contentPageBlockItem).nullable(),
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.nativeEnum(Lang),
|
||||
@@ -20,3 +58,11 @@ export const validateContentPageSchema = z.object({
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export type ContentPageDataRaw = z.infer<typeof validateContentPageSchema>
|
||||
type ContentPageRaw = ContentPageDataRaw["content_page"]
|
||||
|
||||
export type ContentPage = Omit<ContentPageRaw, "blocks" | "hero_image"> & {
|
||||
heroImage?: ImageVaultAsset
|
||||
blocks: Block[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user