feat(SW-3015): Added pagelinks for campaign page on all connections

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-06-18 12:06:48 +00:00
parent 2f553bb945
commit c783f3a764
39 changed files with 248 additions and 39 deletions

View File

@@ -65,6 +65,17 @@ export const destinationCityPageRefSchema = z.object({
system: systemSchema,
})
export const campaignPageSchema = z
.object({
__typename: z.literal(ContentEnum.blocks.CampaignPage),
})
.merge(pageLinkSchema)
export const campaignPageRefSchema = z.object({
__typename: z.literal(ContentEnum.blocks.CampaignPage),
system: systemSchema,
})
export const destinationCountryPageSchema = z
.object({
__typename: z.literal(ContentEnum.blocks.DestinationCountryPage),
@@ -122,6 +133,7 @@ export const startPageRefSchema = z.object({
export const linkUnionSchema = z.discriminatedUnion("__typename", [
accountPageSchema,
campaignPageSchema,
collectionPageSchema,
contentPageSchema,
destinationCityPageSchema,
@@ -134,6 +146,7 @@ export const linkUnionSchema = z.discriminatedUnion("__typename", [
type Data =
| z.output<typeof accountPageSchema>
| z.output<typeof campaignPageSchema>
| z.output<typeof collectionPageSchema>
| z.output<typeof contentPageSchema>
| z.output<typeof destinationCityPageSchema>
@@ -148,10 +161,11 @@ export function transformPageLink(data: Data) {
if (data && "__typename" in data) {
switch (data.__typename) {
case ContentEnum.blocks.AccountPage:
case ContentEnum.blocks.HotelPage:
case ContentEnum.blocks.CampaignPage:
case ContentEnum.blocks.DestinationCityPage:
case ContentEnum.blocks.DestinationCountryPage:
case ContentEnum.blocks.DestinationOverviewPage:
case ContentEnum.blocks.HotelPage:
case ContentEnum.blocks.StartPage:
return {
__typename: data.__typename,
@@ -159,8 +173,8 @@ export function transformPageLink(data: Data) {
title: data.title,
url: removeMultipleSlashes(`/${data.system.locale}/${data.url}`),
}
case ContentEnum.blocks.ContentPage:
case ContentEnum.blocks.CollectionPage:
case ContentEnum.blocks.ContentPage:
case ContentEnum.blocks.LoyaltyPage:
// TODO: Once all links use this transform
// `web` can be removed and not to be worried
@@ -179,26 +193,28 @@ export function transformPageLink(data: Data) {
}
export const linkRefsUnionSchema = z.discriminatedUnion("__typename", [
contentPageRefSchema,
hotelPageRefSchema,
loyaltyPageRefSchema,
accountPageRefSchema,
campaignPageRefSchema,
collectionPageRefSchema,
contentPageRefSchema,
destinationCityPageRefSchema,
destinationCountryPageRefSchema,
destinationOverviewPageRefSchema,
hotelPageRefSchema,
loyaltyPageRefSchema,
startPageRefSchema,
])
type RefData =
| z.output<typeof accountPageRefSchema>
| z.output<typeof campaignPageRefSchema>
| z.output<typeof collectionPageRefSchema>
| z.output<typeof contentPageRefSchema>
| z.output<typeof destinationCityPageRefSchema>
| z.output<typeof destinationCountryPageRefSchema>
| z.output<typeof destinationOverviewPageRefSchema>
| z.output<typeof hotelPageRefSchema>
| z.output<typeof loyaltyPageRefSchema>
| z.output<typeof destinationCountryPageRefSchema>
| z.output<typeof destinationCityPageRefSchema>
| z.output<typeof destinationOverviewPageRefSchema>
| z.output<typeof startPageRefSchema>
| Object
@@ -206,13 +222,14 @@ export function transformPageLinkRef(data: RefData) {
if (data && "__typename" in data) {
switch (data.__typename) {
case ContentEnum.blocks.AccountPage:
case ContentEnum.blocks.ContentPage:
case ContentEnum.blocks.CampaignPage:
case ContentEnum.blocks.CollectionPage:
case ContentEnum.blocks.HotelPage:
case ContentEnum.blocks.LoyaltyPage:
case ContentEnum.blocks.ContentPage:
case ContentEnum.blocks.DestinationCityPage:
case ContentEnum.blocks.DestinationCountryPage:
case ContentEnum.blocks.DestinationOverviewPage:
case ContentEnum.blocks.HotelPage:
case ContentEnum.blocks.LoyaltyPage:
case ContentEnum.blocks.StartPage:
return data.system
}