feat(SW-368): added link chips component

This commit is contained in:
Erik Tiekstra
2024-09-19 15:16:58 +02:00
parent 6720370c41
commit 4352997322
18 changed files with 290 additions and 41 deletions

View File

@@ -11,8 +11,8 @@ import {
contentSchema as blockContentSchema,
} from "../schemas/blocks/content"
import {
dynamicContentRefsSchema,
dynamicContentSchema as blockDynamicContentSchema,
dynamicContentRefsSchema,
} from "../schemas/blocks/dynamicContent"
import {
shortcutsRefsSchema,
@@ -32,7 +32,18 @@ import {
} from "../schemas/sidebar/joinLoyaltyContact"
import { systemSchema } from "../schemas/system"
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
import { ContentPageEnum } from "@/types/enums/contentPage"
import {
linkAndTitleSchema,
linkConnectionRefs,
} from "../schemas/linkConnection"
const linkUnionSchema = z.discriminatedUnion("__typename", [
pageLinks.contentPageSchema,
pageLinks.hotelPageSchema,
pageLinks.loyaltyPageSchema,
])
// Block schemas
export const contentPageCards = z
@@ -106,6 +117,19 @@ export const sidebarSchema = z.discriminatedUnion("__typename", [
contentPageJoinLoyaltyContact,
])
const navigationLinksSchema = z
.array(linkAndTitleSchema)
.nullable()
.transform((data) => {
if (!data) {
return null
}
return data
.filter((item) => !!item.link)
.map((item) => ({ url: item.link.url, title: item.title }))
})
// Content Page Schema and types
export const contentPageSchema = z.object({
content_page: z.object({
@@ -116,6 +140,7 @@ export const contentPageSchema = z.object({
header: z.object({
heading: z.string(),
preamble: z.string(),
navigation_links: navigationLinksSchema,
}),
system: systemSchema.merge(
z.object({
@@ -191,8 +216,13 @@ const contentPageSidebarRefsItem = z.discriminatedUnion("__typename", [
contentPageSidebarJoinLoyaltyContactRef,
])
const contentPageHeaderRefs = z.object({
navigation_links: z.array(linkConnectionRefs),
})
export const contentPageRefsSchema = z.object({
content_page: z.object({
header: contentPageHeaderRefs,
blocks: discriminatedUnionArray(
contentPageBlockRefsItem.options
).nullable(),