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,4 +1,3 @@
import { dt } from "@scandic-hotels/common/dt"
import { Divider } from "@scandic-hotels/design-system/Divider"
import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer"
import { Typography } from "@scandic-hotels/design-system/Typography"
@@ -12,6 +11,7 @@ import { getSingleDecimal } from "@/utils/numberFormatting"
import ReadMore from "../../ReadMore"
import TripAdvisorChip from "../../TripAdvisorChip"
import { getHotelAlertsForBookingDates } from "../../utils"
import HotelDescription from "./HotelDescription"
import styles from "./hotelInfoCard.module.css"
@@ -31,8 +31,11 @@ export default async function HotelInfoCard({
const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || [])
const fromDate = dt(booking.fromDate)
const toDate = dt(booking.toDate)
const specialAlerts = getHotelAlertsForBookingDates(
hotel.specialAlerts,
booking.fromDate,
booking.toDate
)
return (
<article className={styles.container}>
@@ -101,30 +104,7 @@ export default async function HotelInfoCard({
</div>
</div>
</section>
{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 (
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
<Alert