diff --git a/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx b/frontend/src/pages/organization/AuditLogsPage/components/LogsDateFilter.tsx index 71d418c9d..b9f9a1cd6 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,28 +200,44 @@ export const LogsDateFilter = ({ setFilter, filter, timezone, setTimezone }: Pro })} ))} -
- - field.onChange(`${val}${unitOfTime}`)} - max={60} - min={1} - /> - - - - + { + const durationVal = val.target.value + ? Number(val.target.value) + : undefined; + 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() })