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,