114 lines
2.9 KiB
JavaScript
114 lines
2.9 KiB
JavaScript
// ==============================|| MOCK ADAPTER — ADMIN ||============================== //
|
|
// Assembles the documented backend response shapes from the existing demo data in
|
|
// src/data/mock.js. Defining these shapes IS the act of pinning the API contract:
|
|
// when the real backend lands it must return the same structure, and flipping
|
|
// VITE_USE_MOCK=false will send the page through to live HTTP unchanged.
|
|
|
|
import {
|
|
dispatchQueue,
|
|
activeDeliveries,
|
|
aiInsights,
|
|
executionFeed,
|
|
fleetSummary,
|
|
lanePerformance,
|
|
hubCityStats,
|
|
ordersTrend,
|
|
analyticsKpis,
|
|
orders,
|
|
orderTimeline,
|
|
deliveries,
|
|
riders,
|
|
fleetVehicles
|
|
} from '@/data/mock';
|
|
|
|
const hubUtilization = Math.round(hubCityStats.reduce((s, h) => s + h.utilization, 0) / hubCityStats.length);
|
|
|
|
// GET /admin/dashboard
|
|
export function mockDashboard() {
|
|
return {
|
|
// Headline KPI strip — previously hardcoded in the page.
|
|
kpis: {
|
|
totalOrders: 1402,
|
|
activeShipments: 96,
|
|
ridersOnline: 48,
|
|
hubUtilization,
|
|
revenueToday: 384200,
|
|
slaPerformance: analyticsKpis.slaAchievement
|
|
},
|
|
dispatchQueue,
|
|
activeDeliveries,
|
|
aiInsights,
|
|
executionFeed,
|
|
fleetSummary,
|
|
lanePerformance,
|
|
ordersTrend
|
|
};
|
|
}
|
|
|
|
// GET /admin/bookings -> Booking[]
|
|
export function mockBookings() {
|
|
return orders;
|
|
}
|
|
|
|
// GET /admin/bookings/:id -> BookingDetail
|
|
export function mockBooking(id) {
|
|
const order = orders.find((o) => o.id === id) || orders[0];
|
|
const delivery = deliveries.find((d) => d.id === order.id) || deliveries[0];
|
|
return { order, timeline: orderTimeline, delivery };
|
|
}
|
|
|
|
// GET /admin/milers -> Miler[]
|
|
export function mockMilers() {
|
|
return riders;
|
|
}
|
|
|
|
// GET /admin/dispatch-queue -> DispatchQueueItem[]
|
|
export function mockDispatchQueue() {
|
|
return dispatchQueue;
|
|
}
|
|
|
|
// GET /admin/consignments -> Consignment[]
|
|
export function mockConsignments() {
|
|
return activeDeliveries;
|
|
}
|
|
|
|
// GET /admin/consignments/track/:trackingno -> Consignment
|
|
export function mockTrackConsignment(trackingNo) {
|
|
return activeDeliveries.find((d) => d.id === trackingNo) || null;
|
|
}
|
|
|
|
// Ambient fleet scatter for the tracking map.
|
|
export function mockFleetPositions() {
|
|
return fleetVehicles;
|
|
}
|
|
|
|
// Write acknowledgements — the mock backend simply confirms the mutation.
|
|
export function mockOk(extra = {}) {
|
|
return { ok: true, ...extra };
|
|
}
|
|
|
|
// POST /admin/login — fake token + admin profile (incl. role + fine-grained permissions).
|
|
export function mockLogin({ authName } = {}) {
|
|
return {
|
|
token: 'mock.admin.jwt.token',
|
|
profile: {
|
|
id: 'ADM-001',
|
|
name: 'Aman Deshmukh',
|
|
role: 'ops_admin',
|
|
email: authName || 'admin@doormile.in',
|
|
permissions: [
|
|
'dashboard:view',
|
|
'bookings:view',
|
|
'bookings:assign',
|
|
'bookings:update',
|
|
'milers:view',
|
|
'consignments:view',
|
|
'fleet:view',
|
|
'hubs:view',
|
|
'reports:view',
|
|
'settings:view'
|
|
]
|
|
}
|
|
};
|
|
}
|