import { useEffect, useState } from 'react'; import { assetsUrl } from './lib/api'; import Dashboard from './components/Dashboard'; import ReportView from './components/ReportView'; import WidgetConfigurator from './components/WidgetConfigurator'; import StatementGenerator from './components/StatementGenerator'; import Settings from './components/Settings'; type View = '' | 'report' | 'widget' | 'statement' | 'settings'; function parseHash(): View { const valid: View[] = ['', 'report', 'widget', 'statement', 'settings']; const raw = window.location.hash.replace('#/', '').replace('#', ''); if (raw && valid.includes(raw as View)) return raw as View; // No hash set — use the view PHP passed when navigating from the WP sidebar. const initial = (window as any).accessmateConfig?.initialView as string | undefined; return initial && valid.includes(initial as View) ? (initial as View) : ''; } export default function App() { const [view, setView] = useState(parseHash); useEffect(() => { const onHashChange = () => setView(parseHash()); window.addEventListener('hashchange', onHashChange); return () => window.removeEventListener('hashchange', onHashChange); }, []); const navigate = (v: View) => { window.location.hash = v ? `/${v}` : '/'; setView(v); }; return (
{/* Sidebar nav */} {/* Main content */}
{view === '' && } {view === 'report' && } {view === 'widget' && } {view === 'statement' && } {view === 'settings' && }
); } function NavItem({ active, onClick, children, }: { active: boolean; onClick: () => void; children: React.ReactNode; }) { return (
  • ); }