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,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
|
||||
|
||||
Reference in New Issue
Block a user