updates on the active section regarding the notifications
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useRef, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
MdTwoWheeler,
|
MdTwoWheeler,
|
||||||
MdLocationOn,
|
MdLocationOn,
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from 'react-icons/md';
|
} from 'react-icons/md';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { getStatusStyle, getActiveOrder } from './dispatchShared';
|
import { getStatusStyle, getActiveOrder } from './dispatchShared';
|
||||||
|
import { OpenToast } from 'components/third-party/OpenToast';
|
||||||
|
|
||||||
const ActiveSection = ({
|
const ActiveSection = ({
|
||||||
visibleRiders,
|
visibleRiders,
|
||||||
@@ -20,14 +21,55 @@ const ActiveSection = ({
|
|||||||
getRiderColor,
|
getRiderColor,
|
||||||
formatMeters
|
formatMeters
|
||||||
}) => {
|
}) => {
|
||||||
|
// Sort by live distance ascending (closest drop-off first; null/unknown last)
|
||||||
const activeDeliveries = visibleRiders
|
const activeDeliveries = visibleRiders
|
||||||
.map((r) => getActiveOrder(r.orders))
|
.map((r) => getActiveOrder(r.orders))
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.sort((a, b) =>
|
.sort((a, b) => {
|
||||||
String(a.rider_name || a.ridername || '').localeCompare(
|
const mA = calculateEstMeters(a.rider_id, a) ?? Infinity;
|
||||||
String(b.rider_name || b.ridername || '')
|
const mB = calculateEstMeters(b.rider_id, b) ?? Infinity;
|
||||||
)
|
return mA - mB;
|
||||||
);
|
});
|
||||||
|
|
||||||
|
// Toast notifications: detect status transitions across renders
|
||||||
|
const prevStatusMapRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const currentMap = {};
|
||||||
|
visibleRiders.forEach((r) => {
|
||||||
|
(r.orders || []).forEach((o) => {
|
||||||
|
currentMap[String(o.orderid)] = {
|
||||||
|
status: String(o.orderstatus || '').toLowerCase(),
|
||||||
|
riderName: o.rider_name || o.ridername || 'Rider',
|
||||||
|
customer: o.deliverycustomer || o.customername || `Order #${o.orderid}`
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const prev = prevStatusMapRef.current;
|
||||||
|
if (prev !== null) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
prevStatusMapRef.current = currentMap;
|
||||||
|
}, [visibleRiders]);
|
||||||
|
|
||||||
if (activeDeliveries.length === 0) {
|
if (activeDeliveries.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -78,11 +120,11 @@ const ActiveSection = ({
|
|||||||
<div className="adcard-top">
|
<div className="adcard-top">
|
||||||
<div className="adcard-avatar" style={{ background: color }}>{initials}</div>
|
<div className="adcard-avatar" style={{ background: color }}>{initials}</div>
|
||||||
<div className="adcard-titles">
|
<div className="adcard-titles">
|
||||||
<div className="adcard-customer" title={customer}>{customer}</div>
|
|
||||||
<div className="adcard-rider" title={riderName}>
|
<div className="adcard-rider" title={riderName}>
|
||||||
<MdTwoWheeler style={{ fontSize: 13, flexShrink: 0 }} />
|
<MdTwoWheeler style={{ fontSize: 13, flexShrink: 0 }} />
|
||||||
<span className="adcard-tx">{riderName}</span>
|
<span className="adcard-tx">{riderName}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="adcard-customer" title={customer}>{customer}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: '4px' }}>
|
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: '4px' }}>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -10810,9 +10810,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dispatch-container .adcard-customer {
|
.dispatch-container .adcard-customer {
|
||||||
font-size: 14.5px;
|
font-size: 12px;
|
||||||
font-weight: 700;
|
font-weight: 500;
|
||||||
color: var(--text);
|
color: #94a3b8;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -10822,9 +10822,9 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 4px;
|
gap: 4px;
|
||||||
color: var(--text-muted);
|
color: var(--text);
|
||||||
font-size: 12px;
|
font-size: 14.5px;
|
||||||
font-weight: 500;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dispatch-container .adcard-status {
|
.dispatch-container .adcard-status {
|
||||||
|
|||||||
Reference in New Issue
Block a user