import { useEffect, useMemo, useState } from 'react'; import { Clock, Database, Server, ShieldCheck, } from 'lucide-react'; import { TopBar } from '@/components/layout/TopBar'; import { MetricCard } from '@/components/dashboard/MetricCard'; import { IpPoolChart } from '@/components/dashboard/IpPoolChart'; import { NetworkTrafficChart } from '@/components/dashboard/NetworkTrafficChart'; import { ProvisioningWizard } from '@/components/provisioning/ProvisioningWizard'; import { BackendSettings } from '@/components/settings/BackendSettings'; import { ActivityLogs } from '@/components/activity/ActivityLogs'; import { Card } from '@/components/ui/Card'; import { vpnApi } from '@/services/vpnApi'; import { vpsApi } from '@/services/vpsApi'; import type { UsedIpsResponse, VpsHealth, } from '@/types/api'; export function DashboardRoute() { const [health, setHealth] = useState(null); const [usedIps, setUsedIps] = useState(null); const [error, setError] = useState(''); useEffect(() => { async function loadDashboard() { try { const [ healthResponse, usedIpsResponse, ] = await Promise.all([ vpsApi.health(), vpnApi.usedIps(), ]); setHealth(healthResponse); setUsedIps(usedIpsResponse); setError(''); } catch (err) { setHealth(null); setUsedIps(null); setError(String(err)); } } loadDashboard(); const intervalId = window.setInterval( loadDashboard, 15000, ); return () => { window.clearInterval(intervalId); }; }, []); const ipPoolTotal = health?.ipPoolTotal ?? 65534; const usedCount = health?.ipPoolUsed ?? usedIps?.count ?? 0; const ipPoolPercent = useMemo(() => { return ( (usedCount / ipPoolTotal) * 100 ).toFixed(2); }, [usedCount, ipPoolTotal]); const backendHealthy = health?.backend === true; const vpnHealthy = health?.wireGuardRunning === true; const dashboardReady = !error && Boolean(health) && backendHealthy && vpnHealthy; return (
{error && (
Dashboard backend error:{' '} {error}
)}
} /> } /> } /> } />
); } export function PlaceholderRoute({ name, }: { name: string; }) { return (

{name}

Screen scaffold ready for production implementation.

); } export function RouteView({ active, }: { active: string; }) { if (active === 'Dashboard') { return ; } if (active === 'Provisioning') { return ; } if (active === 'UDP2RAW Config') { return ( ); } if (active === 'Activity Logs') { return ; } if (active === 'Workstation') { return ; } return ; }