import { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import { Users, Scissors, Calendar, FileText, MessageCircle, ClipboardList, TrendingUp, AlertCircle, } from 'lucide-react'; import { API_URL } from '../config'; interface Stat { label: string; value: number; icon: any; color: string; path: string } export default function Dashboard() { const stats: Stat[] = [ { label: 'Active Clients', value: 0, icon: Users, color: 'bg-blue-500', path: '/clients' }, { label: 'Services', value: 0, icon: Scissors, color: 'bg-emerald-500', path: '/services' }, { label: 'Pending Bookings', value: 0, icon: Calendar, color: 'bg-amber-500', path: '/bookings' }, { label: 'Unpaid Invoices', value: 0, icon: FileText, color: 'bg-red-500', path: '/invoices' }, { label: 'Messages', value: 0, icon: MessageCircle, color: 'bg-purple-500', path: '/messages' }, ]; // Fetch stats const [statsData, setStatsData] = useState([]); useEffect(() => { Promise.all([ fetch(`${API_URL}/clients?limit=1`).catch(() => ({ ok: false })), fetch(`${API_URL}/bookings?status=scheduled`).catch(() => ({ ok: false })), fetch(`${API_URL}/invoices`).catch(() => ({ ok: false })), fetch(`${API_URL}/services`).catch(() => ({ ok: false })), ]).then(async ([c, b, i, s]) => { const [clients, bookings, invoices, services] = await Promise.all([ (c as Response).json().catch(() => ({ total: 0 })), (b as Response).json().catch(() => ({ items: [] })), (i as Response).json().catch(() => ({ items: [] })), (s as Response).json().catch(() => ({ items: [] })), ]); setStatsData([ { ...stats[0], value: clients.total || 0 }, { ...stats[1], value: services.items?.length || services.length || 0 }, { ...stats[2], value: bookings.items?.filter((x: any) => x.status === 'scheduled').length || 0 }, { ...stats[3], value: (invoices.items || []).filter((x: any) => x.status !== 'paid').length || 0 }, { ...stats[4], value: 0 }, ]); }); }, []); return (

Dashboard

{statsData.map((s, i) => (
{s.value}

{s.label}

))}

Quick Actions

{[ { label: 'Add New Client', path: '/clients', icon: Users }, { label: 'Create Booking', path: '/bookings', icon: Calendar }, { label: 'Generate Invoice', path: '/invoices', icon: FileText }, { label: 'New Message', path: '/messages', icon: MessageCircle }, ].map((action) => { const Icon = action.icon; return ( {action.label} ); })}

Recent Bookings

); } function RecentBookings() { const [bookings, setBookings] = useState([]); useEffect(() => { fetch(`${API_URL}/bookings?limit=5`) .then(r => r.json()) .then(d => setBookings(d.items || [])) .catch(() => {}); }, []); if (bookings.length === 0) { return

No bookings yet. Create one to get started.

; } return (
{bookings.map((b) => (

{b.client?.firstName} {b.client?.lastName}

{b.service?.name} ยท {b.startAt ? new Date(b.startAt).toLocaleDateString() : ''}

{b.status}
))}
); }