fix(BOOK-599): Filtering on correct values for hotel pages now and added comments
Approved-by: Matilda Landström
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||
import { dt } from "@scandic-hotels/common/dt"
|
||||
import { nullableStringValidator } from "@scandic-hotels/common/utils/zod/stringValidator"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
@@ -16,19 +15,13 @@ const specialAlertSchema = z.object({
|
||||
export const specialAlertsSchema = z
|
||||
.array(specialAlertSchema)
|
||||
.nullish()
|
||||
.transform((arr) => (arr ? arr.filter(Boolean) : []))
|
||||
.transform((data) => {
|
||||
const now = dt().utc().format("YYYY-MM-DD")
|
||||
const filteredAlerts = data.filter((alert) => {
|
||||
const hasText = alert.description || alert.title
|
||||
const hasDates = alert.startDate && alert.endDate
|
||||
if (!hasDates) {
|
||||
return hasText
|
||||
}
|
||||
const isAlertExpired = alert.endDate < now
|
||||
return !isAlertExpired && hasText
|
||||
})
|
||||
return filteredAlerts.map((alert, idx) => ({
|
||||
// Filter out alerts with no title and no description since they won't have any visible content
|
||||
// We're filtering on dates on the hotel page itself
|
||||
.transform((arr) =>
|
||||
arr ? arr.filter((alert) => alert?.description || alert?.title) : []
|
||||
)
|
||||
.transform((alerts) =>
|
||||
alerts.map((alert, idx) => ({
|
||||
heading: alert.title || null,
|
||||
id: `alert-${alert.type}-${idx}`,
|
||||
name: alert.type,
|
||||
@@ -38,4 +31,4 @@ export const specialAlertsSchema = z
|
||||
endDate: alert.endDate,
|
||||
startDate: alert.startDate,
|
||||
}))
|
||||
})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user