34 lines
1006 B
TypeScript
34 lines
1006 B
TypeScript
import { dt } from "@/lib/dt"
|
|
import { AlertTypeEnum } from "@/types/enums/alert"
|
|
import { z } from "zod"
|
|
|
|
const specialAlertSchema = z.object({
|
|
type: z.string(),
|
|
title: z.string().optional(),
|
|
description: z.string().optional(),
|
|
displayInBookingFlow: z.boolean(),
|
|
startDate: z.string().optional(),
|
|
endDate: z.string().optional(),
|
|
})
|
|
|
|
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) => ({
|
|
id: `alert-${alert.type}-${idx}`,
|
|
type: AlertTypeEnum.Info,
|
|
heading: alert.title || null,
|
|
text: alert.description || null,
|
|
}))
|
|
})
|
|
.default([])
|