feat(SW-66, SW-348): search functionality and ui
This commit is contained in:
@@ -1,197 +1,87 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||
|
||||
import {
|
||||
ContentEntries,
|
||||
DynamicContentComponents,
|
||||
} from "@/types/components/myPages/myPage/enums"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import { PageLinkEnum } from "@/types/requests/pageLinks"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
dynamicContentRefsSchema,
|
||||
dynamicContentSchema,
|
||||
} from "../schemas/blocks/dynamicContent"
|
||||
import {
|
||||
shortcutsRefsSchema,
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { textContentSchema } from "../schemas/blocks/textContent"
|
||||
import { page } from "../schemas/metadata"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
const accountPageShortcuts = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
||||
shortcuts: z.object({
|
||||
title: z.string().nullable(),
|
||||
preamble: z.string().nullable(),
|
||||
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().nullable().optional(),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
text: z.string().nullable(),
|
||||
open_in_new_tab: z.boolean(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
import { AccountPageEnum } from "@/types/enums/accountPage"
|
||||
|
||||
const accountPageDynamicContent = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentDynamicContent),
|
||||
dynamic_content: z.object({
|
||||
title: z.string().nullable(),
|
||||
preamble: z.string().nullable(),
|
||||
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().nullable().optional(),
|
||||
title: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
totalCount: z.number(),
|
||||
}),
|
||||
link_text: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
const accountPageDynamicContent = z
|
||||
.object({
|
||||
__typename: z.literal(AccountPageEnum.ContentStack.blocks.DynamicContent),
|
||||
})
|
||||
.merge(dynamicContentSchema)
|
||||
|
||||
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(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
const accountPageShortcuts = z
|
||||
.object({
|
||||
__typename: z.literal(AccountPageEnum.ContentStack.blocks.ShortCuts),
|
||||
})
|
||||
.merge(shortcutsSchema)
|
||||
|
||||
type TextContentRaw = z.infer<typeof accountPageTextContent>
|
||||
const accountPageTextContent = z
|
||||
.object({
|
||||
__typename: z.literal(AccountPageEnum.ContentStack.blocks.TextContent),
|
||||
})
|
||||
.merge(textContentSchema)
|
||||
|
||||
type DynamicContentRaw = z.infer<typeof accountPageDynamicContent>
|
||||
|
||||
type ShortcutsRaw = z.infer<typeof accountPageShortcuts>
|
||||
|
||||
export type Shortcuts = Omit<ShortcutsRaw, "shortcuts"> & {
|
||||
shortcuts: Omit<ShortcutsRaw["shortcuts"], "shortcuts"> & {
|
||||
shortcuts: {
|
||||
text?: string
|
||||
openInNewTab: boolean
|
||||
url: string
|
||||
title: string
|
||||
}[]
|
||||
}
|
||||
}
|
||||
|
||||
export type RteTextContent = Omit<TextContentRaw, "text_content"> & {
|
||||
text_content: {
|
||||
content: {
|
||||
json: RTEDocument
|
||||
embedded_itemsConnection: Edges<Embeds>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type AccountPageContentItem =
|
||||
| DynamicContentRaw
|
||||
| Shortcuts
|
||||
| RteTextContent
|
||||
|
||||
const accountPageContentItem = z.discriminatedUnion("__typename", [
|
||||
accountPageShortcuts,
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
accountPageDynamicContent,
|
||||
accountPageShortcuts,
|
||||
accountPageTextContent,
|
||||
])
|
||||
|
||||
export const validateAccountPageSchema = z.object({
|
||||
export const accountPageSchema = z.object({
|
||||
account_page: z.object({
|
||||
content: discriminatedUnionArray(blocksSchema.options),
|
||||
heading: z.string().nullable(),
|
||||
url: z.string(),
|
||||
title: z.string(),
|
||||
content: z.array(accountPageContentItem),
|
||||
system: z.object({
|
||||
uid: z.string(),
|
||||
locale: z.nativeEnum(Lang),
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export type AccountPageDataRaw = z.infer<typeof validateAccountPageSchema>
|
||||
|
||||
type AccountPageRaw = AccountPageDataRaw["account_page"]
|
||||
|
||||
export type AccountPage = Omit<AccountPageRaw, "content"> & {
|
||||
content: AccountPageContentItem[]
|
||||
}
|
||||
|
||||
// Refs types
|
||||
const pageConnectionRefs = z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
__typename: z.nativeEnum(PageLinkEnum),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
const accountPageShortcutsRefs = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentShortcuts),
|
||||
shortcuts: z.object({
|
||||
shortcuts: z.array(
|
||||
url: z.string(),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
linkConnection: pageConnectionRefs,
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
|
||||
const accountPageDynamicContentRefs = z.object({
|
||||
__typename: z.literal(ContentEntries.AccountPageContentDynamicContent),
|
||||
dynamic_content: z.object({
|
||||
link: z.object({
|
||||
linkConnection: pageConnectionRefs,
|
||||
}),
|
||||
}),
|
||||
})
|
||||
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),
|
||||
}),
|
||||
accountPageDynamicContentRefs,
|
||||
accountPageShortcutsRefs,
|
||||
])
|
||||
|
||||
export const validateAccountPageRefsSchema = z.object({
|
||||
export const accountPageRefsSchema = z.object({
|
||||
account_page: z.object({
|
||||
content: z.array(accountPageContentItemRefs),
|
||||
system: z.object({
|
||||
content_type_uid: z.string(),
|
||||
uid: z.string(),
|
||||
}),
|
||||
content: discriminatedUnionArray(accountPageContentItemRefs.options),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
|
||||
export type AccountPageRefsDataRaw = z.infer<
|
||||
typeof validateAccountPageRefsSchema
|
||||
>
|
||||
export const accountPageMetadataSchema = z.object({
|
||||
account_page: page,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user