From ec3aa40aae9529cbd736f25be1952913dcb6c5a0 Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Wed, 27 May 2026 22:01:10 -0300 Subject: [PATCH] chore(logs): delete deprecated AuditLogTab.tsx duplicate (B/F4) --- .../dashboard/logs/AuditLogTab.tsx | 379 ------------------ 1 file changed, 379 deletions(-) delete mode 100644 src/app/(dashboard)/dashboard/logs/AuditLogTab.tsx diff --git a/src/app/(dashboard)/dashboard/logs/AuditLogTab.tsx b/src/app/(dashboard)/dashboard/logs/AuditLogTab.tsx deleted file mode 100644 index 303b956e12..0000000000 --- a/src/app/(dashboard)/dashboard/logs/AuditLogTab.tsx +++ /dev/null @@ -1,379 +0,0 @@ -"use client"; - -/** - * Audit Log Tab — Embedded version of the audit-log page for the Logs dashboard. - * Fetches from /api/compliance/audit-log with filter support. - */ - -import { useState, useEffect, useCallback } from "react"; -import { useTranslations } from "next-intl"; - -interface AuditEntry { - id: number; - timestamp: string; - action: string; - actor: string; - target?: string | null; - details?: unknown; - metadata?: unknown; - ip_address?: string | null; - resourceType?: string | null; - status?: string | null; - requestId?: string | null; -} - -const PAGE_SIZE = 25; - -export default function AuditLogTab() { - const [entries, setEntries] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - const [actionFilter, setActionFilter] = useState(""); - const [actorFilter, setActorFilter] = useState(""); - const [offset, setOffset] = useState(0); - const [hasMore, setHasMore] = useState(false); - const [totalCount, setTotalCount] = useState(0); - const [selectedEntry, setSelectedEntry] = useState(null); - const t = useTranslations("logs"); - - const fetchEntries = useCallback(async () => { - setLoading(true); - setError(null); - try { - const params = new URLSearchParams(); - if (actionFilter) params.set("action", actionFilter); - if (actorFilter) params.set("actor", actorFilter); - params.set("limit", String(PAGE_SIZE + 1)); - params.set("offset", String(offset)); - - const res = await fetch(`/api/compliance/audit-log?${params.toString()}`); - if (!res.ok) throw new Error(t("failedFetchAuditLog")); - const data = (await res.json()) as AuditEntry[]; - const total = Number(res.headers.get("x-total-count") || "0"); - - setHasMore(data.length > PAGE_SIZE); - setEntries(data.slice(0, PAGE_SIZE)); - setTotalCount(Number.isFinite(total) ? total : 0); - } catch (err: any) { - setError(err.message || t("failedFetchAuditLog")); - } finally { - setLoading(false); - } - }, [actionFilter, actorFilter, offset, t]); - - useEffect(() => { - fetchEntries(); - }, [fetchEntries]); - - const handleSearch = () => { - if (offset === 0) { - fetchEntries(); - return; - } - setOffset(0); - }; - - const formatTimestamp = (ts: string) => { - try { - return new Date(ts).toLocaleString(); - } catch { - return ts; - } - }; - - const actionBadgeColor = (action: string) => { - if (action === "provider.warning") return "bg-amber-500/15 text-amber-300 border-amber-500/20"; - if (action.includes("delete") || action.includes("remove")) - return "bg-red-500/15 text-red-400 border-red-500/20"; - if (action.includes("create") || action.includes("add")) - return "bg-green-500/15 text-green-400 border-green-500/20"; - if (action.includes("update") || action.includes("change")) - return "bg-blue-500/15 text-blue-400 border-blue-500/20"; - if (action.includes("login") || action.includes("auth")) - return "bg-purple-500/15 text-purple-400 border-purple-500/20"; - return "bg-gray-500/15 text-gray-400 border-gray-500/20"; - }; - - const statusBadgeColor = (status?: string | null) => { - if (!status) return "bg-gray-500/15 text-gray-400 border-gray-500/20"; - if (status === "success") return "bg-green-500/15 text-green-400 border-green-500/20"; - if (status === "warning" || status === "blocked") - return "bg-amber-500/15 text-amber-300 border-amber-500/20"; - if (status === "error" || status === "failed") - return "bg-red-500/15 text-red-400 border-red-500/20"; - return "bg-blue-500/15 text-blue-400 border-blue-500/20"; - }; - - return ( -
-
-
-

{t("auditLog")}

-

{t("auditLogDesc")}

-

- {t("totalEntries", { count: totalCount })} -

-
- -
- -
- setActionFilter(e.target.value)} - onKeyDown={(e) => e.key === "Enter" && handleSearch()} - aria-label={t("filterByActionTypeAria")} - className="flex-1 min-w-[180px] px-3 py-2 rounded-lg text-sm bg-[var(--color-bg)] border border-[var(--color-border)] text-[var(--color-text-main)] placeholder:text-[var(--color-text-muted)] focus:outline-2 focus:outline-[var(--color-accent)]" - /> - setActorFilter(e.target.value)} - onKeyDown={(e) => e.key === "Enter" && handleSearch()} - aria-label={t("filterByActorAria")} - className="flex-1 min-w-[180px] px-3 py-2 rounded-lg text-sm bg-[var(--color-bg)] border border-[var(--color-border)] text-[var(--color-text-main)] placeholder:text-[var(--color-text-muted)] focus:outline-2 focus:outline-[var(--color-accent)]" - /> - -
- - {/* Error */} - {error && ( -
- {error} -
- )} - -
- - - - - - - - - - - - - - - - {entries.length === 0 && !loading ? ( - - - - ) : ( - entries.map((entry) => ( - - - - - - - - - - - - )) - )} - -
- {t("timestamp")} - - {t("action")} - - {t("status")} - - {t("actor")} - - {t("target")} - - {t("resourceType")} - - {t("ipAddress")} - - {t("requestId")} - - {t("details")} -
- {t("noEntries")} -
- {formatTimestamp(entry.timestamp)} - - - - {entry.action === "provider.warning" && ( - warning - )} - {entry.action} - - - - - {entry.status || t("notAvailable")} - - {entry.actor} - {entry.target || t("notAvailable")} - - {entry.resourceType || t("notAvailable")} - - {entry.ip_address || t("notAvailable")} - - {entry.requestId || t("notAvailable")} - - -
-
- -
-

- {t("showing", { count: entries.length, offset })} -

-
- - -
-
- - {selectedEntry && ( -
-
-
-
-

- {selectedEntry.action} -

-

- {t("auditModalSubtitle", { - actor: selectedEntry.actor || t("notAvailable"), - target: selectedEntry.target || t("notAvailable"), - })} -

-
- -
- -
- {selectedEntry.action === "provider.warning" && ( -
-
- warning -
-

{t("providerWarningTitle")}

-

{t("providerWarningDesc")}

-
-
-
- )} - -
-
-

- {t("eventMetadata")} -

-
-
-
{t("timestamp")}
-
- {formatTimestamp(selectedEntry.timestamp)} -
-
-
-
{t("status")}
-
- {selectedEntry.status || t("notAvailable")} -
-
-
-
{t("resourceType")}
-
- {selectedEntry.resourceType || t("notAvailable")} -
-
-
-
{t("requestId")}
-
- {selectedEntry.requestId || t("notAvailable")} -
-
-
-
{t("ipAddress")}
-
- {selectedEntry.ip_address || t("notAvailable")} -
-
-
-
- -
-

- {t("eventPayload")} -

-
-                    {JSON.stringify(selectedEntry.metadata || selectedEntry.details || {}, null, 2)}
-                  
-
-
-
-
-
- )} -
- ); -}