import React from 'react'; import { useQuery } from '@tanstack/react-query'; import { Building2, Users, Activity, CreditCard, TrendingUp, TrendingDown, } from 'lucide-react'; import { api } from '@/lib/api'; import { usePermissions } from '@/hooks/usePermissions'; interface DashboardStats { tenants: { total: number; active: number; trial: number }; users: { total: number; active: number }; api_usage: { today: number; this_month: number; limit: number }; revenue: { mrr: number; this_month: number; last_month: number }; } function StatCard({ title, value, subtitle, icon: Icon, trend, trendUp, }: { title: string; value: string | number; subtitle: string; icon: React.ElementType; trend?: string; trendUp?: boolean; }) { return (

{title}

{value}

{trend && (
{trendUp ? : } {trend}
)}

{subtitle}

); } export function Dashboard() { const { hasPermission } = usePermissions(); const { data: stats } = useQuery({ queryKey: ['dashboard', 'summary'], queryFn: () => api.get('/dashboard/summary'), }); return (

Dashboard

{hasPermission('tenants.read') && ( )} {hasPermission('billing.read') && ( )}
{/* Recent Activity */}

Recent Activity

{/* API Usage Chart */}

API Usage (7 days)

); } function ActivityFeed() { const activities = [ { action: 'New tenant', detail: 'Stockholm Kommun registered', time: '2 min ago' }, { action: 'User locked', detail: 'admin@example.com after 5 failed attempts', time: '15 min ago' }, { action: 'Invoice paid', detail: '#INV-2024-001 - 12,000 SEK', time: '1 hour ago' }, { action: 'API key revoked', detail: 'Production key by admin@x.com', time: '2 hours ago' }, ]; return ( ); } function ApiUsageChart() { // Placeholder for chart - would use recharts or similar const data = [65, 78, 90, 81, 56, 95, 120]; const max = Math.max(...data); return (
{data.map((value, i) => (
{['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][i]}
))}
); }