110 lines
2.9 KiB
TypeScript
110 lines
2.9 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
|
|
|
|
import { AccountPageEnum } from "../../../types/accountPageEnum"
|
|
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
|
import {
|
|
accordionRefsSchema,
|
|
accordionSchema,
|
|
} from "../schemas/blocks/accordion"
|
|
import {
|
|
dynamicContentRefsSchema,
|
|
dynamicContentSchema,
|
|
} from "../schemas/blocks/dynamicContent"
|
|
import {
|
|
shortcutsRefsSchema,
|
|
shortcutsSchema,
|
|
} from "../schemas/blocks/shortcuts"
|
|
import { textContentSchema } from "../schemas/blocks/textContent"
|
|
import { systemSchema } from "../schemas/system"
|
|
|
|
const accountPageAccordions = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.Accordion),
|
|
})
|
|
.merge(accordionSchema)
|
|
|
|
const accountPageDynamicContent = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.DynamicContent),
|
|
})
|
|
.merge(dynamicContentSchema)
|
|
|
|
const accountPageShortcuts = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.ShortCuts),
|
|
})
|
|
.merge(shortcutsSchema)
|
|
|
|
const accountPageTextContent = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.TextContent),
|
|
})
|
|
.merge(textContentSchema)
|
|
|
|
export const blocksSchema = z.discriminatedUnion("__typename", [
|
|
accountPageAccordions,
|
|
accountPageDynamicContent,
|
|
accountPageShortcuts,
|
|
accountPageTextContent,
|
|
])
|
|
|
|
export const accountPageSchema = z.object({
|
|
account_page: z.object({
|
|
content: discriminatedUnionArray(blocksSchema.options),
|
|
heading: z.string().nullable(),
|
|
preamble: z.string().nullable(),
|
|
hero_image: transformedImageVaultAssetSchema,
|
|
hero_image_active: z
|
|
.boolean()
|
|
.nullable()
|
|
.transform((val) => val ?? false),
|
|
title: z.string(),
|
|
url: z.string(),
|
|
system: systemSchema.merge(
|
|
z.object({
|
|
created_at: z.string(),
|
|
updated_at: z.string(),
|
|
})
|
|
),
|
|
}),
|
|
trackingProps: z.object({
|
|
url: z.string(),
|
|
}),
|
|
})
|
|
|
|
const accountPageAccordionRefs = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.Accordion),
|
|
})
|
|
.merge(accordionRefsSchema)
|
|
|
|
const accountPageDynamicContentRefs = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.DynamicContent),
|
|
})
|
|
.merge(dynamicContentRefsSchema)
|
|
|
|
const accountPageShortcutsRefs = z
|
|
.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.ShortCuts),
|
|
})
|
|
.merge(shortcutsRefsSchema)
|
|
|
|
const accountPageContentItemRefs = z.discriminatedUnion("__typename", [
|
|
z.object({
|
|
__typename: z.literal(AccountPageEnum.ContentStack.blocks.TextContent),
|
|
}),
|
|
accountPageAccordionRefs,
|
|
accountPageDynamicContentRefs,
|
|
accountPageShortcutsRefs,
|
|
])
|
|
|
|
export const accountPageRefsSchema = z.object({
|
|
account_page: z.object({
|
|
content: discriminatedUnionArray(accountPageContentItemRefs.options),
|
|
system: systemSchema,
|
|
}),
|
|
})
|