updates on the api integration and the design changes on the whole website
This commit is contained in:
@@ -1314,7 +1314,16 @@ const Dispatch = ({
|
||||
|
||||
const { data: riderInfoData, isFetching: riderInfoFetching, isError: riderInfoIsError, error: riderInfoError } = useQuery({
|
||||
queryKey: ['riderPeriodicLog', riderInfoUserid],
|
||||
queryFn: () => getRiderPeriodicLogs(riderInfoUserid),
|
||||
// riderInfoUserid is actually a userid (it's sourced from ridersAllDay,
|
||||
// which comes from booking data — assignedmileruserid, confirmed live)
|
||||
// but /admin/milers/:id/* routes need milerprofileid. liveRiderLocations
|
||||
// (declared below) carries both, so resolve the real id here rather than
|
||||
// changing riderInfoUserid itself, which is compared against elsewhere
|
||||
// in this file for sidebar row highlighting in userid-space.
|
||||
queryFn: () => {
|
||||
const match = liveRiderLocations.find((r) => String(r.userid) === String(riderInfoUserid));
|
||||
return getRiderPeriodicLogs(match?.milerprofileid ?? riderInfoUserid);
|
||||
},
|
||||
enabled: viewMode === 'rider-info' && riderInfoUserid != null,
|
||||
// Auto-refresh the rider snapshot every 15s while the view is open and a
|
||||
// rider is selected. Don't poll while the tab is hidden so we don't burn
|
||||
@@ -1544,8 +1553,14 @@ const Dispatch = ({
|
||||
const lon = parseFloat(r?.longitude);
|
||||
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return null;
|
||||
return {
|
||||
// id stays userid-keyed — it's what joins this live-GPS feed against
|
||||
// `riders`/orders elsewhere in this file, which are themselves keyed
|
||||
// by a booking's assignedmileruserid (also a userid, confirmed live).
|
||||
// milerprofileid is kept separately for the one place that actually
|
||||
// needs it: /admin/milers/:id/* calls (the rider-info panel).
|
||||
id: String(r.userid ?? ''),
|
||||
userid: r.userid,
|
||||
milerprofileid: r.milerprofileid,
|
||||
username: r.username || `Rider #${r.userid}`,
|
||||
status: String(r.status || '').toLowerCase(),
|
||||
contactno: r.contactno,
|
||||
@@ -1558,12 +1573,15 @@ const Dispatch = ({
|
||||
.filter(Boolean);
|
||||
}, [ridersLocationLogs]);
|
||||
|
||||
// Set of rider ids whose latest GPS log row is `active` (i.e. on the road
|
||||
// Set of rider ids whose latest position is `active` (i.e. on the road
|
||||
// right now). The "All Active Routes" view (viewMode === 'all') uses this to
|
||||
// show ONLY currently-active riders — their cards, routes, drop markers and
|
||||
// live bike markers — and hide everyone who is offline/idle for the slot.
|
||||
// GET /admin/milers/summary's availabilitystatus enum is confirmed live as
|
||||
// Available/Assigned/On_Pickup/Offline — not active/pending, which never
|
||||
// matched anything and left this set permanently empty.
|
||||
const activeRiderIdSet = useMemo(
|
||||
() => new Set(liveRiderLocations.filter((r) => r.status === 'active' || r.status === 'pending').map((r) => String(r.id))),
|
||||
() => new Set(liveRiderLocations.filter((r) => r.status !== 'offline' && r.status !== 'blocked').map((r) => String(r.id))),
|
||||
[liveRiderLocations]
|
||||
);
|
||||
// Default to the slot containing the current wall-clock time. Use a
|
||||
@@ -1707,6 +1725,12 @@ const Dispatch = ({
|
||||
const riderDailyData = {};
|
||||
|
||||
liveRows.forEach(r => {
|
||||
// Cancelled/skipped orders never delivered, so they shouldn't earn
|
||||
// revenue or be charged fuel/slot cost either — matches the same fix
|
||||
// already applied to ProfitabilitySection.js's calcRiderMetrics.
|
||||
const status = String(r.orderstatus ?? r.status ?? '').toLowerCase();
|
||||
if (SKIPPED_STATUSES.has(status)) return;
|
||||
|
||||
// Filter by selectedDate to align with daily slot aggregations
|
||||
const dateStr = r.assigntime
|
||||
? dayjs(r.assigntime).format('YYYY-MM-DD')
|
||||
@@ -2053,7 +2077,7 @@ const Dispatch = ({
|
||||
() =>
|
||||
isAllActiveView
|
||||
? liveRiderLocations
|
||||
.filter((r) => (r.status === 'active' || r.status === 'pending') && activeOrderRiderIdSet.has(String(r.id)))
|
||||
.filter((r) => r.status !== 'offline' && r.status !== 'blocked' && activeOrderRiderIdSet.has(String(r.id)))
|
||||
.map((r) => [r.lat, r.lon])
|
||||
: [],
|
||||
[isAllActiveView, liveRiderLocations, activeOrderRiderIdSet]
|
||||
@@ -5129,7 +5153,8 @@ const Dispatch = ({
|
||||
|
||||
{/* Live rider GPS markers from GET /admin/milers/summary (see
|
||||
fetchRidersLogs in api.js). Green pin when the rider's status
|
||||
is `active`, red otherwise, with the rider's username as a
|
||||
isn't `offline` (Available/Assigned/On_Pickup — confirmed
|
||||
live enum), red otherwise, with the rider's username as a
|
||||
label. Scoped to riders who actually have orders in the
|
||||
currently selected slot — `riders` is derived from
|
||||
filteredLiveRows so it already reflects the slot filter. A
|
||||
@@ -5139,12 +5164,12 @@ const Dispatch = ({
|
||||
{liveRiderLocations
|
||||
.filter((r) =>
|
||||
isAllActiveView
|
||||
? ((r.status === 'active' || r.status === 'pending') && activeOrderRiderIdSet.has(String(r.id)))
|
||||
? (r.status !== 'offline' && r.status !== 'blocked' && activeOrderRiderIdSet.has(String(r.id)))
|
||||
: riders.some((rd) => String(rd.id) === String(r.id))
|
||||
)
|
||||
.filter((r) => !focusedRider || String(focusedRider.id) === String(r.id))
|
||||
.map((r) => {
|
||||
const isActive = r.status === 'active' || r.status === 'pending';
|
||||
const isActive = r.status !== 'offline' && r.status !== 'blocked';
|
||||
const pinColor = isActive ? '#16a34a' : '#dc2626';
|
||||
// Look up the rider's in-progress order so the popup can show
|
||||
// where they're heading next (drop customer/area + originating
|
||||
|
||||
Reference in New Issue
Block a user