feat(SW-2975): Added top campaign to campaign overview page
Approved-by: Matilda Landström
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||
import {
|
||||
campaignPageHotelListing,
|
||||
heroSchema,
|
||||
includedHotelsSchema,
|
||||
} from "@/server/routers/contentstack/campaignPage/output"
|
||||
import {
|
||||
linkAndTitleSchema,
|
||||
linkConnectionRefs,
|
||||
@@ -7,6 +13,8 @@ import {
|
||||
|
||||
import { systemSchema } from "../schemas/system"
|
||||
|
||||
import { CampaignPageEnum } from "@/types/enums/campaignPage"
|
||||
|
||||
const navigationLinksSchema = z
|
||||
.array(linkAndTitleSchema)
|
||||
.nullable()
|
||||
@@ -23,21 +31,64 @@ const navigationLinksSchema = z
|
||||
}))
|
||||
})
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
campaignPageHotelListing,
|
||||
])
|
||||
|
||||
const topCampaignSchema = z
|
||||
.object({
|
||||
heading: z.string(),
|
||||
hero: heroSchema,
|
||||
included_hotels: includedHotelsSchema,
|
||||
blocks: discriminatedUnionArray(blocksSchema.options),
|
||||
url: z.string(),
|
||||
})
|
||||
.transform((data) => {
|
||||
const { blocks, included_hotels, ...rest } = data
|
||||
const hotelListingBlock = blocks.find(
|
||||
(block) =>
|
||||
block.__typename === CampaignPageEnum.ContentStack.blocks.HotelListing
|
||||
)
|
||||
|
||||
return {
|
||||
...rest,
|
||||
hotel_listing: {
|
||||
heading: hotelListingBlock?.hotel_listing.heading || "",
|
||||
hotelIds: included_hotels,
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
export const campaignOverviewPageSchema = z.object({
|
||||
campaign_overview_page: z.object({
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
heading: z.string(),
|
||||
preamble: z.string(),
|
||||
navigation_links: navigationLinksSchema,
|
||||
campaign_overview_page: z
|
||||
.object({
|
||||
title: z.string(),
|
||||
header: z.object({
|
||||
heading: z.string(),
|
||||
preamble: z.string(),
|
||||
navigation_links: navigationLinksSchema,
|
||||
}),
|
||||
top_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: topCampaignSchema,
|
||||
})
|
||||
),
|
||||
}),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => {
|
||||
const { top_campaignConnection, ...rest } = data
|
||||
return {
|
||||
...rest,
|
||||
topCampaign: top_campaignConnection.edges.map(({ node }) => node)[0],
|
||||
}
|
||||
}),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
trackingProps: z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
@@ -52,6 +103,15 @@ const campaignOverviewPageHeaderRefs = z.object({
|
||||
export const campaignOverviewPageRefsSchema = z.object({
|
||||
campaign_overview_page: z.object({
|
||||
header: campaignOverviewPageHeaderRefs,
|
||||
top_campaignConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -28,6 +28,11 @@ export function getConnections({
|
||||
}
|
||||
})
|
||||
}
|
||||
if (campaign_overview_page.top_campaignConnection) {
|
||||
campaign_overview_page.top_campaignConnection.edges.forEach(({ node }) => {
|
||||
connections.push(node.system)
|
||||
})
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
@@ -56,17 +56,30 @@ export const heroSchema = z.object({
|
||||
image: tempImageVaultAssetSchema,
|
||||
heading: z.string(),
|
||||
theme: z.enum(["Peach", "Burgundy"]).default("Peach"),
|
||||
benefits: z.array(z.string()).nullish(),
|
||||
benefits: z
|
||||
.array(z.string())
|
||||
.nullish()
|
||||
.transform((data) => data || []),
|
||||
rate_text: z
|
||||
.object({
|
||||
bold_text: z.string().nullish(),
|
||||
text: z.string().nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
button: z.intersection(z.object({ cta: z.string() }), linkConnectionSchema),
|
||||
button: z
|
||||
.intersection(z.object({ cta: z.string() }), linkConnectionSchema)
|
||||
.transform((data) => {
|
||||
if (!data.link) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
cta: data.cta,
|
||||
url: data.link?.url || "",
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
const includedHotelsSchema = z
|
||||
export const includedHotelsSchema = z
|
||||
.object({
|
||||
list_1Connection: z.object({
|
||||
edges: z.array(
|
||||
|
||||
Reference in New Issue
Block a user