/** * Dashboard Home Page - Clean & Colorful with Charts * Professional design with data visualization */ 'use client'; import { useQuery } from '@tanstack/react-query'; import { dashboardApi } from '@/lib/api'; import Link from 'next/link'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Package, PackageCheck, PackageX, Clock, Weight, TrendingUp, Plus, ArrowRight, } from 'lucide-react'; import { PieChart, Pie, Cell, BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, LineChart, Line, Legend, } from 'recharts'; export default function DashboardPage() { // Fetch CSV booking KPIs const { data: csvKpis, isLoading: csvKpisLoading } = useQuery({ queryKey: ['dashboard', 'csv-booking-kpis'], queryFn: () => dashboardApi.getCsvBookingKPIs(), }); // Fetch top carriers const { data: topCarriers, isLoading: carriersLoading } = useQuery({ queryKey: ['dashboard', 'top-carriers'], queryFn: () => dashboardApi.getTopCarriers(), }); // Prepare data for charts const statusDistribution = csvKpis ? [ { name: 'Acceptés', value: csvKpis.totalAccepted, color: '#10b981' }, { name: 'Refusés', value: csvKpis.totalRejected, color: '#ef4444' }, { name: 'En Attente', value: csvKpis.totalPending, color: '#f59e0b' }, ] : []; const carrierWeightData = topCarriers ? topCarriers.slice(0, 5).map(c => ({ name: c.carrierName.length > 15 ? c.carrierName.substring(0, 15) + '...' : c.carrierName, poids: Math.round(c.totalWeightKG), })) : []; return (
{/* Header - Compact */}

Tableau de Bord

Vue d'ensemble de vos bookings et performances

{/* KPI Cards - Compact with Color */}
{/* Bookings Acceptés */}

Acceptés

{csvKpisLoading ? (
) : ( <>

{csvKpis?.totalAccepted || 0}

+{csvKpis?.acceptedThisMonth || 0} ce mois

)}
{/* Bookings Refusés */}

Refusés

{csvKpisLoading ? (
) : ( <>

{csvKpis?.totalRejected || 0}

+{csvKpis?.rejectedThisMonth || 0} ce mois

)}
{/* Bookings En Attente */}

En Attente

{csvKpisLoading ? (
) : ( <>

{csvKpis?.totalPending || 0}

{csvKpis?.acceptanceRate.toFixed(1)}% acceptés

)}
{/* Poids Total */}

Poids Total

{csvKpisLoading ? (
) : ( <>

{(csvKpis?.totalWeightAcceptedKG || 0).toLocaleString()}

KG • {(csvKpis?.totalVolumeAcceptedCBM || 0).toFixed(1)} CBM

)}
{/* Charts Section */}
{/* Distribution des Statuts - Pie Chart */} Distribution des Bookings Répartition par statut {csvKpisLoading ? (
) : ( `${name} ${((percent || 0) * 100).toFixed(0)}%` } outerRadius={70} fill="#8884d8" dataKey="value" > {statusDistribution.map((entry, index) => ( ))} )} {/* Poids par Transporteur - Bar Chart */} Poids par Transporteur Top 5 carriers par poids (KG) {carriersLoading ? (
) : ( )}
{/* Performance Overview - Compact */}

Taux d'Acceptation

{csvKpisLoading ? '--' : `${csvKpis?.acceptanceRate.toFixed(1)}%`}

Total Bookings

{csvKpisLoading ? '--' : (csvKpis?.totalAccepted || 0) + (csvKpis?.totalRejected || 0) + (csvKpis?.totalPending || 0)}

Volume Total

{csvKpisLoading ? '--' : `${(csvKpis?.totalVolumeAcceptedCBM || 0).toFixed(1)}`} CBM

{/* Top Carriers - Compact Table */}
Top Transporteurs Classement des meilleures compagnies
{carriersLoading ? (
{Array.from({ length: 3 }).map((_, i) => (
))}
) : topCarriers && topCarriers.length > 0 ? (
{topCarriers.slice(0, 5).map((carrier, index) => (
{index + 1}

{carrier.carrierName}

{carrier.totalBookings} bookings {carrier.totalWeightKG.toLocaleString()} KG
{carrier.acceptedBookings} ✓ {carrier.rejectedBookings > 0 && ( {carrier.rejectedBookings} ✗ )}

{carrier.acceptanceRate.toFixed(0)}% • ${carrier.avgPriceUSD.toFixed(0)}

))}
) : (

Aucun booking

Créez votre premier booking pour voir vos statistiques

)}
); }