From 33c274bce169241cfd4f5fc3b1506a252ba560e1 Mon Sep 17 00:00:00 2001 From: Hrishikesh Vaipurkar Date: Fri, 1 Aug 2025 08:26:32 +0000 Subject: [PATCH] Merged in fix/SW-2926-hotel-special-alerts- (pull request #2580) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(SW-2926): Display alerts in booking flow if date range matches search dates and in hotel page if current date is in date range * fix(SW-2926): Display alerts in booking flow if date range matches search dates and in hotel page if current date is in date range * fix(SW-2926) Updated hotel alerts with respect to booking dates * fix(SW-2926): Optimized code Approved-by: Matilda Landström --- .../ContentType/HotelPage/index.tsx | 15 ++++++-- .../BookingConfirmation/index.tsx | 7 +++- .../HotelReservation/MyStay/index.tsx | 8 +++++ .../SelectRate/HotelInfoCard/index.tsx | 34 ++++--------------- .../HotelReservation/utils/index.tsx | 32 +++++++++++++++++ .../hotels/schemas/hotel/specialAlerts.ts | 4 +-- 6 files changed, 67 insertions(+), 33 deletions(-) diff --git a/apps/scandic-web/components/ContentType/HotelPage/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/index.tsx index ee1d318ed..5f8342675 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/index.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/index.tsx @@ -1,6 +1,7 @@ import { notFound } from "next/navigation" import { Suspense } from "react" +import { dt } from "@scandic-hotels/common/dt" import { safeTry } from "@scandic-hotels/common/utils/safeTry" import { @@ -181,9 +182,17 @@ export default async function HotelPage({ hotelId }: HotelPageProps) { {specialAlerts.length ? (
{specialAlerts - .filter( - (alert) => alert.name !== AlertName.HotelChildrenInBooking - ) + .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) => ( - {hotel.specialAlerts.map((alert) => ( + {getHotelAlertsForBookingDates( + hotel.specialAlerts, + booking.checkInDate, + booking.checkOutDate + ).map((alert) => (
@@ -101,30 +104,7 @@ export default async function HotelInfoCard({
- {hotel.specialAlerts.map((alert) => { - if (alert.endDate && alert.startDate) { - const endDate = dt(alert.endDate) - const startDate = dt(alert.startDate) - - const fromDateIsBetweenAlertDates = dt(fromDate).isBetween( - startDate, - endDate, - "date", - "[]" - ) - const toDateIsBetweenAlertDates = dt(toDate).isBetween( - startDate, - endDate, - "date", - "[]" - ) - const bookingSpanIsBetweenAlertDates = - fromDateIsBetweenAlertDates && toDateIsBetweenAlertDates - if (!bookingSpanIsBetweenAlertDates) { - return null - } - } - + {specialAlerts.map((alert) => { return (
, + fromDate: string, + toDate: string +) { + return specialAlerts.filter((alert) => { + if (alert.endDate && alert.startDate) { + const endDate = dt(alert.endDate) + const startDate = dt(alert.startDate) + + const fromDateIsBetweenAlertDates = dt(fromDate).isBetween( + startDate, + endDate, + "date", + "[]" + ) + const toDateIsBetweenAlertDates = dt(toDate).isBetween( + startDate, + endDate, + "date", + "[]" + ) + const bookingSpanIsBetweenAlertDates = + fromDateIsBetweenAlertDates || toDateIsBetweenAlertDates + return bookingSpanIsBetweenAlertDates + } + return true + }) +} diff --git a/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts b/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts index b182cafbe..e30ae9c33 100644 --- a/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts +++ b/packages/trpc/lib/routers/hotels/schemas/hotel/specialAlerts.ts @@ -26,8 +26,8 @@ export const specialAlertsSchema = z if (!hasDates) { return hasText } - const shouldShowNow = alert.startDate <= now && alert.endDate >= now - return shouldShowNow && hasText + const isAlertExpired = alert.endDate < now + return !isAlertExpired && hasText }) return filteredAlerts.map((alert, idx) => ({ heading: alert.title || null,