chore(SW-285): content page types dir

This commit is contained in:
Chuma McPhoy
2024-09-05 15:50:40 +02:00
parent b0e84dd016
commit 0f80d82eac
7 changed files with 96 additions and 92 deletions

View File

@@ -19,8 +19,8 @@ import { RTEEmbedsEnum } from "@/types/requests/rte"
import { EdgesWithTotalCount } from "@/types/requests/utils/edges"
import { RTEDocument } from "@/types/rte/node"
// Block Schema and types
const contentPageBlockTextContent = z.object({
// Block schemas
export const contentPageBlockTextContent = z.object({
__typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksContent),
content: z.object({
content: z.object({
@@ -33,7 +33,7 @@ const contentPageBlockTextContent = z.object({
}),
})
const contentPageShortcuts = z.object({
export const contentPageShortcuts = z.object({
__typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksShortcuts),
shortcuts: z.object({
title: z.string().nullable(),
@@ -49,7 +49,7 @@ const contentPageShortcuts = z.object({
}),
})
const contentPageDynamicContent = z.object({
export const contentPageDynamicContent = z.object({
__typename: z.literal(
ContentBlocksTypenameEnum.ContentPageBlocksDynamicContent
),
@@ -66,7 +66,7 @@ const contentPageDynamicContent = z.object({
}),
})
const cardBlock = z.object({
export const cardBlock = z.object({
__typename: z.literal(CardsGridEnum.Card),
heading: z.string().nullable(),
body_text: z.string().nullable(),
@@ -94,7 +94,7 @@ const cardBlock = z.object({
}),
})
const loyaltyCardBlock = z.object({
export const loyaltyCardBlock = z.object({
__typename: z.literal(CardsGridEnum.LoyaltyCard),
heading: z.string().nullable(),
body_text: z.string().nullable(),
@@ -118,7 +118,7 @@ const contentPageCardsItems = z.discriminatedUnion("__typename", [
cardBlock,
])
const contentPageCards = z.object({
export const contentPageCards = z.object({
__typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksCardsGrid),
cards_grid: z.object({
title: z.string().nullable(),
@@ -136,7 +136,7 @@ const contentPageBlockItem = z.discriminatedUnion("__typename", [
contentPageShortcuts,
])
const contentPageSidebarTextContent = z.object({
export const contentPageSidebarTextContent = z.object({
__typename: z.literal(SidebarTypenameEnum.ContentPageSidebarContent),
content: z.object({
content: z.object({
@@ -149,7 +149,7 @@ const contentPageSidebarTextContent = z.object({
}),
})
const contentPageJoinLoyaltyContact = z.object({
export const contentPageJoinLoyaltyContact = z.object({
__typename: z.literal(
SidebarTypenameEnum.ContentPageSidebarJoinLoyaltyContact
),
@@ -179,7 +179,7 @@ const contentPageJoinLoyaltyContact = z.object({
}),
})
const contentPageSidebarDynamicContent = z.object({
export const contentPageSidebarDynamicContent = z.object({
__typename: z.literal(SidebarTypenameEnum.ContentPageSidebarDynamicContent),
dynamic_content: z.object({
component: z.nativeEnum(SidebarDynamicComponentEnum),
@@ -192,55 +192,6 @@ const contentPageSidebarItem = z.discriminatedUnion("__typename", [
contentPageJoinLoyaltyContact,
])
export type DynamicContent = z.infer<typeof contentPageDynamicContent>
type BlockContentRaw = z.infer<typeof contentPageBlockTextContent>
export interface RteBlockContent extends BlockContentRaw {
content: {
content: {
json: RTEDocument
embedded_itemsConnection: EdgesWithTotalCount<Embeds>
}
}
}
export type Shortcuts = z.infer<typeof contentPageShortcuts>
type LoyaltyCardRaw = z.infer<typeof loyaltyCardBlock>
type LoyaltyCard = Omit<LoyaltyCardRaw, "image"> & {
image?: ImageVaultAsset
}
type CardRaw = z.infer<typeof cardBlock>
type Card = Omit<CardRaw, "background_image"> & {
backgroundImage?: ImageVaultAsset
}
type CardsGridRaw = z.infer<typeof contentPageCards>
export type CardsGrid = Omit<CardsGridRaw, "cards"> & {
cards: (LoyaltyCard | Card)[]
}
export type CardsRaw = CardsGrid["cards_grid"]["cards"][number]
export type Block = RteBlockContent | Shortcuts | CardsGrid | DynamicContent
type SidebarContentRaw = z.infer<typeof contentPageSidebarTextContent>
export type RteSidebarContent = Omit<SidebarContentRaw, "content"> & {
content: {
content: {
json: RTEDocument
embedded_itemsConnection: EdgesWithTotalCount<Embeds>
}
}
}
type SideBarDynamicContent = z.infer<typeof contentPageSidebarDynamicContent>
export type JoinLoyaltyContact = z.infer<typeof contentPageJoinLoyaltyContact>
export type Sidebar =
| JoinLoyaltyContact
| RteSidebarContent
| SideBarDynamicContent
// Content Page Schema and types
export const validateContentPageSchema = z.object({
content_page: z.object({
@@ -261,18 +212,6 @@ export const validateContentPageSchema = z.object({
}),
})
export type ContentPageDataRaw = z.infer<typeof validateContentPageSchema>
type ContentPageRaw = ContentPageDataRaw["content_page"]
export type ContentPage = Omit<
ContentPageRaw,
"blocks" | "hero_image" | "sidebar"
> & {
heroImage?: ImageVaultAsset
blocks: Block[]
sidebar: Sidebar[]
}
const pageConnectionRefs = z.object({
edges: z.array(
z.object({
@@ -425,7 +364,3 @@ export const validateContentPageRefsSchema = z.object({
}),
}),
})
export type ContentPageRefsDataRaw = z.infer<
typeof validateContentPageRefsSchema
>

View File

@@ -8,13 +8,7 @@ import { makeImageVaultImage } from "@/utils/imageVault"
import { removeMultipleSlashes } from "@/utils/url"
import { removeEmptyObjects } from "../../utils"
import {
Block,
ContentPage,
ContentPageDataRaw,
Sidebar,
validateContentPageSchema,
} from "./output"
import { validateContentPageSchema } from "./output"
import {
fetchContentPageRefs,
generatePageTags,
@@ -32,6 +26,12 @@ import {
TrackingChannelEnum,
TrackingSDKPageData,
} from "@/types/components/tracking"
import {
Block,
ContentPage,
ContentPageDataRaw,
Sidebar,
} from "@/types/trpc/routers/contentstack/contentPage"
export const contentPageQueryRouter = router({
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {

View File

@@ -9,11 +9,12 @@ import { generateTag, generateTags } from "@/utils/generateTag"
import { removeMultipleSlashes } from "@/utils/url"
import { removeEmptyObjects } from "../../utils"
import { ContentPageRefsDataRaw, validateContentPageRefsSchema } from "./output"
import { validateContentPageRefsSchema } from "./output"
import { ContentBlocksTypenameEnum } from "@/types/components/content/enums"
import { Edges } from "@/types/requests/utils/edges"
import { NodeRefs } from "@/types/requests/utils/refs"
import { ContentPageRefsDataRaw } from "@/types/trpc/routers/contentstack/contentPage"
const meter = metrics.getMeter("trpc.contentPage")
// OpenTelemetry metrics: ContentPage

View File

@@ -1,12 +1,13 @@
import { Lang } from "@/constants/languages"
import { membershipLevels } from "@/constants/membershipLevels"
import type { IntlFormatters } from "@formatjs/intl"
import {
Block,
CardsGrid,
DynamicContent,
} from "@/server/routers/contentstack/contentPage/output"
import type { IntlFormatters } from "@formatjs/intl"
} from "@/types/trpc/routers/contentstack/contentPage"
export type BlocksProps = {
blocks: Block[]

View File

@@ -1,6 +1,5 @@
import { JoinLoyaltyContact } from "@/server/routers/contentstack/contentPage/output"
import { Typename } from "@/types/requests/utils/typename"
import { JoinLoyaltyContact } from "@/types/trpc/routers/contentstack/contentPage"
export enum ContentBlocksTypenameEnum {
ContentPageBlocksContent = "ContentPageBlocksContent",

View File

@@ -1,8 +1,9 @@
import { ContactFields } from "@/server/routers/contentstack/base/output"
import {
JoinLoyaltyContact,
Sidebar,
} from "@/server/routers/contentstack/contentPage/output"
} from "@/types/trpc/routers/contentstack/contentPage"
export type SidebarProps = {
blocks: Sidebar[]

View File

@@ -1,17 +1,84 @@
import { z } from "zod"
import {
Block,
cardBlock,
contentPageBlockTextContent,
contentPageCards,
contentPageDynamicContent,
contentPageJoinLoyaltyContact,
contentPageShortcuts,
contentPageSidebarDynamicContent,
contentPageSidebarTextContent,
loyaltyCardBlock,
validateContentPageRefsSchema,
validateContentPageSchema,
} from "@/server/routers/contentstack/contentPage/output"
import { ImageVaultAsset } from "@/types/components/imageVault"
import { Embeds } from "@/types/requests/embeds"
import { EdgesWithTotalCount } from "@/types/requests/utils/edges"
import { RTEDocument } from "@/types/rte/node"
export type ContentPageDataRaw = z.infer<typeof validateContentPageSchema>
type ContentPageRaw = ContentPageDataRaw["content_page"]
export type ContentPage = Omit<ContentPageRaw, "hero_image"> & {
export type ContentPage = Omit<
ContentPageRaw,
"blocks" | "hero_image" | "sidebar"
> & {
heroImage?: ImageVaultAsset
blocks?: Block[]
blocks: Block[]
sidebar: Sidebar[]
}
export type ContentPageRefsDataRaw = z.infer<
typeof validateContentPageRefsSchema
>
type SidebarContentRaw = z.infer<typeof contentPageSidebarTextContent>
type SideBarDynamicContent = z.infer<typeof contentPageSidebarDynamicContent>
export type JoinLoyaltyContact = z.infer<typeof contentPageJoinLoyaltyContact>
export type RteSidebarContent = Omit<SidebarContentRaw, "content"> & {
content: {
content: {
json: RTEDocument
embedded_itemsConnection: EdgesWithTotalCount<Embeds>
}
}
}
export type Sidebar =
| JoinLoyaltyContact
| RteSidebarContent
| SideBarDynamicContent
export type DynamicContent = z.infer<typeof contentPageDynamicContent>
type BlockContentRaw = z.infer<typeof contentPageBlockTextContent>
export interface RteBlockContent extends BlockContentRaw {
content: {
content: {
json: RTEDocument
embedded_itemsConnection: EdgesWithTotalCount<Embeds>
}
}
}
export type Shortcuts = z.infer<typeof contentPageShortcuts>
type LoyaltyCardRaw = z.infer<typeof loyaltyCardBlock>
type LoyaltyCard = Omit<LoyaltyCardRaw, "image"> & {
image?: ImageVaultAsset
}
type CardRaw = z.infer<typeof cardBlock>
type Card = Omit<CardRaw, "background_image"> & {
backgroundImage?: ImageVaultAsset
}
type CardsGridRaw = z.infer<typeof contentPageCards>
export type CardsGrid = Omit<CardsGridRaw, "cards"> & {
cards: (LoyaltyCard | Card)[]
}
export type CardsRaw = CardsGrid["cards_grid"]["cards"][number]
export type Block = RteBlockContent | Shortcuts | CardsGrid | DynamicContent