fix(SW-1211): Fixed issue where special alerts are showing when either startDate or endDate is missing
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { dt } from "@/lib/dt"
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
import { z } from "zod"
|
||||
|
||||
import { dt } from "@/lib/dt"
|
||||
|
||||
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
|
||||
const specialAlertSchema = z.object({
|
||||
type: z.string(),
|
||||
title: z.string().optional(),
|
||||
@@ -16,10 +18,14 @@ export const specialAlertsSchema = z
|
||||
.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
|
||||
let shouldShowNow = true
|
||||
|
||||
if (alert.startDate && alert.startDate > now) {
|
||||
shouldShowNow = false
|
||||
}
|
||||
if (alert.endDate && alert.endDate < now) {
|
||||
shouldShowNow = false
|
||||
}
|
||||
const hasText = alert.description || alert.title
|
||||
return shouldShowNow && hasText
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user