fix(BOOK-599): Filtering on correct values for hotel pages now and added comments
Approved-by: Matilda Landström
This commit is contained in:
@@ -149,6 +149,13 @@ export default async function HotelPage({
|
|||||||
|
|
||||||
const isThemed = hotelTheme !== DEFAULT_THEME
|
const isThemed = hotelTheme !== DEFAULT_THEME
|
||||||
const galleryImages = mapApiImagesToGalleryImages(images ?? [])
|
const galleryImages = mapApiImagesToGalleryImages(images ?? [])
|
||||||
|
const filteredAlerts = specialAlerts.filter(({ endDate, name }) => {
|
||||||
|
// Hotel alerts should only be shown if they:
|
||||||
|
// - Have no end date or Have an end date in the future (including today)
|
||||||
|
// - Are not of type 'HotelChildrenInBooking'
|
||||||
|
const shouldShowNow = !endDate || dt().isSameOrBefore(dt(endDate), "day")
|
||||||
|
return name !== AlertName.HotelChildrenInBooking && shouldShowNow
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.pageContainer}>
|
<div className={styles.pageContainer}>
|
||||||
@@ -194,28 +201,16 @@ export default async function HotelPage({
|
|||||||
|
|
||||||
<AmenitiesList detailedFacilities={detailedFacilities} />
|
<AmenitiesList detailedFacilities={detailedFacilities} />
|
||||||
</div>
|
</div>
|
||||||
{specialAlerts.length ? (
|
{filteredAlerts.length ? (
|
||||||
<div className={styles.alertsContainer}>
|
<div className={styles.alertsContainer}>
|
||||||
{specialAlerts
|
{filteredAlerts.map((alert) => (
|
||||||
.filter((alert) => {
|
<Alert
|
||||||
const now = dt().utc().format("YYYY-MM-DD")
|
key={alert.id}
|
||||||
const shouldShowNow =
|
type={alert.type}
|
||||||
alert.startDate && alert.endDate
|
heading={alert.heading}
|
||||||
? alert.startDate <= now && alert.endDate >= now
|
text={alert.text}
|
||||||
: true
|
/>
|
||||||
return (
|
))}
|
||||||
alert.name !== AlertName.HotelChildrenInBooking &&
|
|
||||||
shouldShowNow
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.map((alert) => (
|
|
||||||
<Alert
|
|
||||||
key={alert.id}
|
|
||||||
type={alert.type}
|
|
||||||
heading={alert.heading}
|
|
||||||
text={alert.text}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||||
import { dt } from "@scandic-hotels/common/dt"
|
|
||||||
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
||||||
|
|
||||||
const specialAlertSchema = z.object({
|
const specialAlertSchema = z.object({
|
||||||
@@ -16,19 +15,13 @@ const specialAlertSchema = z.object({
|
|||||||
export const specialAlertsSchema = z
|
export const specialAlertsSchema = z
|
||||||
.array(specialAlertSchema)
|
.array(specialAlertSchema)
|
||||||
.nullish()
|
.nullish()
|
||||||
.transform((arr) => (arr ? arr.filter(Boolean) : []))
|
// Filter out alerts with no title and no description since they won't have any visible content
|
||||||
.transform((data) => {
|
// We're filtering on dates on the hotel page itself
|
||||||
const now = dt().utc().format("YYYY-MM-DD")
|
.transform((arr) =>
|
||||||
const filteredAlerts = data.filter((alert) => {
|
arr ? arr.filter((alert) => alert?.description || alert?.title) : []
|
||||||
const hasText = alert.description || alert.title
|
)
|
||||||
const hasDates = alert.startDate && alert.endDate
|
.transform((alerts) =>
|
||||||
if (!hasDates) {
|
alerts.map((alert, idx) => ({
|
||||||
return hasText
|
|
||||||
}
|
|
||||||
const isAlertExpired = alert.endDate < now
|
|
||||||
return !isAlertExpired && hasText
|
|
||||||
})
|
|
||||||
return filteredAlerts.map((alert, idx) => ({
|
|
||||||
heading: alert.title || null,
|
heading: alert.title || null,
|
||||||
id: `alert-${alert.type}-${idx}`,
|
id: `alert-${alert.type}-${idx}`,
|
||||||
name: alert.type,
|
name: alert.type,
|
||||||
@@ -38,4 +31,4 @@ export const specialAlertsSchema = z
|
|||||||
endDate: alert.endDate,
|
endDate: alert.endDate,
|
||||||
startDate: alert.startDate,
|
startDate: alert.startDate,
|
||||||
}))
|
}))
|
||||||
})
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user