import { Title, Text, SimpleGrid, Card, Group, ThemeIcon, Stack, Table, Badge, Loader, Center, } from '@mantine/core'; import { IconCash, IconFileInvoice, IconShieldCheck, IconAlertTriangle, } from '@tabler/icons-react'; import { useQuery } from '@tanstack/react-query'; import { useAuthStore } from '../../stores/authStore'; import api from '../../services/api'; interface DashboardData { total_cash: string; total_receivables: string; reserve_fund_balance: string; delinquent_units: number; recent_transactions: { id: string; entry_date: string; description: string; entry_type: string; amount: string; }[]; } export function DashboardPage() { const currentOrg = useAuthStore((s) => s.currentOrg); const { data, isLoading } = useQuery({ queryKey: ['dashboard'], queryFn: async () => { const { data } = await api.get('/reports/dashboard'); return data; }, enabled: !!currentOrg, }); const fmt = (v: string | number) => parseFloat(String(v || '0')).toLocaleString('en-US', { style: 'currency', currency: 'USD' }); const stats = [ { title: 'Total Cash', value: fmt(data?.total_cash || '0'), icon: IconCash, color: 'green' }, { title: 'Total Receivables', value: fmt(data?.total_receivables || '0'), icon: IconFileInvoice, color: 'blue' }, { title: 'Reserve Fund', value: fmt(data?.reserve_fund_balance || '0'), icon: IconShieldCheck, color: 'violet' }, { title: 'Delinquent Accounts', value: String(data?.delinquent_units || 0), icon: IconAlertTriangle, color: 'orange' }, ]; const entryTypeColors: Record = { manual: 'gray', assessment: 'blue', payment: 'green', late_fee: 'red', transfer: 'cyan', adjustment: 'yellow', closing: 'dark', opening_balance: 'indigo', }; return (
Dashboard {currentOrg ? `${currentOrg.name} - ${currentOrg.role}` : 'No organization selected'}
{!currentOrg ? ( Welcome to HOA LedgerIQ Create or select an organization to get started. ) : isLoading ? (
) : ( <> {stats.map((stat) => (
{stat.title} {stat.value}
))}
Recent Transactions {(data?.recent_transactions || []).length === 0 ? ( No transactions yet. Start by entering journal entries. ) : ( {(data?.recent_transactions || []).map((tx) => ( {new Date(tx.entry_date).toLocaleDateString()} {tx.description} {tx.entry_type} {fmt(tx.amount)} ))}
)}
Quick Stats Cash Position {fmt(data?.total_cash || '0')} Outstanding AR {fmt(data?.total_receivables || '0')} Reserve Funding {fmt(data?.reserve_fund_balance || '0')} Delinquent Units {data?.delinquent_units || 0}
)}
); }