feat(SW-391): Added sidepeek functionality to teasercard

This commit is contained in:
Erik Tiekstra
2024-10-10 08:13:50 +02:00
parent a5d9eb43c9
commit 9620071c78
21 changed files with 311 additions and 69 deletions

View File

@@ -1,5 +1,8 @@
import { Lang } from "@/constants/languages"
import { GetContentPage } from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
import {
GetContentPage,
GetContentPageBlocks,
} from "@/lib/graphql/Query/ContentPage/ContentPage.graphql"
import { request } from "@/lib/graphql/request"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
@@ -40,18 +43,38 @@ export const contentPageQueryRouter = router({
})
)
const response = await request<GetContentPageSchema>(
GetContentPage,
{ locale: lang, uid },
{
cache: "force-cache",
next: {
tags,
},
}
)
const [mainResponse, blocksResponse] = await Promise.all([
request<GetContentPageSchema>(
GetContentPage,
{ locale: lang, uid },
{
cache: "force-cache",
next: {
tags,
},
}
),
request<GetContentPageSchema>(
GetContentPageBlocks,
{ locale: lang, uid },
{
cache: "force-cache",
next: {
tags,
},
}
),
])
const contentPage = contentPageSchema.safeParse(response.data)
const responseData = {
...mainResponse.data,
content_page: {
...mainResponse.data.content_page,
blocks: blocksResponse.data.content_page.blocks,
},
}
const contentPage = contentPageSchema.safeParse(responseData)
if (!contentPage.success) {
console.error(

View File

@@ -1,12 +1,17 @@
import { z } from "zod"
import * as pageLinks from "@/server/routers/contentstack/schemas/pageLinks"
import { tempImageVaultAssetSchema } from "../imageVault"
import { systemSchema } from "../system"
import { buttonSchema } from "./utils/buttonLinkSchema"
import { linkConnectionRefsSchema } from "./utils/linkConnection"
import { imageSchema } from "./image"
import { imageContainerSchema } from "./imageContainer"
import { BlocksEnums } from "@/types/enums/blocks"
import { CardsGridEnum } from "@/types/enums/cardsGrid"
import { CardsGridLayoutEnum } from "@/types/trpc/routers/contentstack/blocks"
export const cardBlockSchema = z.object({
__typename: z.literal(CardsGridEnum.cards.Card),
@@ -49,17 +54,57 @@ export const teaserCardBlockSchema = z.object({
has_primary_button: z.boolean().default(false),
has_secondary_button: z.boolean().default(false),
has_sidepeek_button: z.boolean().default(false),
side_peek_button: z
sidepeek_button: z
.object({
title: z.string().optional().default(""),
call_to_action_text: z.string().optional().default(""),
})
.optional(),
sidepeek_content: z
.object({
heading: z.string(),
content: z.object({
json: z.any(),
embedded_itemsConnection: z.object({
edges: z.array(
z.object({
node: z
.discriminatedUnion("__typename", [
imageContainerSchema,
imageSchema,
pageLinks.accountPageSchema,
pageLinks.contentPageSchema,
pageLinks.hotelPageSchema,
pageLinks.loyaltyPageSchema,
])
.transform((data) => {
const link = pageLinks.transform(data)
if (link) {
return link
}
return data
}),
})
),
}),
}),
has_primary_button: z.boolean().default(false),
primary_button: buttonSchema,
has_secondary_button: z.boolean().default(false),
secondary_button: buttonSchema,
})
.optional(),
// sidepeek_content: z
// .object({
// heading: z.string(),
// })
// .optional(),
system: systemSchema,
})
export function transformTeaserCardBlock(
card: typeof teaserCardBlockSchema._type
) {
console.log({ has_sidepeek_button: card.sidepeek_content })
return {
__typename: card.__typename,
body_text: card.body_text,
@@ -68,8 +113,9 @@ export function transformTeaserCardBlock(
secondaryButton: card.has_secondary_button
? card.secondary_button
: undefined,
sidePeekButton: card.has_sidepeek_button
? card.side_peek_button
sidePeekButton: card.has_sidepeek_button ? card.sidepeek_button : undefined,
sidePeekContent: card.has_sidepeek_button
? card.sidepeek_content
: undefined,
image: card.image,
system: card.system,
@@ -105,7 +151,7 @@ export const cardsGridSchema = z.object({
})
),
}),
layout: z.enum(["twoColumnGrid", "threeColumnGrid", "twoPlusOne"]),
layout: z.nativeEnum(CardsGridLayoutEnum),
preamble: z.string().optional().default(""),
theme: z.enum(["one", "two", "three"]).nullable(),
title: z.string().optional().default(""),

View File

@@ -20,6 +20,7 @@ export const buttonSchema = z
pageLinks.accountPageSchema,
pageLinks.contentPageSchema,
pageLinks.loyaltyPageSchema,
pageLinks.hotelPageSchema,
])
.transform((data) => {
const link = pageLinks.transform(data)