"use client"; import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { useTranslations } from "next-intl"; import { DataTable } from "@/components/admin/data-table"; import { Badge } from "@/components/ui/badge"; import { HistoryRestore } from "@/features/history/history-restore"; import { formatAuditValue, readAuditChanges } from "@/lib/services/audit-diff"; import type { DataTableColumn, PaginatedResult } from "@/types/common"; import { AuditFilters } from "./audit-filters"; interface AuditRow { operationId?: string | null; id: number; username: string; action: string; target: string; targetId: number | null; diff: string | null; before: string | null; after: string | null; createdAt: string; } function DiffCell({ row }: { row: AuditRow }) { const t = useTranslations("pages.admin.logs"); const { changes, invalid } = readAuditChanges( row.diff, row.before, row.after, ); if (invalid) return ( {t("audit.invalidDetails")} ); if (!changes.length) return {t("emptyValue")}; return ( {t("audit.changesCount", { count: changes.length })} {changes.map((change) => ( {change.key} {t("audit.beforeValue")} {formatAuditValue(change.from)} {t("audit.afterValue")} {formatAuditValue(change.to)} ))} ); } interface AuditTableProps { data: PaginatedResult; } export function AuditTable({ data }: AuditTableProps) { const params = useSearchParams(); const t = useTranslations("pages.admin.logs"); const columns: DataTableColumn[] = [ { key: "id", label: t("colId") }, { key: "username", label: t("colUser") }, { key: "action", label: t("colAction"), render: (value) => { const v = String(value); let variant: "default" | "secondary" | "destructive" = "secondary"; if (v.includes("create") || v.includes("add")) variant = "default"; if (v.includes("delete") || v.includes("remove") || v.includes("ban")) variant = "destructive"; return {v}; }, }, { key: "target", label: t("colTarget") }, { key: "targetId", label: t("audit.colTargetId"), render: (value) => ( {value != null ? String(value) : t("emptyValue")} ), }, { key: "diff", label: t("audit.colDetails"), render: (_value, row) => ( {row.operationId && ( {t("audit.operation")}: {row.operationId} )} {["history_update", "history_restore"].includes(row.action) && ( )} ), }, { key: "createdAt", label: t("audit.colDate"), render: (value) => ( {String(value) || t("audit.notAvailable")} ), }, ]; return ( {t("audit.exportHint")} ); }
{change.key}
{formatAuditValue(change.from)}
{formatAuditValue(change.to)}
{t("audit.exportHint")}