feat(SW-2278): Added hotel listing to campaign page
Approved-by: Matilda Landström
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
carouselCardsSchema,
|
||||
} from "../schemas/blocks/carouselCards"
|
||||
import { essentialsBlockSchema } from "../schemas/blocks/essentials"
|
||||
import { campaignPageHotelListingSchema } from "../schemas/blocks/hotelListing"
|
||||
import { tempImageVaultAssetSchema } from "../schemas/imageVault"
|
||||
import {
|
||||
linkConnectionRefs,
|
||||
@@ -38,10 +39,17 @@ export const campaignPageAccordion = z
|
||||
})
|
||||
.merge(accordionSchema)
|
||||
|
||||
export const campaignPageHotelListing = z
|
||||
.object({
|
||||
__typename: z.literal(CampaignPageEnum.ContentStack.blocks.HotelListing),
|
||||
})
|
||||
.merge(campaignPageHotelListingSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
campaignPageEssentials,
|
||||
campaignPageCarouselCards,
|
||||
campaignPageAccordion,
|
||||
campaignPageHotelListing,
|
||||
])
|
||||
|
||||
export const heroSchema = z.object({
|
||||
@@ -58,30 +66,88 @@ export const heroSchema = z.object({
|
||||
button: z.intersection(z.object({ cta: z.string() }), linkConnectionSchema),
|
||||
})
|
||||
|
||||
export const campaignPageSchema = z.object({
|
||||
campaign_page: z.object({
|
||||
title: z.string(),
|
||||
campaign_identifier: z.string().nullish(),
|
||||
hero: heroSchema,
|
||||
heading: z.string(),
|
||||
subheading: z.string().nullish(),
|
||||
preamble: z.object({
|
||||
is_two_columns: z.boolean().default(false),
|
||||
first_column: z.string(),
|
||||
second_column: z.string(),
|
||||
const includedHotelsSchema = z
|
||||
.object({
|
||||
list_1Connection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
hotel_page_id: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
blocks: discriminatedUnionArray(blocksSchema.options),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
trackingProps: z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
list_2Connection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: z.object({
|
||||
hotel_page_id: z.string(),
|
||||
}),
|
||||
})
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
const list1HotelIds = data.list_1Connection.edges
|
||||
.map((edge) => edge.node.hotel_page_id)
|
||||
.filter(Boolean)
|
||||
const list2HotelIds = data.list_2Connection.edges
|
||||
.map((edge) => edge.node.hotel_page_id)
|
||||
.filter(Boolean)
|
||||
|
||||
return [...new Set([...list1HotelIds, ...list2HotelIds])]
|
||||
})
|
||||
|
||||
export const campaignPageSchema = z
|
||||
.object({
|
||||
campaign_page: z.object({
|
||||
title: z.string(),
|
||||
campaign_identifier: z.string().nullish(),
|
||||
hero: heroSchema,
|
||||
heading: z.string(),
|
||||
subheading: z.string().nullish(),
|
||||
included_hotels: includedHotelsSchema,
|
||||
preamble: z.object({
|
||||
is_two_columns: z.boolean().default(false),
|
||||
first_column: z.string(),
|
||||
second_column: z.string(),
|
||||
}),
|
||||
blocks: discriminatedUnionArray(blocksSchema.options),
|
||||
system: systemSchema.merge(
|
||||
z.object({
|
||||
created_at: z.string(),
|
||||
updated_at: z.string(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
trackingProps: z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => {
|
||||
const blocks = data.campaign_page.blocks.map((block) => {
|
||||
if (
|
||||
block.__typename === CampaignPageEnum.ContentStack.blocks.HotelListing
|
||||
) {
|
||||
return {
|
||||
...block,
|
||||
hotel_listing: {
|
||||
...block.hotel_listing,
|
||||
hotelIds: data.campaign_page.included_hotels,
|
||||
},
|
||||
}
|
||||
}
|
||||
return block
|
||||
})
|
||||
|
||||
return {
|
||||
...data,
|
||||
campaign_page: {
|
||||
...data.campaign_page,
|
||||
blocks: [...blocks],
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
/** REFS */
|
||||
const campaignPageCarouselCardsRef = z
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
dynamicContentRefsSchema,
|
||||
dynamicContentSchema as blockDynamicContentSchema,
|
||||
} from "../schemas/blocks/dynamicContent"
|
||||
import { hotelListingSchema } from "../schemas/blocks/hotelListing"
|
||||
import { contentPageHotelListingSchema } from "../schemas/blocks/hotelListing"
|
||||
import {
|
||||
shortcutsRefsSchema,
|
||||
shortcutsSchema,
|
||||
@@ -113,7 +113,7 @@ export const contentPageHotelListing = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.HotelListing),
|
||||
})
|
||||
.merge(hotelListingSchema)
|
||||
.merge(contentPageHotelListingSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
contentPageAccordion,
|
||||
|
||||
@@ -36,10 +36,10 @@ export const locationFilterSchema = z
|
||||
}
|
||||
})
|
||||
|
||||
export const hotelListingSchema = z.object({
|
||||
export const contentPageHotelListingSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.HotelListing)
|
||||
.default(BlocksEnums.block.HotelListing),
|
||||
.literal(BlocksEnums.block.ContentPageHotelListing)
|
||||
.default(BlocksEnums.block.ContentPageHotelListing),
|
||||
hotel_listing: z
|
||||
.object({
|
||||
heading: z.string().optional(),
|
||||
@@ -60,3 +60,12 @@ export const hotelListingSchema = z.object({
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
export const campaignPageHotelListingSchema = z.object({
|
||||
typename: z
|
||||
.literal(BlocksEnums.block.CampaignPageHotelListing)
|
||||
.default(BlocksEnums.block.CampaignPageHotelListing),
|
||||
hotel_listing: z.object({
|
||||
heading: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -237,7 +237,7 @@ export const getHotelsByCSFilterInput = z.object({
|
||||
country: z.nativeEnum(Country).nullable(),
|
||||
excluded: z.array(z.string()),
|
||||
})
|
||||
.nullable(),
|
||||
.nullish(),
|
||||
hotelsToInclude: z.array(z.string()),
|
||||
})
|
||||
export interface GetHotelsByCSFilterInput
|
||||
|
||||
Reference in New Issue
Block a user