feat(SW-3354): Added possibility to add heading to top campaign on campaign overview page

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-09-03 10:52:50 +00:00
parent 260a544c99
commit 941eb51665
5 changed files with 55 additions and 37 deletions

View File

@@ -16,25 +16,28 @@ interface TopCampaignProps {
export default async function TopCampaign({ topCampaign }: TopCampaignProps) { export default async function TopCampaign({ topCampaign }: TopCampaignProps) {
const lang = await getLang() const lang = await getLang()
const intl = await getIntl() const intl = await getIntl()
const { campaign, heading } = topCampaign
const buttonData = { const buttonData = {
cta: intl.formatMessage({ defaultMessage: "Explore the offer" }), cta: intl.formatMessage({ defaultMessage: "Explore the offer" }),
url: `/${lang}${topCampaign.url}`, url: `/${lang}${campaign.url}`,
} }
return ( return (
<section className={styles.topCampaign}> <section className={styles.topCampaign}>
{heading ? (
<Typography variant="Title/md"> <Typography variant="Title/md">
<h2 className={styles.heading}>{topCampaign.heading}</h2> <h2 className={styles.heading}>{heading}</h2>
</Typography> </Typography>
<CampaignHero {...topCampaign.hero} button={buttonData} /> ) : null}
<CampaignHero {...campaign.hero} button={buttonData} />
<CampaignHotelListing <CampaignHotelListing
heading={ heading={
topCampaign.hotel_listing.heading || campaign.hotel_listing.heading ||
intl.formatMessage({ intl.formatMessage({
defaultMessage: "Hotels included in this offer", defaultMessage: "Hotels included in this offer",
}) })
} }
hotelIds={topCampaign.hotel_listing.hotelIds} hotelIds={campaign.hotel_listing.hotelIds}
visibleCountMobile={3} visibleCountMobile={3}
visibleCountDesktop={3} visibleCountDesktop={3}
/> />

View File

@@ -5,7 +5,6 @@
#import "../CampaignPage/Hero.graphql" #import "../CampaignPage/Hero.graphql"
fragment TopCampaign on CampaignPage { fragment TopCampaign on CampaignPage {
heading
included_hotels { included_hotels {
...CampaignPageIncludedHotels ...CampaignPageIncludedHotels
} }

View File

@@ -15,13 +15,16 @@ query GetCampaignOverviewPage($locale: String!, $uid: String!) {
preamble preamble
...NavigationLinks_CampaignOverviewPage ...NavigationLinks_CampaignOverviewPage
} }
top_campaignConnection { top_campaign_block {
heading
campaignConnection {
edges { edges {
node { node {
...TopCampaign ...TopCampaign
} }
} }
} }
}
blocks { blocks {
__typename __typename
...AllCampaigns ...AllCampaigns
@@ -44,13 +47,15 @@ query GetCampaignOverviewPageRefs($locale: String!, $uid: String!) {
header { header {
...NavigationLinksRef_CampaignOverviewPage ...NavigationLinksRef_CampaignOverviewPage
} }
top_campaignConnection { top_campaign_block {
campaignConnection {
edges { edges {
node { node {
...TopCampaignRef ...TopCampaignRef
} }
} }
} }
}
blocks { blocks {
__typename __typename
...CarouselCards_CampaignOverviewPageRefs ...CarouselCards_CampaignOverviewPageRefs

View File

@@ -45,7 +45,6 @@ export const campaignPageBlocksSchema = z.discriminatedUnion("__typename", [
const topCampaignSchema = z const topCampaignSchema = z
.object({ .object({
heading: z.string(),
hero: heroSchema, hero: heroSchema,
included_hotels: includedHotelsSchema, included_hotels: includedHotelsSchema,
blocks: discriminatedUnionArray(campaignPageBlocksSchema.options), blocks: discriminatedUnionArray(campaignPageBlocksSchema.options),
@@ -106,13 +105,16 @@ export const campaignOverviewPageSchema = z.object({
preamble: z.string(), preamble: z.string(),
navigation_links: navigationLinksSchema, navigation_links: navigationLinksSchema,
}), }),
top_campaignConnection: z.object({ top_campaign_block: z.object({
heading: z.string().nullish(),
campaignConnection: z.object({
edges: z.array( edges: z.array(
z.object({ z.object({
node: topCampaignSchema, node: topCampaignSchema,
}) })
), ),
}), }),
}),
blocks: discriminatedUnionArray(blocksSchema.options), blocks: discriminatedUnionArray(blocksSchema.options),
system: systemSchema.merge( system: systemSchema.merge(
z.object({ z.object({
@@ -122,10 +124,15 @@ export const campaignOverviewPageSchema = z.object({
), ),
}) })
.transform((data) => { .transform((data) => {
const { top_campaignConnection, ...rest } = data const { top_campaign_block, ...rest } = data
return { return {
...rest, ...rest,
topCampaign: top_campaignConnection.edges.map(({ node }) => node)[0], topCampaign: {
heading: top_campaign_block.heading,
campaign: top_campaign_block.campaignConnection.edges.map(
({ node }) => node
)[0],
},
} }
}), }),
trackingProps: z.object({ trackingProps: z.object({
@@ -163,7 +170,8 @@ const blockRefsSchema = z.discriminatedUnion("__typename", [
export const campaignOverviewPageRefsSchema = z.object({ export const campaignOverviewPageRefsSchema = z.object({
campaign_overview_page: z.object({ campaign_overview_page: z.object({
header: campaignOverviewPageHeaderRefs, header: campaignOverviewPageHeaderRefs,
top_campaignConnection: z.object({ top_campaign_block: z.object({
campaignConnection: z.object({
edges: z.array( edges: z.array(
z.object({ z.object({
node: z.object({ node: z.object({
@@ -172,6 +180,7 @@ export const campaignOverviewPageRefsSchema = z.object({
}) })
), ),
}), }),
}),
blocks: discriminatedUnionArray(blockRefsSchema.options).nullable(), blocks: discriminatedUnionArray(blockRefsSchema.options).nullable(),
system: systemSchema, system: systemSchema,
}), }),

View File

@@ -29,10 +29,12 @@ export function getConnections({
} }
}) })
} }
if (campaign_overview_page.top_campaignConnection) { if (campaign_overview_page.top_campaign_block.campaignConnection) {
campaign_overview_page.top_campaignConnection.edges.forEach(({ node }) => { campaign_overview_page.top_campaign_block.campaignConnection.edges.forEach(
({ node }) => {
connections.push(node.system) connections.push(node.system)
}) }
)
} }
if (campaign_overview_page.blocks) { if (campaign_overview_page.blocks) {
campaign_overview_page.blocks.forEach((block) => { campaign_overview_page.blocks.forEach((block) => {