import { NavLink, ScrollArea, Divider, Text } from '@mantine/core'; import { useNavigate, useLocation } from 'react-router-dom'; import { IconDashboard, IconListDetails, IconReceipt, IconHome, IconFileInvoice, IconCash, IconReportAnalytics, IconChartSankey, IconShieldCheck, IconBuildingBank, IconUsers, IconCrown, IconCategory, IconChartAreaLine, IconClipboardCheck, IconSparkles, IconHeartRateMonitor, } from '@tabler/icons-react'; import { useAuthStore } from '../../stores/authStore'; const navSections = [ { items: [ { label: 'Dashboard', icon: IconDashboard, path: '/dashboard' }, ], }, { label: 'Financials', items: [ { label: 'Accounts', icon: IconListDetails, path: '/accounts', tourId: 'nav-accounts' }, { label: 'Cash Flow', icon: IconChartAreaLine, path: '/cash-flow' }, { label: 'Monthly Actuals', icon: IconClipboardCheck, path: '/monthly-actuals' }, { label: 'Budgets', icon: IconReportAnalytics, path: '/budgets/2026', tourId: 'nav-budgets' }, ], }, { label: 'Assessments', items: [ { label: 'Units / Homeowners', icon: IconHome, path: '/units' }, { label: 'Assessment Groups', icon: IconCategory, path: '/assessment-groups', tourId: 'nav-assessment-groups' }, ], }, { label: 'Transactions', items: [ { label: 'Transactions', icon: IconReceipt, path: '/transactions', tourId: 'nav-transactions' }, { label: 'Invoices', icon: IconFileInvoice, path: '/invoices' }, { label: 'Payments', icon: IconCash, path: '/payments' }, ], }, { label: 'Planning', items: [ { label: 'Projects', icon: IconShieldCheck, path: '/projects' }, { label: 'Capital Planning', icon: IconBuildingBank, path: '/capital-projects' }, { label: 'Investment Planning', icon: IconSparkles, path: '/investment-planning', tourId: 'nav-investment-planning' }, { label: 'Vendors', icon: IconUsers, path: '/vendors' }, ], }, { label: 'Reports', items: [ { label: 'Reports', icon: IconChartSankey, tourId: 'nav-reports', children: [ { label: 'Balance Sheet', path: '/reports/balance-sheet' }, { label: 'Income Statement', path: '/reports/income-statement' }, { label: 'Cash Flow', path: '/reports/cash-flow' }, { label: 'Budget vs Actual', path: '/reports/budget-vs-actual' }, { label: 'Aging Report', path: '/reports/aging' }, { label: 'Sankey Diagram', path: '/reports/sankey' }, { label: 'Year-End', path: '/reports/year-end' }, { label: 'Quarterly Financial', path: '/reports/quarterly' }, ], }, ], }, ]; interface SidebarProps { onNavigate?: () => void; } export function Sidebar({ onNavigate }: SidebarProps) { const navigate = useNavigate(); const location = useLocation(); const user = useAuthStore((s) => s.user); const currentOrg = useAuthStore((s) => s.currentOrg); const organizations = useAuthStore((s) => s.organizations); const isAdminOnly = location.pathname.startsWith('/admin') && !currentOrg; const go = (path: string) => { navigate(path); onNavigate?.(); }; // When on admin route with no org selected, show admin-only sidebar if (isAdminOnly && user?.isSuperadmin) { return ( Platform Administration } active={location.pathname === '/admin'} onClick={() => go('/admin')} color="red" /> {organizations && organizations.length > 0 && ( <> } onClick={() => go('/select-org')} variant="subtle" /> )} ); } return ( {navSections.map((section, sIdx) => (
{section.label && ( <> {sIdx > 0 && } 0 ? 4 : 0}> {section.label} )} {section.items.map((item: any) => item.children ? ( } defaultOpened={item.children.some((c: any) => location.pathname.startsWith(c.path), )} data-tour={item.tourId || undefined} > {item.children.map((child: any) => ( go(child.path)} /> ))} ) : ( } active={location.pathname === item.path} onClick={() => go(item.path!)} data-tour={item.tourId || undefined} /> ), )}
))} {user?.isSuperadmin && ( <> Platform Admin } active={location.pathname === '/admin'} onClick={() => go('/admin')} color="red" /> )}
); }