Feat/SW-3028 hotel page campaigns

* feat(SW-3028): Added query and typings to fetch campaigns by hotelUid
* feat(SW-3028): Added components for campaigns to the hotel page
* feat(SW-3028): Implemented prioritized campaigns list
* chore(SW-3028): Refactor how campaigns are fetched on hotel pages
* feat(SW-3028): Added offers/campaigns to tab navigation

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-08-21 13:00:34 +00:00
parent 456e10c674
commit 2064732e56
22 changed files with 566 additions and 45 deletions

View File

@@ -6,7 +6,9 @@ import { GetHotelPage } from "../../../graphql/Query/HotelPage/HotelPage.graphql
import { request } from "../../../graphql/request"
import { contentstackExtendedProcedureUID } from "../../../procedures"
import { generateTag } from "../../../utils/generateTag"
import { getCampaignPagesByHotelPageUid } from "../campaignPage/utils"
import { hotelPageSchema } from "./output"
import { getSortedCampaigns } from "./utils"
import type { GetHotelPageData } from "../../../types/hotelPage"
@@ -22,7 +24,7 @@ export const hotelPageQueryRouter = router({
metricsGetHotelPage.start()
const response = await request<GetHotelPageData>(
const hotelPageResponse = await request<GetHotelPageData>(
GetHotelPage,
{
locale: lang,
@@ -33,13 +35,14 @@ export const hotelPageQueryRouter = router({
ttl: "max",
}
)
if (!response.data) {
const notFoundError = notFound(response)
if (!hotelPageResponse.data) {
const notFoundError = notFound(hotelPageResponse)
metricsGetHotelPage.noDataError()
throw notFoundError
}
const validatedHotelPage = hotelPageSchema.safeParse(response.data)
const validatedHotelPage = hotelPageSchema.safeParse(hotelPageResponse.data)
if (!validatedHotelPage.success) {
metricsGetHotelPage.validationError(validatedHotelPage.error)
@@ -48,6 +51,19 @@ export const hotelPageQueryRouter = router({
metricsGetHotelPage.success()
return validatedHotelPage.data.hotel_page
const hotelCampaigns = await getCampaignPagesByHotelPageUid(uid, lang)
const hotelPage = validatedHotelPage.data.hotel_page
const { prioritizedCampaigns, ...campaignsBlockContent } =
hotelPage.campaigns
return {
...hotelPage,
campaignsBlock: hotelCampaigns?.length
? {
...campaignsBlockContent,
campaigns: getSortedCampaigns(prioritizedCampaigns, hotelCampaigns),
}
: null,
}
}),
})