From 504a8c1d01971b42d5a2347133e37f0e315f417a Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Tue, 7 Oct 2025 00:53:51 +0530 Subject: [PATCH 1/3] fix: Audit log custom date picker --- .../organization/AuditLogsPage/components/LogsDateFilter.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx index 71d418c9d..5fa38cdce 100644 --- a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx +++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx @@ -205,7 +205,10 @@ export const LogsDateFilter = ({ setFilter, filter, timezone, setTimezone }: Pro field.onChange(`${val}${unitOfTime}`)} + onChange={(val) => { + const durationVal = val.target.value; + field.onChange(`${durationVal}${unitOfTime}`); + }} max={60} min={1} /> From 0ca583aa87b61d77c0f49bc86d0070b434aaa0c9 Mon Sep 17 00:00:00 2001 From: x032205 Date: Tue, 7 Oct 2025 13:39:47 -0400 Subject: [PATCH 2/3] add input validation & allow blank input values --- .../components/LogsDateFilter.tsx | 61 +++++++++++-------- .../AuditLogsPage/components/types.tsx | 14 ++++- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx index 5fa38cdce..d791b64cf 100644 --- a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx +++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx @@ -174,7 +174,7 @@ export const LogsDateFilter = ({ setFilter, filter, timezone, setTimezone }: Pro { + render={({ field, fieldState: { error } }) => { const duration = field.value?.substring(0, field.value.length - 1); const unitOfTime = field.value?.at(-1); return ( @@ -200,31 +200,42 @@ export const LogsDateFilter = ({ setFilter, filter, timezone, setTimezone }: Pro })} ))} -
- - { - const durationVal = val.target.value; - field.onChange(`${durationVal}${unitOfTime}`); - }} - max={60} - min={1} - /> - - - - + { + const durationVal = val.target.value; + field.onChange(`${durationVal}${unitOfTime}`); + }} + max={60} + min={1} + /> + + + + +
+ {error && ( + + {error.message} + + )} ); diff --git a/frontend/src/pages/organization/AuditLogsPage/components/types.tsx b/frontend/src/pages/organization/AuditLogsPage/components/types.tsx index b1338be24..ee51b0eaf 100644 --- a/frontend/src/pages/organization/AuditLogsPage/components/types.tsx +++ b/frontend/src/pages/organization/AuditLogsPage/components/types.tsx @@ -1,3 +1,4 @@ +import ms from "ms"; import { z } from "zod"; import { ActorType, EventType, UserAgentType } from "@app/hooks/api/auditLogs/enums"; @@ -27,7 +28,18 @@ export const auditLogFilterFormSchema = z.object({ export const auditLogDateFilterFormSchema = z .object({ type: z.nativeEnum(AuditLogDateFilterType), - relativeModeValue: z.string().optional(), + relativeModeValue: z + .string() + .refine( + (val) => { + const parsedMs = ms(val); + return typeof parsedMs === "number" && parsedMs > 0; + }, + { + message: "Invalid duration format. Must be a positive duration." + } + ) + .optional(), startDate: z.date(), endDate: z.date() }) From ba49e494882656d2041aac3fbdc7e7d16dc94a27 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Wed, 8 Oct 2025 00:38:53 +0530 Subject: [PATCH 3/3] fix: handle undefined duration value in LogsDateFilter component --- .../organization/AuditLogsPage/components/LogsDateFilter.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx index d791b64cf..b9f9a1cd6 100644 --- a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx +++ b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx @@ -211,7 +211,9 @@ export const LogsDateFilter = ({ setFilter, filter, timezone, setTimezone }: Pro type="number" value={duration} onChange={(val) => { - const durationVal = val.target.value; + const durationVal = val.target.value + ? Number(val.target.value) + : undefined; field.onChange(`${durationVal}${unitOfTime}`); }} max={60}