import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { CreditCard, TrendingUp, Activity, Menu, X, Home, List, BarChart3, Wifi, WifiOff, Bell } from 'lucide-react'; import { apiClient } from '../lib/api'; import AccountsOverview from './AccountsOverview'; import TransactionsList from './TransactionsList'; import Notifications from './Notifications'; import ErrorBoundary from './ErrorBoundary'; import { cn } from '../lib/utils'; import type { Account } from '../types/api'; type TabType = 'overview' | 'transactions' | 'analytics' | 'notifications'; export default function Dashboard() { const [activeTab, setActiveTab] = useState('overview'); const [sidebarOpen, setSidebarOpen] = useState(false); const { data: accounts } = useQuery({ queryKey: ['accounts'], queryFn: apiClient.getAccounts, }); const { data: healthStatus, isLoading: healthLoading, isError: healthError } = useQuery({ queryKey: ['health'], queryFn: async () => { const response = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:8000'}/api/v1/health`); if (!response.ok) { throw new Error(`Health check failed: ${response.status}`); } return response.json(); }, refetchInterval: 30000, // Check every 30 seconds retry: 3, }); const navigation = [ { name: 'Overview', icon: Home, id: 'overview' as TabType }, { name: 'Transactions', icon: List, id: 'transactions' as TabType }, { name: 'Analytics', icon: BarChart3, id: 'analytics' as TabType }, { name: 'Notifications', icon: Bell, id: 'notifications' as TabType }, ]; const totalBalance = accounts?.reduce((sum, account) => { // Get the first available balance from the balances array const primaryBalance = account.balances?.[0]?.amount || 0; return sum + primaryBalance; }, 0) || 0; return (
{/* Sidebar */}

Leggen

{/* Account Summary in Sidebar */}
Total Balance

{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'EUR', }).format(totalBalance)}

{accounts?.length || 0} accounts

{/* Overlay for mobile */} {sidebarOpen && (
setSidebarOpen(false)} /> )} {/* Main content */}
{/* Header */}

{navigation.find(item => item.id === activeTab)?.name}

{healthLoading ? ( <> Checking... ) : healthError || !healthStatus?.success ? ( <> Disconnected ) : ( <> Connected )}
{/* Main content area */}
{activeTab === 'overview' && } {activeTab === 'transactions' && } {activeTab === 'analytics' && (

Analytics

Analytics dashboard coming soon...

)} {activeTab === 'notifications' && }
); }