import { z } from "zod" import { Lang } from "@/constants/languages" import { ContentEntries, DynamicContentComponents, } from "@/types/components/myPages/myPage/enums" import { Embeds } from "@/types/requests/embeds" import { Edges } from "@/types/requests/utils/edges" import { RTEDocument } from "@/types/rte/node" const accountPageShortcuts = z.object({ __typename: z.literal(ContentEntries.AccountPageContentShortcuts), shortcuts: z.object({ title: z.string().optional(), preamble: z.string().optional(), shortcuts: z.array( z.object({ linkConnection: z.object({ edges: z.array( z.object({ node: z.object({ system: z.object({ uid: z.string(), locale: z.nativeEnum(Lang), }), original_url: z.string().optional(), url: z.string(), title: z.string(), }), }) ), totalCount: z.number(), }), text: z.string().optional(), open_in_new_tab: z.boolean(), }) ), }), }) const accountPageDynamicContent = z.object({ __typename: z.literal(ContentEntries.AccountPageContentDynamicContent), dynamic_content: z.object({ title: z.string().optional(), preamble: z.string().optional(), component: z.nativeEnum(DynamicContentComponents), link: z.object({ linkConnection: z.object({ edges: z.array( z.object({ node: z.object({ system: z.object({ uid: z.string(), locale: z.nativeEnum(Lang), }), url: z.string(), original_url: z.string().optional(), title: z.string(), }), }) ), totalCount: z.number(), }), link_text: z.string(), }), // .optional(), }), }) const accountPageTextContent = z.object({ __typename: z.literal(ContentEntries.AccountPageContentTextContent), text_content: z.object({ content: z.object({ json: z.any(), embedded_itemsConnection: z.object({ edges: z.array(z.any()), totalCount: z.number(), }), }), }), }) type TextContentRaw = z.infer type DynamicContentRaw = z.infer type ShortcutsRaw = z.infer export type Shortcuts = Omit & { shortcuts: Omit & { shortcuts: { text?: string openInNewTab: boolean url: string title: string }[] } } export type RteTextContent = Omit & { text_content: { content: { json: RTEDocument embedded_itemsConnection: Edges } } } export type AccountPageContentItem = | DynamicContentRaw | Shortcuts | RteTextContent const accountPageContentItem = z.discriminatedUnion("__typename", [ accountPageShortcuts, accountPageDynamicContent, accountPageTextContent, ]) export const validateAccountPageSchema = z.object({ all_account_page: z.object({ items: z.array( z.object({ url: z.string(), title: z.string(), content: z.array(accountPageContentItem), }) ), }), }) type AccountPageDataRaw = z.infer type AccountPageRaw = AccountPageDataRaw["all_account_page"]["items"][0] export type AccountPage = Omit & { url: string title: string content: AccountPageContentItem[] }