feat(SW-2975): Added top campaign to campaign overview page

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-06-24 10:22:07 +00:00
parent 438de66a1f
commit 11201e238d
13 changed files with 212 additions and 37 deletions

View File

@@ -21,20 +21,24 @@ import type { HotelDataWithUrl } from "@/types/hotel"
interface CampaignHotelListingClientProps { interface CampaignHotelListingClientProps {
heading: string heading: string
hotels: HotelDataWithUrl[] hotels: HotelDataWithUrl[]
visibleCountMobile?: 3 | 6
visibleCountDesktop?: 3 | 6
} }
export default function CampaignHotelListingClient({ export default function CampaignHotelListingClient({
heading, heading,
hotels, hotels,
visibleCountMobile = 3,
visibleCountDesktop = 6,
}: CampaignHotelListingClientProps) { }: CampaignHotelListingClientProps) {
const intl = useIntl() const intl = useIntl()
const isMobile = useMediaQuery("(max-width: 767px)") const isMobile = useMediaQuery("(max-width: 767px)")
const scrollRef = useRef<HTMLElement>(null) const scrollRef = useRef<HTMLElement>(null)
const initialCount = isMobile ? 3 : 6 // Initial number of hotels to show const initialCount = isMobile ? visibleCountMobile : visibleCountDesktop // Initial number of hotels to show
const thresholdCount = isMobile ? 6 : 9 // This is the threshold at which we start showing the "Show More" button const thresholdCount = initialCount + 3 // This is the threshold at which we start showing the "Show More" button
const showAllThreshold = isMobile ? 9 : 18 // This is the threshold at which we show the "Show All" button const showAllThreshold = initialCount * 3 // This is the threshold at which we show the "Show All" button
const incrementCount = isMobile ? 3 : 6 // Number of hotels to increment when the button is clicked const incrementCount = initialCount // Number of hotels to increment when the button is clicked
const [visibleCount, setVisibleCount] = useState(() => const [visibleCount, setVisibleCount] = useState(() =>
// Set initial visible count based on the number of hotels and the threshold // Set initial visible count based on the number of hotels and the threshold
@@ -86,8 +90,8 @@ export default function CampaignHotelListingClient({
return ( return (
<section className={styles.hotelListingSection} ref={scrollRef}> <section className={styles.hotelListingSection} ref={scrollRef}>
<header className={styles.header}> <header className={styles.header}>
<Typography variant="Title/md"> <Typography variant="Title/Subtitle/lg">
<h2 className={styles.heading}>{heading}</h2> <h3>{heading}</h3>
</Typography> </Typography>
</header> </header>
<ul className={styles.list}> <ul className={styles.list}>

View File

@@ -8,10 +8,6 @@
scroll-margin-top: var(--scroll-margin-top); scroll-margin-top: var(--scroll-margin-top);
} }
.heading {
color: var(--Text-Heading);
}
.list { .list {
list-style: none; list-style: none;
display: grid; display: grid;
@@ -27,7 +23,6 @@
--scroll-margin-top: calc( --scroll-margin-top: calc(
var(--booking-widget-tablet-height) + var(--Spacing-x2) var(--booking-widget-tablet-height) + var(--Spacing-x2)
); );
gap: var(--Space-x5);
} }
.list { .list {
row-gap: var(--Space-x5); row-gap: var(--Space-x5);

View File

@@ -5,11 +5,15 @@ import CampaignHotelListingClient from "./Client"
interface CampaignHotelListingProps { interface CampaignHotelListingProps {
heading: string heading: string
hotelIds: string[] hotelIds: string[]
visibleCountMobile?: 3 | 6
visibleCountDesktop?: 3 | 6
} }
export default async function CampaignHotelListing({ export default async function CampaignHotelListing({
heading, heading,
hotelIds, hotelIds,
visibleCountMobile,
visibleCountDesktop,
}: CampaignHotelListingProps) { }: CampaignHotelListingProps) {
const hotels = await getHotelsByCSFilter({ hotelsToInclude: hotelIds }) const hotels = await getHotelsByCSFilter({ hotelsToInclude: hotelIds })
@@ -17,5 +21,12 @@ export default async function CampaignHotelListing({
return null return null
} }
return <CampaignHotelListingClient heading={heading} hotels={hotels} /> return (
<CampaignHotelListingClient
heading={heading}
hotels={hotels}
visibleCountMobile={visibleCountMobile}
visibleCountDesktop={visibleCountDesktop}
/>
)
} }

View File

@@ -0,0 +1,43 @@
import { Typography } from "@scandic-hotels/design-system/Typography"
import CampaignHotelListing from "@/components/Blocks/CampaignHotelListing"
import CampaignHero from "@/components/ContentType/CampaignPage/Hero"
import { getIntl } from "@/i18n"
import { getLang } from "@/i18n/serverContext"
import styles from "./topCampaign.module.css"
import { type CampaignOverviewPageData } from "@/types/trpc/routers/contentstack/campaignOverviewPage"
interface TopCampaignProps {
topCampaign: CampaignOverviewPageData["topCampaign"]
}
export default async function TopCampaign({ topCampaign }: TopCampaignProps) {
const lang = await getLang()
const intl = await getIntl()
const buttonData = {
cta: intl.formatMessage({ defaultMessage: "Explore the offer" }),
url: `/${lang}${topCampaign.url}`,
}
return (
<section className={styles.topCampaign}>
<Typography variant="Title/md">
<h2 className={styles.heading}>{topCampaign.heading}</h2>
</Typography>
<CampaignHero {...topCampaign.hero} button={buttonData} />
<CampaignHotelListing
heading={
topCampaign.hotel_listing.heading ||
intl.formatMessage({
defaultMessage: "Hotels included in this offer",
})
}
hotelIds={topCampaign.hotel_listing.hotelIds}
visibleCountMobile={3}
visibleCountDesktop={3}
/>
</section>
)
}

View File

@@ -0,0 +1,8 @@
.topCampaign {
display: grid;
gap: var(--Space-x3);
}
.heading {
color: var(--Text-Heading);
}

View File

@@ -5,6 +5,7 @@ import { Typography } from "@scandic-hotels/design-system/Typography"
import { getCampaignOverviewPage } from "@/lib/trpc/memoizedRequests" import { getCampaignOverviewPage } from "@/lib/trpc/memoizedRequests"
import TopCampaign from "@/components/ContentType/CampaignOverviewPage/TopCampaign"
import LinkChips from "@/components/TempDesignSystem/LinkChips" import LinkChips from "@/components/TempDesignSystem/LinkChips"
import CampaignOverviewPageSkeleton from "./CampaignOverviewPageSkeleton" import CampaignOverviewPageSkeleton from "./CampaignOverviewPageSkeleton"
@@ -19,7 +20,7 @@ export default async function CampaignOverviewPage() {
} }
const { campaignOverviewPage } = pageData const { campaignOverviewPage } = pageData
const { header } = campaignOverviewPage const { header, topCampaign } = campaignOverviewPage
return ( return (
<> <>
@@ -46,8 +47,7 @@ export default async function CampaignOverviewPage() {
) : null} ) : null}
<main className={styles.mainContent}> <main className={styles.mainContent}>
{/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} <TopCampaign topCampaign={topCampaign} />
{">>> MAIN CONTENT <<<"}
</main> </main>
</div> </div>
</Suspense> </Suspense>

View File

@@ -10,7 +10,7 @@ import { variants } from "./variants"
import styles from "./hero.module.css" import styles from "./hero.module.css"
import type { HeroProps } from "./types" import type { HeroProps } from "@/components/ContentType/CampaignPage/Hero/types"
export default async function CampaignHero({ export default async function CampaignHero({
image, image,
@@ -82,11 +82,11 @@ export default async function CampaignHero({
) : null} ) : null}
</span> </span>
) : null} ) : null}
{button.link ? ( {button ? (
<ButtonLink <ButtonLink
variant="Secondary" variant="Secondary"
color={theme === "Peach" ? "Primary" : "Inverted"} color={theme === "Peach" ? "Primary" : "Inverted"}
href={button.link.url} href={button.url}
typography="Body/Paragraph/mdBold" typography="Body/Paragraph/mdBold"
size="Medium" size="Medium"
> >

View File

@@ -0,0 +1,24 @@
#import "../System.graphql"
#import "../Blocks/HotelListing.graphql"
#import "../CampaignPage/IncludedHotels.graphql"
#import "../CampaignPage/Hero.graphql"
fragment TopCampaign on CampaignPage {
heading
included_hotels {
...CampaignPageIncludedHotels
}
blocks {
__typename
...HotelListing_CampaignPage
}
url
...Hero_CampaignPage
}
fragment TopCampaignRef on CampaignPage {
system {
...System
}
}

View File

@@ -1,6 +1,7 @@
#import "../../Fragments/System.graphql" #import "../../Fragments/System.graphql"
#import "../../Fragments/CampaignOverviewPage/NavigationLinks.graphql" #import "../../Fragments/CampaignOverviewPage/NavigationLinks.graphql"
#import "../../Fragments/CampaignOverviewPage/TopCampaign.graphql"
query GetCampaignOverviewPage($locale: String!, $uid: String!) { query GetCampaignOverviewPage($locale: String!, $uid: String!) {
campaign_overview_page(uid: $uid, locale: $locale) { campaign_overview_page(uid: $uid, locale: $locale) {
@@ -10,6 +11,13 @@ query GetCampaignOverviewPage($locale: String!, $uid: String!) {
preamble preamble
...NavigationLinks_CampaignOverviewPage ...NavigationLinks_CampaignOverviewPage
} }
top_campaignConnection {
edges {
node {
...TopCampaign
}
}
}
system { system {
...System ...System
created_at created_at
@@ -26,6 +34,13 @@ query GetCampaignOverviewPageRefs($locale: String!, $uid: String!) {
header { header {
...NavigationLinksRef_CampaignOverviewPage ...NavigationLinksRef_CampaignOverviewPage
} }
top_campaignConnection {
edges {
node {
...TopCampaignRef
}
}
}
system { system {
...System ...System
} }

View File

@@ -42,9 +42,6 @@ query GetCampaignPage($locale: String!, $uid: String!) {
query GetCampaignPageRefs($locale: String!, $uid: String!) { query GetCampaignPageRefs($locale: String!, $uid: String!) {
campaign_page(locale: $locale, uid: $uid) { campaign_page(locale: $locale, uid: $uid) {
included_hotels {
...CampaignPageIncludedHotelsRef
}
blocks { blocks {
__typename __typename
...CarouselCards_CampaignPageRefs ...CarouselCards_CampaignPageRefs

View File

@@ -1,5 +1,11 @@
import { z } from "zod" import { z } from "zod"
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
import {
campaignPageHotelListing,
heroSchema,
includedHotelsSchema,
} from "@/server/routers/contentstack/campaignPage/output"
import { import {
linkAndTitleSchema, linkAndTitleSchema,
linkConnectionRefs, linkConnectionRefs,
@@ -7,6 +13,8 @@ import {
import { systemSchema } from "../schemas/system" import { systemSchema } from "../schemas/system"
import { CampaignPageEnum } from "@/types/enums/campaignPage"
const navigationLinksSchema = z const navigationLinksSchema = z
.array(linkAndTitleSchema) .array(linkAndTitleSchema)
.nullable() .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({ export const campaignOverviewPageSchema = z.object({
campaign_overview_page: z.object({ campaign_overview_page: z
title: z.string(), .object({
header: z.object({ title: z.string(),
heading: z.string(), header: z.object({
preamble: z.string(), heading: z.string(),
navigation_links: navigationLinksSchema, 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({ trackingProps: z.object({
url: z.string(), url: z.string(),
}), }),
@@ -52,6 +103,15 @@ const campaignOverviewPageHeaderRefs = z.object({
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({
edges: z.array(
z.object({
node: z.object({
system: systemSchema,
}),
})
),
}),
system: systemSchema, system: systemSchema,
}), }),
}) })

View File

@@ -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 return connections
} }

View File

@@ -56,17 +56,30 @@ export const heroSchema = z.object({
image: tempImageVaultAssetSchema, image: tempImageVaultAssetSchema,
heading: z.string(), heading: z.string(),
theme: z.enum(["Peach", "Burgundy"]).default("Peach"), 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 rate_text: z
.object({ .object({
bold_text: z.string().nullish(), bold_text: z.string().nullish(),
text: z.string().nullish(), text: z.string().nullish(),
}) })
.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({ .object({
list_1Connection: z.object({ list_1Connection: z.object({
edges: z.array( edges: z.array(