Files
web/server/routers/hotels/schemas/hotel/specialAlerts.ts
Erik Tiekstra 413c197ca0 Merged in feat/SW-1495-hide-alerts-on-hotel-pages (pull request #1268)
feat(SW-1495): removed alerts on hotel pages when displayInBookingFlow is true

* feat(SW-1495): removed alerts on hotel pages when displayInBookingFlow is true


Approved-by: Fredrik Thorsson
Approved-by: Matilda Landström
2025-02-10 07:40:38 +00:00

39 lines
1.1 KiB
TypeScript

import { z } from "zod"
import { dt } from "@/lib/dt"
import { nullableStringValidator } from "@/utils/zod/stringValidator"
import { AlertTypeEnum } from "@/types/enums/alert"
const specialAlertSchema = z.object({
description: nullableStringValidator,
displayInBookingFlow: z.boolean().default(false),
endDate: nullableStringValidator,
startDate: nullableStringValidator,
title: nullableStringValidator,
type: nullableStringValidator,
})
export const specialAlertsSchema = z
.array(specialAlertSchema)
.transform((data) => {
const now = dt().utc().format("YYYY-MM-DD")
const filteredAlerts = data.filter((alert) => {
const shouldShowNow =
alert.startDate && alert.endDate
? alert.startDate <= now && alert.endDate >= now
: true
const hasText = alert.description || alert.title
return shouldShowNow && hasText
})
return filteredAlerts.map((alert, idx) => ({
heading: alert.title || null,
id: `alert-${alert.type}-${idx}`,
text: alert.description || null,
type: AlertTypeEnum.Info,
displayInBookingFlow: alert.displayInBookingFlow,
}))
})
.default([])