From 10fc6285dd165ece583226ca6cea3c1e187a9744 Mon Sep 17 00:00:00 2001 From: kibin Date: Wed, 1 Apr 2026 07:54:59 +0000 Subject: [PATCH] feat(260): add date range, entity type, action type filters --- app/(app)/audit-log/page.tsx | 75 +++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/app/(app)/audit-log/page.tsx b/app/(app)/audit-log/page.tsx index 0316ce1..be8c265 100644 --- a/app/(app)/audit-log/page.tsx +++ b/app/(app)/audit-log/page.tsx @@ -11,13 +11,29 @@ import { formatDateTime } from "@/lib/utils"; import api from "@/lib/api"; import type { AuditLog, PaginatedResponse } from "@/types"; +const ENTITY_TYPES = ["", "CLIENT", "INVOICE", "PAYMENT", "TICKET", "PLAN", "AREA", "USER", "SUBSCRIPTION", "LEAD", "REMITTANCE", "JOURNAL_ENTRY"]; +const ACTION_TYPES = ["", "CREATE", "UPDATE", "DELETE", "LOGIN", "LOGOUT", "ACTIVATE", "DEACTIVATE", "VOID", "RESOLVE", "CLOSE"]; + export default function AuditLogPage() { const [page, setPage] = useState(1); + const [dateFrom, setDateFrom] = useState(""); + const [dateTo, setDateTo] = useState(""); + const [entityType, setEntityType] = useState(""); + const [actionType, setActionType] = useState(""); const { data, isLoading, refetch } = useQuery>({ - queryKey: ["audit-logs", page], + queryKey: ["audit-logs", page, dateFrom, dateTo, entityType, actionType], queryFn: async () => { - const res = await api.get>(`/api/v1/audit-logs?page=${page}&limit=50`); + const params = new URLSearchParams({ page: String(page), limit: "50" }); + if (dateFrom) params.set("dateFrom", new Date(dateFrom).toISOString()); + if (dateTo) { + const end = new Date(dateTo); + end.setHours(23, 59, 59, 999); + params.set("dateTo", end.toISOString()); + } + if (entityType) params.set("entityType", entityType); + if (actionType) params.set("action", actionType); + const res = await api.get>(`/api/v1/audit-logs?${params}`); return res.data; }, }); @@ -25,6 +41,16 @@ export default function AuditLogPage() { const logs = data?.data ?? []; const meta = data?.meta; + const clearFilters = () => { + setDateFrom(""); + setDateTo(""); + setEntityType(""); + setActionType(""); + setPage(1); + }; + + const hasFilters = dateFrom || dateTo || entityType || actionType; + return (
@@ -33,13 +59,52 @@ export default function AuditLogPage() {

Track all system activity

+ {/* Filters */} - Activity Log + +
+
+ + { setDateFrom(e.target.value); setPage(1); }} + className="border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40" /> +
+
+ + { setDateTo(e.target.value); setPage(1); }} + className="border rounded-lg px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 w-40" /> +
+
+ + +
+
+ + +
+ {hasFilters && ( + + )} +
+
+
+ + + Activity Log {meta ? `(${meta.total} entries)` : ""} @@ -61,7 +126,7 @@ export default function AuditLogPage() { )) ) : logs.length === 0 ? ( - + ) : ( logs.map((log) => (