refactor: make my-pages page more reusable

This commit is contained in:
Arvid Norlin
2024-04-30 14:48:20 +02:00
parent a1e474073e
commit a81f641ccd
9 changed files with 44 additions and 137 deletions

View File

@@ -69,15 +69,6 @@ const accountPageDynamicContent = z.object({
}),
})
// To validate the JSON content
// https://zod.dev/?id=json-type
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()])
type Literal = z.infer<typeof literalSchema>
type Json = Literal | { [key: string]: Json } | Json[]
const jsonSchema: z.ZodType<Json> = z.lazy(() =>
z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])
)
const accountPageTextContent = z.object({
__typename: z.literal(ContentEntries.AccountPageContentTextContent),
text_content: z.object({
@@ -126,30 +117,7 @@ export const validateAccountPageSchema = z.object({
}),
})
export const validateAccountPageOverviewSchema = z.object({
all_account_page: z.object({
items: z.array(
z.object({
url: z.string(),
title: z.string(),
content: z.array(accountPageContentItem),
})
),
}),
})
export const validateAccountPageBenefitsSchema = z.object({
all_account_page: z.object({
items: z.array(
z.object({
url: z.string(),
title: z.string(),
content: z.array(z.object({})),
})
),
}),
})
type AccountPageDataRaw = z.infer<typeof validateAccountPageOverviewSchema>
type AccountPageDataRaw = z.infer<typeof validateAccountPageSchema>
type AccountPageRaw = AccountPageDataRaw["all_account_page"]["items"][0]