fix: align typings with loyalty-page branch

This commit is contained in:
Arvid Norlin
2024-04-29 16:40:26 +02:00
parent 4d4d67ab38
commit f01bd44c44
7 changed files with 142 additions and 27 deletions

View File

@@ -1,9 +1,14 @@
import { z } from "zod"
import { Lang } from "@/constants/languages"
import { Embeds } from "@/types/requests/embeds"
import {
ContentEntries,
DynamicContentComponents,
} from "@/types/requests/myPages/accountpage"
import { Edges } from "@/types/requests/utils/edges"
import { RTEDocument } from "@/types/rte/node"
const accountPageShortcuts = z.object({
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
@@ -20,13 +25,14 @@ const accountPageShortcuts = z.object({
node: z.object({
system: z.object({
uid: z.string(),
locale: z.string(),
locale: z.nativeEnum(Lang),
}),
url: z.string(),
title: z.string(),
}),
})
),
totalCount: z.number(),
}),
text: z.string().optional(),
open_in_new_tab: z.boolean(),
@@ -41,24 +47,25 @@ const accountPageDynamicContent = 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.string(),
}),
url: z.string(),
title: z.string(),
link: z.object({
linkConnection: z.object({
edges: z.array(
z.object({
node: z.object({
system: z.object({
uid: z.string(),
locale: z.nativeEnum(Lang),
}),
})
),
}),
})
.optional(),
url: z.string(),
title: z.string(),
}),
})
),
totalCount: z.number(),
}),
link_text: z.string(),
}),
// .optional(),
}),
})
@@ -75,11 +82,32 @@ const accountPageTextContent = z.object({
__typename: z.literal(ContentEntries.AccountPageContentTextContent),
text_content: z.object({
content: z.object({
json: jsonSchema,
json: z.any(),
embedded_itemsConnection: z.object({
edges: z.array(z.any()),
totalCount: z.number(),
}),
}),
}),
})
type TextContentRaw = z.infer<typeof accountPageTextContent>
type DynamicContentRaw = z.infer<typeof accountPageDynamicContent>
type ShortcutsRaw = z.infer<typeof accountPageShortcuts>
export type RteTextContent = Omit<TextContentRaw, "text_content"> & {
text_content: {
content: {
json: RTEDocument
embedded_itemsConnection: Edges<Embeds>
}
}
}
type AccountPageContentItem = DynamicContentRaw | ShortcutsRaw | RteTextContent
const accountPageContentItem = z.discriminatedUnion("__typename", [
accountPageShortcuts,
accountPageDynamicContent,
@@ -120,3 +148,13 @@ export const validateAccountPageBenefitsSchema = z.object({
),
}),
})
type AccountPageDataRaw = z.infer<typeof validateAccountPageOverviewSchema>
type AccountPageRaw = AccountPageDataRaw["all_account_page"]["items"][0]
export type AccountPage = Omit<AccountPageRaw, "content"> & {
url: string
title: string
content: AccountPageContentItem[]
}