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,6 +1,7 @@
|
|||||||
import { notFound } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
|
import { dt } from "@scandic-hotels/common/dt"
|
||||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -181,9 +182,17 @@ export default async function HotelPage({ hotelId }: HotelPageProps) {
|
|||||||
{specialAlerts.length ? (
|
{specialAlerts.length ? (
|
||||||
<div className={styles.alertsContainer}>
|
<div className={styles.alertsContainer}>
|
||||||
{specialAlerts
|
{specialAlerts
|
||||||
.filter(
|
.filter((alert) => {
|
||||||
(alert) => alert.name !== AlertName.HotelChildrenInBooking
|
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) => (
|
.map((alert) => (
|
||||||
<Alert
|
<Alert
|
||||||
key={alert.id}
|
key={alert.id}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import Alert from "@/components/TempDesignSystem/Alert"
|
|||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import BookingConfirmationProvider from "@/providers/BookingConfirmationProvider"
|
import BookingConfirmationProvider from "@/providers/BookingConfirmationProvider"
|
||||||
|
|
||||||
|
import { getHotelAlertsForBookingDates } from "../utils"
|
||||||
import Confirmation from "./Confirmation"
|
import Confirmation from "./Confirmation"
|
||||||
import Tracking from "./Tracking"
|
import Tracking from "./Tracking"
|
||||||
import { mapRoomState } from "./utils"
|
import { mapRoomState } from "./utils"
|
||||||
@@ -77,7 +78,11 @@ export default async function BookingConfirmation({
|
|||||||
<PaymentDetails />
|
<PaymentDetails />
|
||||||
<Divider color="Border/Divider/Subtle" />
|
<Divider color="Border/Divider/Subtle" />
|
||||||
<HotelDetails hotel={hotel} />
|
<HotelDetails hotel={hotel} />
|
||||||
{hotel.specialAlerts.map((alert) => (
|
{getHotelAlertsForBookingDates(
|
||||||
|
hotel.specialAlerts,
|
||||||
|
booking.checkInDate,
|
||||||
|
booking.checkOutDate
|
||||||
|
).map((alert) => (
|
||||||
<div key={alert.id}>
|
<div key={alert.id}>
|
||||||
<Alert
|
<Alert
|
||||||
type={alert.type}
|
type={alert.type}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ import { getIntl } from "@/i18n"
|
|||||||
import MyStayProvider from "@/providers/MyStay"
|
import MyStayProvider from "@/providers/MyStay"
|
||||||
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
import { isLoggedInUser } from "@/utils/isLoggedInUser"
|
||||||
|
|
||||||
|
import { getHotelAlertsForBookingDates } from "../utils"
|
||||||
|
|
||||||
import styles from "./index.module.css"
|
import styles from "./index.module.css"
|
||||||
|
|
||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
@@ -199,6 +201,12 @@ export default async function MyStay(props: {
|
|||||||
} satisfies SafeUser)
|
} satisfies SafeUser)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
|
hotel.specialAlerts = getHotelAlertsForBookingDates(
|
||||||
|
hotel.specialAlerts,
|
||||||
|
fromDate,
|
||||||
|
toDate
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MyStayProvider
|
<MyStayProvider
|
||||||
bookingConfirmation={maskedBookingConfirmation}
|
bookingConfirmation={maskedBookingConfirmation}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { dt } from "@scandic-hotels/common/dt"
|
|
||||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||||
import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer"
|
import SkeletonShimmer from "@scandic-hotels/design-system/SkeletonShimmer"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
@@ -12,6 +11,7 @@ import { getSingleDecimal } from "@/utils/numberFormatting"
|
|||||||
|
|
||||||
import ReadMore from "../../ReadMore"
|
import ReadMore from "../../ReadMore"
|
||||||
import TripAdvisorChip from "../../TripAdvisorChip"
|
import TripAdvisorChip from "../../TripAdvisorChip"
|
||||||
|
import { getHotelAlertsForBookingDates } from "../../utils"
|
||||||
import HotelDescription from "./HotelDescription"
|
import HotelDescription from "./HotelDescription"
|
||||||
|
|
||||||
import styles from "./hotelInfoCard.module.css"
|
import styles from "./hotelInfoCard.module.css"
|
||||||
@@ -31,8 +31,11 @@ export default async function HotelInfoCard({
|
|||||||
|
|
||||||
const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || [])
|
const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || [])
|
||||||
|
|
||||||
const fromDate = dt(booking.fromDate)
|
const specialAlerts = getHotelAlertsForBookingDates(
|
||||||
const toDate = dt(booking.toDate)
|
hotel.specialAlerts,
|
||||||
|
booking.fromDate,
|
||||||
|
booking.toDate
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className={styles.container}>
|
<article className={styles.container}>
|
||||||
@@ -101,30 +104,7 @@ export default async function HotelInfoCard({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{hotel.specialAlerts.map((alert) => {
|
{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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
|
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
|
||||||
<Alert
|
<Alert
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { dt } from "@scandic-hotels/common/dt"
|
||||||
import {
|
import {
|
||||||
MaterialIcon,
|
MaterialIcon,
|
||||||
type MaterialIconSetIconProps,
|
type MaterialIconSetIconProps,
|
||||||
@@ -6,6 +7,7 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
|
|||||||
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
|
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
|
||||||
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
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 { Packages } from "@scandic-hotels/trpc/types/packages"
|
||||||
import type { JSX } from "react"
|
import type { JSX } from "react"
|
||||||
|
|
||||||
@@ -83,3 +85,33 @@ export function calculateVat(priceInclVat: number, vat: number) {
|
|||||||
vatAmount,
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ export const specialAlertsSchema = z
|
|||||||
if (!hasDates) {
|
if (!hasDates) {
|
||||||
return hasText
|
return hasText
|
||||||
}
|
}
|
||||||
const shouldShowNow = alert.startDate <= now && alert.endDate >= now
|
const isAlertExpired = alert.endDate < now
|
||||||
return shouldShowNow && hasText
|
return !isAlertExpired && hasText
|
||||||
})
|
})
|
||||||
return filteredAlerts.map((alert, idx) => ({
|
return filteredAlerts.map((alert, idx) => ({
|
||||||
heading: alert.title || null,
|
heading: alert.title || null,
|
||||||
|
|||||||
Reference in New Issue
Block a user