import { useNavigate } from 'react-router-dom'; import { Grid, Stack, Typography, Box, Button, Divider, LinearProgress, Chip, Avatar } from '@mui/material'; import Inventory2OutlinedIcon from '@mui/icons-material/Inventory2Outlined'; import LocalShippingOutlinedIcon from '@mui/icons-material/LocalShippingOutlined'; import TwoWheelerOutlinedIcon from '@mui/icons-material/TwoWheelerOutlined'; import HubOutlinedIcon from '@mui/icons-material/HubOutlined'; import CurrencyRupeeIcon from '@mui/icons-material/CurrencyRupee'; import TaskAltOutlinedIcon from '@mui/icons-material/TaskAltOutlined'; import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined'; import ArrowRightAltRoundedIcon from '@mui/icons-material/ArrowRightAltRounded'; import ScheduleOutlinedIcon from '@mui/icons-material/ScheduleOutlined'; import AutoAwesomeOutlinedIcon from '@mui/icons-material/AutoAwesomeOutlined'; import ArrowForwardRoundedIcon from '@mui/icons-material/ArrowForwardRounded'; import PageHeader from '@/components/PageHeader'; import KpiStrip from '@/components/KpiStrip'; import MainCard from '@/components/MainCard'; import StatusChip from '@/components/StatusChip'; import AreaChart from '@/components/charts/AreaChart'; import ProcessTracker from '@/components/ProcessTracker'; import AiImpactSummary from '@/components/AiImpactSummary'; import Toast, { useToast } from '@/components/Toast'; import AsyncBoundary from '@/components/AsyncBoundary'; import HealthStatusWidget from '@/components/HealthStatusWidget'; import useApi from '@/hooks/useApi'; import { getDashboard } from '@/services/adminService'; import { inr } from '@/utils/format'; const SEV_DOT = { high: '#F04134', medium: '#FFBF00', low: '#00A2AE', info: '#8C8C8C' }; function SectionLabel({ children }) { return {children}; } export default function Dashboard() { const [toast, showToast] = useToast(); // Live dashboard payload (GET /admin/dashboard), auto-refreshed every 30s. const { data, loading, error, refetch } = useApi(getDashboard, [], { refreshMs: 30000 }); return ( <> } /> {data && } ); } function DashboardContent({ data }) { const navigate = useNavigate(); const { kpis: k, dispatchQueue, activeDeliveries, aiInsights, executionFeed, fleetSummary, lanePerformance, ordersTrend } = data; const priority = activeDeliveries.filter((d) => (d.priority === 'high' || d.priority === 'express') && d.status !== 'Delivered').slice(0, 4); const delayed = activeDeliveries.filter((d) => d.etaStatus !== 'on-time' && d.status !== 'Delivered').slice(0, 4); const recs = aiInsights.slice(0, 4); const kpis = [ { label: 'Total Orders', value: k.totalOrders.toLocaleString('en-IN'), icon: Inventory2OutlinedIcon }, { label: 'Active Shipments', value: String(k.activeShipments), color: '#1D4ED8', icon: LocalShippingOutlinedIcon }, { label: 'Riders Online', value: String(k.ridersOnline), color: '#00773B', icon: TwoWheelerOutlinedIcon }, { label: 'Hub Utilization', value: `${k.hubUtilization}%`, color: k.hubUtilization > 80 ? '#A82216' : '#8A6500', icon: HubOutlinedIcon }, { label: 'Revenue Today', value: inr(k.revenueToday), color: '#00727B', icon: CurrencyRupeeIcon }, { label: 'SLA Performance', value: `${k.slaPerformance}%`, color: '#00773B', icon: TaskAltOutlinedIcon } ]; return ( <> {/* Top row — 6 live KPIs */} {/* Second row — dispatch intelligence */} Dispatch & Exceptions navigate('/orders/assign')} sx={{ fontWeight: 600 }}>Open} noPadding> }> {dispatchQueue.map((d) => ( {d.id} {d.pickup} → {d.drop} AI → {d.suggestedRider} · SLA {d.sla} ))} }> {priority.map((d) => ( {d.id} {d.destination} {d.priority} ))} }> {delayed.map((d) => ( {d.id} {d.rider} +{d.delayMin}m ))} {delayed.length === 0 && No delays.} }> {recs.map((r) => ( {r.title} {r.action} ))} {/* Third row — events / fleet / route efficiency */} Operational Intelligence }> {executionFeed.map((e, i) => ( {e.stage} {e.time} {e.id} · {e.loc} ))} {[['On trip', fleetSummary.onTrip, '#1D4ED8'], ['Charging', fleetSummary.charging, '#00A2AE'], ['Idle', fleetSummary.idle, '#8C8C8C'], ['Maintenance', fleetSummary.maintenance, '#F04134']].map(([l, v, c]) => ( {v} {l} ))} EV fleet share {fleetSummary.evShare}% }> {lanePerformance.slice(0, 5).map((l) => ( {l.lane} {l.onTime}% · {inr(l.costPer)} = 98 ? 'success' : l.onTime >= 96 ? 'warning' : 'error'} sx={{ height: 5, borderRadius: 3 }} /> ))} {/* End-to-end flow + volume trend */} Network Flow & Volume } sx={{ height: '100%' }} > d.m)} series={[ { name: 'Orders', color: '#C01227', data: ordersTrend.map((d) => d.orders) }, { name: 'Delivered', color: '#00A854', data: ordersTrend.map((d) => d.delivered) } ]} /> {/* AI impact */} ); } function Legend({ color, label }) { return ( {label} ); }