"use client"; import React, { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import SidebarLayout from "@/components/SidebarLayout"; import { fetchApi, parseDateTime } from "@/app/utils/api"; import { History, Search, RefreshCw, ChevronLeft, ChevronRight, ShieldAlert, Activity, Key, UserPlus, Sliders, Laptop } from "lucide-react"; export default function AuditLogsPage() { const [page, setPage] = useState(0); const limit = 20; const [search, setSearch] = useState(""); const { data: logs, isLoading, isPlaceholderData, refetch } = useQuery({ queryKey: ["audit-logs", page], queryFn: () => fetchApi(`/audit/?skip=${page * limit}&limit=${limit}`), placeholderData: (prev) => prev }); const filteredLogs = logs?.filter((log: any) => { if (!search) return true; const term = search.toLowerCase(); const actionMatch = log.action?.toLowerCase().includes(term); const userMatch = log.user?.email?.toLowerCase().includes(term); const detailsMatch = log.details?.toLowerCase().includes(term); return actionMatch || userMatch || detailsMatch; }); // Helper to map log actions to modern icons const getActionIcon = (action: string) => { const act = action.toLowerCase(); if (act.includes("login") || act.includes("auth")) return ; if (act.includes("create") || act.includes("enroll")) return ; if (act.includes("delete")) return ; if (act.includes("setting") || act.includes("update")) return ; return ; }; return (
{/* Header */}

System Audit Logs

Track admin dashboard actions, user activities, and kiosk alerts.

{/* Filter Bar */}
setSearch(e.target.value)} className="input-field h-9.5 pl-10 text-[12.5px] bg-white border-zinc-200 focus:border-zinc-800 text-zinc-900 rounded-xl transition-all w-full shadow-sm" />
{/* Audit Log Table */}
{isLoading ? ( Array.from({ length: 8 }).map((_, i) => ( {Array.from({ length: 5 }).map((_, j) => ( ))} )) ) : !filteredLogs || filteredLogs.length === 0 ? ( ) : ( filteredLogs.map((log: any) => ( )) )}
Timestamp Action Actor Details IP Address
No audit logs found.
{log.timestamp ? parseDateTime(log.timestamp)?.toLocaleString() : "—"}
{getActionIcon(log.action)}
{log.action}
{log.user?.email || System / Anonymous} {log.details} {log.ip_address || "Local"}
{/* Pagination */}
Page {page + 1}
); }