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:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user