updates on the active section and the dispatch page section regarding the active order details

This commit is contained in:
2026-06-26 16:43:19 +05:30
parent 76c8e5062d
commit 848d1874fa
2 changed files with 193 additions and 178 deletions

View File

@@ -26,9 +26,7 @@ const ActiveSection = ({
}) => { }) => {
// Sort by live distance ascending (closest drop-off first; null/unknown last) // Sort by live distance ascending (closest drop-off first; null/unknown last)
const activeDeliveries = visibleRiders const activeDeliveries = visibleRiders
.map((r) => getActiveOrder(r.orders)) .flatMap((r) => (r.orders || []).filter((o) => String(o.orderstatus || '').toLowerCase() === 'active'))
.filter(Boolean)
.filter((o) => String(o.orderstatus || '').toLowerCase() === 'active')
.sort((a, b) => { .sort((a, b) => {
const mA = calculateEstMeters(a.rider_id || a.userid, a) ?? Infinity; const mA = calculateEstMeters(a.rider_id || a.userid, a) ?? Infinity;
const mB = calculateEstMeters(b.rider_id || b.userid, b) ?? Infinity; const mB = calculateEstMeters(b.rider_id || b.userid, b) ?? Infinity;

View File

@@ -1304,7 +1304,7 @@ const Dispatch = ({
hasNextPage: liveHasNextPage, hasNextPage: liveHasNextPage,
isFetchingNextPage: liveIsFetchingNextPage isFetchingNextPage: liveIsFetchingNextPage
} = useInfiniteQuery({ } = 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, queryFn: fetchDeliveries,
getNextPageParam: (lastPage) => lastPage.nextPage ?? undefined, getNextPageParam: (lastPage) => lastPage.nextPage ?? undefined,
enabled: shouldFetchLive, enabled: shouldFetchLive,
@@ -1578,10 +1578,8 @@ const Dispatch = ({
// excluded here. Every other view (By Location / By Zone / By Rider) is // excluded here. Every other view (By Location / By Zone / By Rider) is
// unchanged. // unchanged.
const isAllActiveView = viewMode === 'all'; 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( 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] [isAllActiveView, allOrders, activeRiderIdSet]
); );
// The single gate for the whole Active view: rider ids that are GPS-active AND // The single gate for the whole Active view: rider ids that are GPS-active AND
@@ -1592,8 +1590,8 @@ const Dispatch = ({
() => () =>
new Set( new Set(
(isAllActiveView ? allViewOrders : []) (isAllActiveView ? allViewOrders : [])
.filter(isActiveDelivery) .filter((o) => String(o?.orderstatus || '').toLowerCase() === 'active')
.map((o) => String(o.rider_id)) .map((o) => String(o.rider_id || o.userid || ''))
), ),
[isAllActiveView, allViewOrders] [isAllActiveView, allViewOrders]
); );
@@ -2305,8 +2303,12 @@ const Dispatch = ({
if (focusedRider && focusedRider.id !== r.id) return; if (focusedRider && focusedRider.id !== r.id) return;
if (focusedKitchen && !focusedKitchen.riders.has(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 = {}; const trips = {};
r.orders.forEach(o => { rOrders.forEach(o => {
const t = o.trip_number || 1; const t = o.trip_number || 1;
if (!trips[t]) trips[t] = []; if (!trips[t]) trips[t] = [];
trips[t].push(o); trips[t].push(o);
@@ -2320,12 +2322,27 @@ const Dispatch = ({
if (filteredTOrders.length === 0) return; 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 roadPath = osrmRoutes[cacheKey];
const sorted = [...filteredTOrders].sort((a, b) => (a.step || 0) - (b.step || 0)); const sorted = [...filteredTOrders].sort((a, b) => (a.step || 0) - (b.step || 0));
// Aerial fallback — NaN-safe build // Aerial fallback
const aerialPath = buildTripPoints(sorted); 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 isKitchenAerial = (viewMode === 'kitchens' || focusedKitchen);
const path = roadPath || aerialPath; const path = roadPath || aerialPath;