feat: only show alerts when booking dates are affected
This commit is contained in:
committed by
Simon.Emanuelsson
parent
64b3bd71dc
commit
145a6d2365
@@ -1,6 +1,8 @@
|
|||||||
import { Divider } from "@scandic-hotels/design-system/Divider"
|
import { Divider } from "@scandic-hotels/design-system/Divider"
|
||||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||||
|
|
||||||
|
import { dt } from "@/lib/dt"
|
||||||
|
|
||||||
import { FacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
import { FacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
||||||
import ImageGallery from "@/components/ImageGallery"
|
import ImageGallery from "@/components/ImageGallery"
|
||||||
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
import SkeletonShimmer from "@/components/SkeletonShimmer"
|
||||||
@@ -18,7 +20,10 @@ import styles from "./hotelInfoCard.module.css"
|
|||||||
import type { HotelInfoCardProps } from "@/types/components/hotelReservation/selectRate/hotelInfoCard"
|
import type { HotelInfoCardProps } from "@/types/components/hotelReservation/selectRate/hotelInfoCard"
|
||||||
import { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
|
import { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
|
||||||
|
|
||||||
export default async function HotelInfoCard({ hotel }: HotelInfoCardProps) {
|
export default async function HotelInfoCard({
|
||||||
|
booking,
|
||||||
|
hotel,
|
||||||
|
}: HotelInfoCardProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const sortedFacilities = hotel.detailedFacilities
|
const sortedFacilities = hotel.detailedFacilities
|
||||||
@@ -27,6 +32,9 @@ export default async function HotelInfoCard({ hotel }: HotelInfoCardProps) {
|
|||||||
|
|
||||||
const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || [])
|
const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || [])
|
||||||
|
|
||||||
|
const fromDate = dt(booking.fromDate)
|
||||||
|
const toDate = dt(booking.toDate)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className={styles.container}>
|
<article className={styles.container}>
|
||||||
<section className={styles.wrapper}>
|
<section className={styles.wrapper}>
|
||||||
@@ -94,16 +102,41 @@ export default async function HotelInfoCard({ hotel }: HotelInfoCardProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{hotel.specialAlerts.map((alert) => (
|
{hotel.specialAlerts.map((alert) => {
|
||||||
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
|
if (alert.endDate && alert.startDate) {
|
||||||
<Alert
|
const endDate = dt(alert.endDate)
|
||||||
key={alert.id}
|
const startDate = dt(alert.startDate)
|
||||||
type={alert.type}
|
|
||||||
heading={alert.heading}
|
const fromDateIsBetweenAlertDates = dt(fromDate).isBetween(
|
||||||
text={alert.text}
|
startDate,
|
||||||
/>
|
endDate,
|
||||||
</div>
|
"date",
|
||||||
))}
|
"[]"
|
||||||
|
)
|
||||||
|
const toDateIsBetweenAlertDates = dt(toDate).isBetween(
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
"date",
|
||||||
|
"[]"
|
||||||
|
)
|
||||||
|
const bookingSpanIsBetweenAlertDates =
|
||||||
|
fromDateIsBetweenAlertDates && toDateIsBetweenAlertDates
|
||||||
|
if (!bookingSpanIsBetweenAlertDates) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.hotelAlert} key={`wrapper_${alert.id}`}>
|
||||||
|
<Alert
|
||||||
|
key={alert.id}
|
||||||
|
type={alert.type}
|
||||||
|
heading={alert.heading}
|
||||||
|
text={alert.text}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export default async function SelectRatePage({
|
|||||||
if (!searchDetails?.hotel) {
|
if (!searchDetails?.hotel) {
|
||||||
return notFound()
|
return notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const { adultsInRoom, childrenInRoom, hotel, noOfRooms, bookingCode } =
|
const { adultsInRoom, childrenInRoom, hotel, noOfRooms, bookingCode } =
|
||||||
searchDetails
|
searchDetails
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ export default async function SelectRatePage({
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HotelInfoCard hotel={hotelData.hotel} />
|
<HotelInfoCard booking={booking} hotel={hotelData.hotel} />
|
||||||
|
|
||||||
{isInValidFNF ? (
|
{isInValidFNF ? (
|
||||||
<FnFNotAllowedAlert />
|
<FnFNotAllowedAlert />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import nb from "dayjs/locale/nb"
|
|||||||
import advancedFormat from "dayjs/plugin/advancedFormat"
|
import advancedFormat from "dayjs/plugin/advancedFormat"
|
||||||
import customParseFormat from "dayjs/plugin/customParseFormat"
|
import customParseFormat from "dayjs/plugin/customParseFormat"
|
||||||
import duration from "dayjs/plugin/duration"
|
import duration from "dayjs/plugin/duration"
|
||||||
|
import isBetween from "dayjs/plugin/isBetween"
|
||||||
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
|
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"
|
||||||
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
|
import isSameOrBefore from "dayjs/plugin/isSameOrBefore"
|
||||||
import isToday from "dayjs/plugin/isToday"
|
import isToday from "dayjs/plugin/isToday"
|
||||||
@@ -35,5 +36,6 @@ d.extend(isSameOrAfter)
|
|||||||
d.extend(isSameOrBefore)
|
d.extend(isSameOrBefore)
|
||||||
d.extend(duration)
|
d.extend(duration)
|
||||||
d.extend(customParseFormat)
|
d.extend(customParseFormat)
|
||||||
|
d.extend(isBetween)
|
||||||
|
|
||||||
export const dt = d
|
export const dt = d
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ export const specialAlertsSchema = z
|
|||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
const now = dt().utc().format("YYYY-MM-DD")
|
const now = dt().utc().format("YYYY-MM-DD")
|
||||||
const filteredAlerts = data.filter((alert) => {
|
const filteredAlerts = data.filter((alert) => {
|
||||||
const shouldShowNow =
|
|
||||||
alert.startDate && alert.endDate
|
|
||||||
? alert.startDate <= now && alert.endDate >= now
|
|
||||||
: true
|
|
||||||
const hasText = alert.description || alert.title
|
const hasText = alert.description || alert.title
|
||||||
|
const hasDates = alert.startDate && alert.endDate
|
||||||
|
if (!hasDates) {
|
||||||
|
return hasText
|
||||||
|
}
|
||||||
|
const shouldShowNow = alert.startDate <= now && alert.endDate >= now
|
||||||
return shouldShowNow && hasText
|
return shouldShowNow && hasText
|
||||||
})
|
})
|
||||||
return filteredAlerts.map((alert, idx) => ({
|
return filteredAlerts.map((alert, idx) => ({
|
||||||
@@ -36,5 +37,7 @@ export const specialAlertsSchema = z
|
|||||||
text: alert.description || null,
|
text: alert.description || null,
|
||||||
type: AlertTypeEnum.Info,
|
type: AlertTypeEnum.Info,
|
||||||
displayInBookingFlow: alert.displayInBookingFlow,
|
displayInBookingFlow: alert.displayInBookingFlow,
|
||||||
|
endDate: alert.endDate,
|
||||||
|
startDate: alert.startDate,
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import type { Hotel } from "@/types/hotel"
|
import type { Hotel } from "@/types/hotel"
|
||||||
|
import type { SelectRateBooking } from "./selectRate"
|
||||||
|
|
||||||
export interface HotelInfoCardProps {
|
export interface HotelInfoCardProps {
|
||||||
|
booking: SelectRateBooking
|
||||||
hotel: Hotel
|
hotel: Hotel
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user