Merged in fix/SW-2926-hotel-special-alerts- (pull request #2580)

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
This commit is contained in:
Hrishikesh Vaipurkar
2025-08-01 08:26:32 +00:00
parent 3922ade199
commit 33c274bce1
6 changed files with 67 additions and 33 deletions

View File

@@ -1,3 +1,4 @@
import { dt } from "@scandic-hotels/common/dt"
import {
MaterialIcon,
type MaterialIconSetIconProps,
@@ -6,6 +7,7 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
import type { Packages } from "@scandic-hotels/trpc/types/packages"
import type { JSX } from "react"
@@ -83,3 +85,33 @@ export function calculateVat(priceInclVat: number, vat: number) {
vatAmount,
}
}
export function getHotelAlertsForBookingDates(
specialAlerts: Zod.infer<typeof specialAlertsSchema>,
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
})
}