diff --git a/src/pages/nearle/dispatch/ActiveSection.js b/src/pages/nearle/dispatch/ActiveSection.js index 7d50c78..bfd45c1 100644 --- a/src/pages/nearle/dispatch/ActiveSection.js +++ b/src/pages/nearle/dispatch/ActiveSection.js @@ -21,12 +21,12 @@ const ActiveSection = ({ calculateEstMeters, getRiderColor, formatMeters, - isLoading, - onMapZoom + isLoading }) => { // Sort by live distance ascending (closest drop-off first; null/unknown last) const activeDeliveries = visibleRiders - .flatMap((r) => (r.orders || []).filter((o) => String(o.orderstatus || '').toLowerCase() === 'active')) + .map((r) => getActiveOrder(r.orders)) + .filter(Boolean) .sort((a, b) => { const mA = calculateEstMeters(a.rider_id || a.userid, a) ?? Infinity; const mB = calculateEstMeters(b.rider_id || b.userid, b) ?? Infinity; @@ -53,14 +53,17 @@ const ActiveSection = ({ Object.entries(currentMap).forEach(([oid, cur]) => { const old = prev[oid]; if (!old) { + // Brand-new order that is already active → rider has taken a new order if (cur.status === 'active') { OpenToast(`🛵 ${cur.riderName} is now delivering to ${cur.customer}`, 'success', 3000); } return; } + // Rider transitioned into active → started heading to customer if (old.status !== 'active' && cur.status === 'active') { OpenToast(`🛵 ${cur.riderName} is now delivering to ${cur.customer}`, 'success', 3000); } + // Rider delivered → reached customer location if (old.status === 'active' && cur.status === 'delivered') { OpenToast(`📍 ${cur.riderName} has reached ${cur.customer}'s location`, 'info', 3000); } @@ -121,7 +124,8 @@ const ActiveSection = ({ className={`adcard${isActive ? ' is-active' : ''}`} style={{ '--ad-accent': color }} onClick={() => { - if (canFocus && onMapZoom) onMapZoom(lat, lon); + if (rider) handleRiderFocus(rider); + if (canFocus) setFocusedStop({ orderid: o.orderid, lat, lon }); }} >