Admin-only Accounting tab + platform COA consolidation

Phase 1: gate the Accounting sidebar item and /dashboard/accounting route
behind isAdmin via a RequireAdmin guard; Financial Reports stay visible.

Phase 2: platform associations now read the Chart of Accounts from
accounting.accounts (single source) instead of public.chart_of_accounts.
Shared fetchChartOfAccounts() normalizes both sources; central COA hooks
and ChartOfAccountsDropdown route through it (reads only, no migration).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 21:21:48 -04:00
parent 64aad1d283
commit 8ac0edfbd9
7 changed files with 156 additions and 61 deletions
+23
View File
@@ -0,0 +1,23 @@
import { Navigate } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";
/**
* Route guard for admin-only areas (e.g. the Accounting platform).
* Shows a spinner while auth resolves, then redirects non-admins to the
* dashboard. Admin status respects "view as" (uses effective `isAdmin`).
*/
export function RequireAdmin({ children }: { children: React.ReactNode }) {
const { loading, isAdmin } = useAuth();
if (loading) {
return (
<div className="flex min-h-[40vh] items-center justify-center">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" />
</div>
);
}
if (!isAdmin) return <Navigate to="/dashboard" replace />;
return <>{children}</>;
}