feat(SW-1386): add full width campaign to start page
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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 { BlocksEnums } from "@/types/enums/blocks"
|
||||
|
||||
export const fullWidthCampaignSchema = z.object({
|
||||
full_width_campaign: z.object({
|
||||
full_width_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
background_image: tempImageVaultAssetSchema,
|
||||
heading: z.string().optional(),
|
||||
body_text: z.string().optional(),
|
||||
scripted_top_title: z.string().optional(),
|
||||
has_primary_button: z.boolean().default(false),
|
||||
primary_button: buttonSchema,
|
||||
has_secondary_button: z.boolean().default(false),
|
||||
secondary_button: buttonSchema,
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
export const fullWidthCampaignBlockSchema = z
|
||||
.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.FullWidthCampaign)
|
||||
.optional()
|
||||
.default(BlocksEnums.block.FullWidthCampaign),
|
||||
})
|
||||
.merge(fullWidthCampaignSchema)
|
||||
|
||||
export const fullWidthCampaignBlockRefsSchema = z.object({
|
||||
full_width_campaign: z.object({
|
||||
full_width_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.discriminatedUnion("__typename", [
|
||||
pageLinks.accountPageRefSchema,
|
||||
pageLinks.contentPageRefSchema,
|
||||
pageLinks.loyaltyPageRefSchema,
|
||||
pageLinks.collectionPageRefSchema,
|
||||
pageLinks.hotelPageRefSchema,
|
||||
]),
|
||||
})
|
||||
),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
@@ -6,27 +6,40 @@ import {
|
||||
cardGridRefsSchema,
|
||||
cardsGridSchema,
|
||||
} from "../schemas/blocks/cardsGrid"
|
||||
import {
|
||||
fullWidthCampaignBlockRefsSchema,
|
||||
fullWidthCampaignBlockSchema,
|
||||
} from "../schemas/blocks/fullWidthCampaign"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import { StartPageEnum } from "@/types/enums/startPage"
|
||||
|
||||
export const startPageCards = z
|
||||
const startPageCards = z
|
||||
.object({
|
||||
__typename: z.literal(StartPageEnum.ContentStack.blocks.CardsGrid),
|
||||
})
|
||||
.merge(cardsGridSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [startPageCards])
|
||||
const startPageFullWidthCampaign = z
|
||||
.object({
|
||||
__typename: z.literal(StartPageEnum.ContentStack.blocks.FullWidthCampaign),
|
||||
})
|
||||
.merge(fullWidthCampaignBlockSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
startPageCards,
|
||||
startPageFullWidthCampaign,
|
||||
])
|
||||
|
||||
export const startPageSchema = z.object({
|
||||
start_page: z.object({
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
heading: z.string(),
|
||||
hero_image: tempImageVaultAssetSchema,
|
||||
}),
|
||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
@@ -46,8 +59,15 @@ const startPageCardsRefs = z
|
||||
})
|
||||
.merge(cardGridRefsSchema)
|
||||
|
||||
const startPageFullWidthCampaignRef = z
|
||||
.object({
|
||||
__typename: z.literal(StartPageEnum.ContentStack.blocks.FullWidthCampaign),
|
||||
})
|
||||
.merge(fullWidthCampaignBlockRefsSchema)
|
||||
|
||||
const startPageBlockRefsItem = z.discriminatedUnion("__typename", [
|
||||
startPageCardsRefs,
|
||||
startPageFullWidthCampaignRef,
|
||||
])
|
||||
|
||||
export const startPageRefsSchema = z.object({
|
||||
|
||||
@@ -6,7 +6,7 @@ import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
|
||||
|
||||
import { generateTag } from "@/utils/generateTag"
|
||||
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
||||
|
||||
import { startPageRefsSchema, startPageSchema } from "./output"
|
||||
import {
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
getStartPageRefsSuccessCounter,
|
||||
getStartPageSuccessCounter,
|
||||
} from "./telemetry"
|
||||
import { getConnections } from "./utils"
|
||||
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
@@ -103,6 +104,13 @@ export const startPageQueryRouter = router({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
|
||||
const connections = getConnections(validatedRefsData.data)
|
||||
|
||||
const tags = [
|
||||
generateTagsFromSystem(lang, connections),
|
||||
generateTag(lang, validatedRefsData.data.start_page.system.uid),
|
||||
].flat()
|
||||
const response = await request<GetStartPageData>(
|
||||
GetStartPage,
|
||||
{
|
||||
@@ -112,10 +120,11 @@ export const startPageQueryRouter = router({
|
||||
{
|
||||
cache: "force-cache",
|
||||
next: {
|
||||
tags: [generateTag(lang, uid)],
|
||||
tags,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
const notFoundError = notFound(response)
|
||||
getStartPageFailCounter.add(1, {
|
||||
|
||||
24
server/routers/contentstack/startPage/utils.ts
Normal file
24
server/routers/contentstack/startPage/utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { StartPageEnum } from "@/types/enums/startPage"
|
||||
import type { System } from "@/types/requests/system"
|
||||
import type { StartPageRefs } from "@/types/trpc/routers/contentstack/startPage"
|
||||
|
||||
export function getConnections({ start_page }: StartPageRefs) {
|
||||
const connections: System["system"][] = [start_page.system]
|
||||
|
||||
if (start_page.blocks) {
|
||||
start_page.blocks.forEach((block) => {
|
||||
switch (block.__typename) {
|
||||
case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
|
||||
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
}
|
||||
)
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
Reference in New Issue
Block a user