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 { z } from "zod"
|
||||||
|
|
||||||
|
import { dt } from "@/lib/dt"
|
||||||
|
|
||||||
|
import { AlertTypeEnum } from "@/types/enums/alert"
|
||||||
|
|
||||||
const specialAlertSchema = z.object({
|
const specialAlertSchema = z.object({
|
||||||
type: z.string(),
|
type: z.string(),
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
@@ -16,10 +18,14 @@ export const specialAlertsSchema = z
|
|||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
const now = dt().utc().format("YYYY-MM-DD")
|
const now = dt().utc().format("YYYY-MM-DD")
|
||||||
const filteredAlerts = data.filter((alert) => {
|
const filteredAlerts = data.filter((alert) => {
|
||||||
const shouldShowNow =
|
let shouldShowNow = true
|
||||||
alert.startDate && alert.endDate
|
|
||||||
? alert.startDate <= now && alert.endDate >= now
|
if (alert.startDate && alert.startDate > now) {
|
||||||
: true
|
shouldShowNow = false
|
||||||
|
}
|
||||||
|
if (alert.endDate && alert.endDate < now) {
|
||||||
|
shouldShowNow = false
|
||||||
|
}
|
||||||
const hasText = alert.description || alert.title
|
const hasText = alert.description || alert.title
|
||||||
return shouldShowNow && hasText
|
return shouldShowNow && hasText
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user