From a9c1a911347ecb1288b1eb83fe2525dccbf524d9 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Fri, 5 Dec 2025 06:31:17 +0000 Subject: [PATCH] fix(BOOK-599): Filtering on correct values for hotel pages now and added comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Matilda Landström --- .../ContentType/HotelPage/index.tsx | 37 ++++++++----------- .../hotels/schemas/hotel/specialAlerts.ts | 23 ++++-------- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/apps/scandic-web/components/ContentType/HotelPage/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/index.tsx index 5c29439e4..6165a3169 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/index.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/index.tsx @@ -149,6 +149,13 @@ export default async function HotelPage({ const isThemed = hotelTheme !== DEFAULT_THEME const galleryImages = mapApiImagesToGalleryImages(images ?? []) + const filteredAlerts = specialAlerts.filter(({ endDate, name }) => { + // Hotel alerts should only be shown if they: + // - Have no end date or Have an end date in the future (including today) + // - Are not of type 'HotelChildrenInBooking' + const shouldShowNow = !endDate || dt().isSameOrBefore(dt(endDate), "day") + return name !== AlertName.HotelChildrenInBooking && shouldShowNow + }) return (
@@ -194,28 +201,16 @@ export default async function HotelPage({
- {specialAlerts.length ? ( + {filteredAlerts.length ? (
- {specialAlerts - .filter((alert) => { - const now = dt().utc().format("YYYY-MM-DD") - const shouldShowNow = - alert.startDate && alert.endDate - ? alert.startDate <= now && alert.endDate >= now - : true - return ( - alert.name !== AlertName.HotelChildrenInBooking && - shouldShowNow - ) - }) - .map((alert) => ( - - ))} + {filteredAlerts.map((alert) => ( + + ))}
) : null} diff --git a/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts b/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts index 387b147bf..1949011f0 100644 --- a/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts +++ b/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts @@ -1,7 +1,6 @@ import { z } from "zod" import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert" -import { dt } from "@scandic-hotels/common/dt" import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator" const specialAlertSchema = z.object({ @@ -16,19 +15,13 @@ const specialAlertSchema = z.object({ export const specialAlertsSchema = z .array(specialAlertSchema) .nullish() - .transform((arr) => (arr ? arr.filter(Boolean) : [])) - .transform((data) => { - const now = dt().utc().format("YYYY-MM-DD") - const filteredAlerts = data.filter((alert) => { - const hasText = alert.description || alert.title - const hasDates = alert.startDate && alert.endDate - if (!hasDates) { - return hasText - } - const isAlertExpired = alert.endDate < now - return !isAlertExpired && hasText - }) - return filteredAlerts.map((alert, idx) => ({ + // Filter out alerts with no title and no description since they won't have any visible content + // We're filtering on dates on the hotel page itself + .transform((arr) => + arr ? arr.filter((alert) => alert?.description || alert?.title) : [] + ) + .transform((alerts) => + alerts.map((alert, idx) => ({ heading: alert.title || null, id: `alert-${alert.type}-${idx}`, name: alert.type, @@ -38,4 +31,4 @@ export const specialAlertsSchema = z endDate: alert.endDate, startDate: alert.startDate, })) - }) + )