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,
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user