updates on the active section and the dispatch page section regarding the active order details
This commit is contained in:
@@ -26,9 +26,7 @@ const ActiveSection = ({
|
||||
}) => {
|
||||
// Sort by live distance ascending (closest drop-off first; null/unknown last)
|
||||
const activeDeliveries = visibleRiders
|
||||
.map((r) => getActiveOrder(r.orders))
|
||||
.filter(Boolean)
|
||||
.filter((o) => String(o.orderstatus || '').toLowerCase() === 'active')
|
||||
.flatMap((r) => (r.orders || []).filter((o) => String(o.orderstatus || '').toLowerCase() === 'active'))
|
||||
.sort((a, b) => {
|
||||
const mA = calculateEstMeters(a.rider_id || a.userid, a) ?? Infinity;
|
||||
const mB = calculateEstMeters(b.rider_id || b.userid, b) ?? Infinity;
|
||||
|
||||
@@ -1304,7 +1304,7 @@ const Dispatch = ({
|
||||
hasNextPage: liveHasNextPage,
|
||||
isFetchingNextPage: liveIsFetchingNextPage
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ['dispatchDeliveries', selectedAppLocationId, liveUserid, 'all', selectedDate, selectedDate, 50, '', 0, 0, 0],
|
||||
queryKey: ['dispatchDeliveries', selectedAppLocationId, liveUserid, 'all', selectedDate, selectedDate, 1000, '', 0, 0, 0],
|
||||
queryFn: fetchDeliveries,
|
||||
getNextPageParam: (lastPage) => lastPage.nextPage ?? undefined,
|
||||
enabled: shouldFetchLive,
|
||||
@@ -1578,10 +1578,8 @@ const Dispatch = ({
|
||||
// excluded here. Every other view (By Location / By Zone / By Rider) is
|
||||
// unchanged.
|
||||
const isAllActiveView = viewMode === 'all';
|
||||
// Orders belonging to GPS-active riders — the candidate pool for this view's
|
||||
// list, drop set and auto-fit. Narrowed to in-progress orders below.
|
||||
const allViewOrders = useMemo(
|
||||
() => (isAllActiveView ? allOrders.filter((o) => activeRiderIdSet.has(String(o.rider_id))) : allOrders),
|
||||
() => (isAllActiveView ? allOrders.filter((o) => activeRiderIdSet.has(String(o.rider_id || o.userid || ''))) : allOrders),
|
||||
[isAllActiveView, allOrders, activeRiderIdSet]
|
||||
);
|
||||
// The single gate for the whole Active view: rider ids that are GPS-active AND
|
||||
@@ -1592,8 +1590,8 @@ const Dispatch = ({
|
||||
() =>
|
||||
new Set(
|
||||
(isAllActiveView ? allViewOrders : [])
|
||||
.filter(isActiveDelivery)
|
||||
.map((o) => String(o.rider_id))
|
||||
.filter((o) => String(o?.orderstatus || '').toLowerCase() === 'active')
|
||||
.map((o) => String(o.rider_id || o.userid || ''))
|
||||
),
|
||||
[isAllActiveView, allViewOrders]
|
||||
);
|
||||
@@ -2305,8 +2303,12 @@ const Dispatch = ({
|
||||
if (focusedRider && focusedRider.id !== r.id) return;
|
||||
if (focusedKitchen && !focusedKitchen.riders.has(r.id)) return;
|
||||
|
||||
const activeOrder = isAllActiveView ? getActiveOrder(r.orders) : null;
|
||||
const isActiveAndShown = activeOrder && String(activeOrder.orderstatus || '').toLowerCase() === 'active';
|
||||
const rOrders = isAllActiveView ? (isActiveAndShown ? [activeOrder] : []) : r.orders;
|
||||
|
||||
const trips = {};
|
||||
r.orders.forEach(o => {
|
||||
rOrders.forEach(o => {
|
||||
const t = o.trip_number || 1;
|
||||
if (!trips[t]) trips[t] = [];
|
||||
trips[t].push(o);
|
||||
@@ -2320,12 +2322,27 @@ const Dispatch = ({
|
||||
|
||||
if (filteredTOrders.length === 0) return;
|
||||
|
||||
const cacheKey = `${r.id}-${tNum}`;
|
||||
const cacheKey = isAllActiveView ? `${r.id}-active-${filteredTOrders[0].orderid}` : `${r.id}-${tNum}`;
|
||||
const roadPath = osrmRoutes[cacheKey];
|
||||
const sorted = [...filteredTOrders].sort((a, b) => (a.step || 0) - (b.step || 0));
|
||||
|
||||
// Aerial fallback — NaN-safe build
|
||||
const aerialPath = buildTripPoints(sorted);
|
||||
// Aerial fallback
|
||||
let activeStraightLeg = null;
|
||||
if (isAllActiveView && filteredTOrders[0]) {
|
||||
const o = filteredTOrders[0];
|
||||
const lp = liveRiderLocations.find((l) => String(l.id) === String(r.id));
|
||||
const start = (lp && Number.isFinite(lp.lat) && Number.isFinite(lp.lon))
|
||||
? [lp.lat, lp.lon]
|
||||
: (hasValidPickup(o)
|
||||
? [toNum(pickupLat(o)), toNum(pickupLon(o))]
|
||||
: null);
|
||||
const dLat = toNum(o.droplat || o.deliverylat);
|
||||
const dLon = toNum(o.droplon || o.deliverylong);
|
||||
if (start && Number.isFinite(dLat) && Number.isFinite(dLon)) {
|
||||
activeStraightLeg = [start, [dLat, dLon]];
|
||||
}
|
||||
}
|
||||
const aerialPath = isAllActiveView ? (activeStraightLeg || []) : buildTripPoints(sorted);
|
||||
|
||||
const isKitchenAerial = (viewMode === 'kitchens' || focusedKitchen);
|
||||
const path = roadPath || aerialPath;
|
||||
|
||||
Reference in New Issue
Block a user