update api
This commit is contained in:
@@ -20,41 +20,64 @@ import AreaChart from '@/components/charts/AreaChart';
|
||||
import ProcessTracker from '@/components/ProcessTracker';
|
||||
import AiImpactSummary from '@/components/AiImpactSummary';
|
||||
import Toast, { useToast } from '@/components/Toast';
|
||||
import { dispatchQueue, activeDeliveries, aiInsights, executionFeed, fleetSummary, lanePerformance, hubCityStats, ordersTrend, analyticsKpis } from '@/data/mock';
|
||||
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' };
|
||||
const hubUtil = Math.round(hubCityStats.reduce((s, h) => s + h.utilization, 0) / hubCityStats.length);
|
||||
|
||||
function SectionLabel({ children }) {
|
||||
return <Typography variant="overline" color="text.secondary" sx={{ letterSpacing: '0.08em', display: 'block', mb: 1.25 }}>{children}</Typography>;
|
||||
}
|
||||
|
||||
export default function Dashboard() {
|
||||
const navigate = useNavigate();
|
||||
const [toast, showToast] = useToast();
|
||||
|
||||
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: '1,402', icon: Inventory2OutlinedIcon },
|
||||
{ label: 'Active Shipments', value: '96', color: '#1D4ED8', icon: LocalShippingOutlinedIcon },
|
||||
{ label: 'Riders Online', value: '48', color: '#00773B', icon: TwoWheelerOutlinedIcon },
|
||||
{ label: 'Hub Utilization', value: `${hubUtil}%`, color: hubUtil > 80 ? '#A82216' : '#8A6500', icon: HubOutlinedIcon },
|
||||
{ label: 'Revenue Today', value: inr(384200), color: '#00727B', icon: CurrencyRupeeIcon },
|
||||
{ label: 'SLA Performance', value: `${analyticsKpis.slaAchievement}%`, color: '#00773B', icon: TaskAltOutlinedIcon }
|
||||
];
|
||||
// Live dashboard payload (GET /admin/dashboard), auto-refreshed every 30s.
|
||||
const { data, loading, error, refetch } = useApi(getDashboard, [], { refreshMs: 30000 });
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Operations Control Center"
|
||||
breadcrumbs={[{ label: 'Control Center' }]}
|
||||
action={<Button variant="outlined" startIcon={<FileDownloadOutlinedIcon />} onClick={() => showToast('Snapshot exported as CSV')}>Export</Button>}
|
||||
action={
|
||||
<Stack direction="row" spacing={2.5} alignItems="center">
|
||||
<HealthStatusWidget />
|
||||
<Button variant="outlined" startIcon={<FileDownloadOutlinedIcon />} onClick={() => showToast('Snapshot exported as CSV')}>Export</Button>
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
|
||||
<AsyncBoundary loading={loading} error={error} onRetry={refetch} skeletonHeight={96} skeletonCount={4}>
|
||||
{data && <DashboardContent data={data} showToast={showToast} />}
|
||||
</AsyncBoundary>
|
||||
|
||||
<Toast {...toast} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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 */}
|
||||
<KpiStrip items={kpis} />
|
||||
|
||||
@@ -226,8 +249,6 @@ export default function Dashboard() {
|
||||
<Box sx={{ mt: 3.5 }}>
|
||||
<AiImpactSummary />
|
||||
</Box>
|
||||
|
||||
<Toast {...toast} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user