Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)
feat(SW-2863): Move contentstack router to trpc package * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package Approved-by: Linus Flood
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { BlocksEnums } from "../../../../types/blocks"
|
||||
import {
|
||||
contentCardRefSchema,
|
||||
contentCardSchema,
|
||||
transformContentCard,
|
||||
} from "./cards/contentCard"
|
||||
import { buttonSchema } from "./utils/buttonLinkSchema"
|
||||
import { linkConnectionRefsSchema } from "./utils/linkConnection"
|
||||
|
||||
export const cardGallerySchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.CardGallery)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.CardGallery),
|
||||
card_gallery: z
|
||||
.object({
|
||||
heading: z.string().optional(),
|
||||
link: buttonSchema.optional(),
|
||||
card_groups: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
filter_identifier: z.string().nullish(),
|
||||
filter_label: z.string().nullish(),
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(z.object({ node: contentCardSchema })),
|
||||
}),
|
||||
})
|
||||
.transform((group) => {
|
||||
if (!group.filter_label || !group.cardsConnection.edges.length) {
|
||||
return null
|
||||
}
|
||||
|
||||
const iconIdentifier = group.filter_identifier ?? "favorite"
|
||||
const identifier = `${group.filter_label.toLowerCase()}-${iconIdentifier}`
|
||||
const cards = group.cardsConnection.edges
|
||||
.map((edge) => transformContentCard(edge.node))
|
||||
.filter(
|
||||
(card): card is NonNullable<typeof card> => card !== null
|
||||
)
|
||||
.map((card) => ({
|
||||
...card,
|
||||
filterId: identifier,
|
||||
}))
|
||||
return {
|
||||
label: group.filter_label,
|
||||
iconIdentifier,
|
||||
identifier,
|
||||
cards,
|
||||
}
|
||||
})
|
||||
)
|
||||
.transform((groups) =>
|
||||
groups.filter(
|
||||
(group): group is NonNullable<typeof group> => group !== null
|
||||
)
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
const filterCategories = data.card_groups.map((group) => ({
|
||||
identifier: group.identifier,
|
||||
iconIdentifier: group.iconIdentifier,
|
||||
label: group.label,
|
||||
}))
|
||||
|
||||
return {
|
||||
heading: data.heading,
|
||||
filterCategories,
|
||||
cards: data.card_groups.map((group) => group.cards).flat(),
|
||||
defaultFilter: filterCategories[0]?.identifier,
|
||||
link:
|
||||
data.link?.href && data.link.title
|
||||
? { href: data.link.href, text: data.link.title }
|
||||
: undefined,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const cardGalleryRefsSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.CardGallery)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.CardGallery),
|
||||
card_gallery: z.object({
|
||||
card_groups: z.array(
|
||||
z.object({
|
||||
cardsConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: contentCardRefSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
),
|
||||
link: linkConnectionRefsSchema.optional(),
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user