"use client"; import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { accountingApi } from "@/lib/accounting-api"; import { useTenantId } from "@/hooks/useTenantId"; import { PageHeader, DataTable, EmptyState, LoadingState, ErrorState, JalaliDateText, Tabs, Badge, } from "@/components/ds"; type TabId = "compliance" | "posting"; export default function AuditPage() { const { tenantId } = useTenantId(); const [tab, setTab] = useState("compliance"); const complianceQ = useQuery({ queryKey: ["accounting", tenantId, "compliance-audit"], queryFn: () => accountingApi.compliance.listAudit(tenantId!), enabled: !!tenantId && tab === "compliance", }); const postingQ = useQuery({ queryKey: ["accounting", tenantId, "posting-audit-logs"], queryFn: () => accountingApi.vouchers.auditLogs(tenantId!), enabled: !!tenantId && tab === "posting", }); const activeQ = tab === "compliance" ? complianceQ : postingQ; if (!tenantId) return ; if (activeQ.isLoading) return ; if (activeQ.error) { return activeQ.refetch()} />; } return (
setTab(id as TabId)} items={[ { id: "compliance", label: "رکوردهای انطباق" }, { id: "posting", label: "لاگ ثبت اسناد" }, ]} /> {tab === "compliance" && ( , }, { key: "action", header: "عملیات" }, { key: "resource_type", header: "منبع" }, { key: "actor_user_id", header: "عامل", render: (r) => ( {String(r.actor_user_id ?? "—")} ), }, ]} rows={(complianceQ.data ?? []) as unknown as Record[]} empty={ } /> )} {tab === "posting" && ( , }, { key: "operation", header: "عملیات", render: (r) => {String(r.operation)}, }, { key: "voucher_number", header: "شماره سند", render: (r) => String(r.voucher_number ?? "—") }, { key: "resource_type", header: "نوع منبع" }, { key: "resource_id", header: "شناسه", render: (r) => ( {String(r.resource_id ?? "—")} ), }, { key: "actor_user_id", header: "عامل", render: (r) => ( {String(r.actor_user_id ?? "—")} ), }, ]} rows={(postingQ.data ?? []) as unknown as Record[]} empty={ } /> )}
); }