updates on the build regarding the queries page and the dispatch page
This commit is contained in:
@@ -212,25 +212,70 @@ const haversineKm = (lat1, lon1, lat2, lon2) => {
|
|||||||
// page's own optional-chaining render whatever fields actually come back.
|
// page's own optional-chaining render whatever fields actually come back.
|
||||||
// Falls back to the miler record itself (which may carry a last-known
|
// Falls back to the miler record itself (which may carry a last-known
|
||||||
// position) if the logs call fails or returns nothing.
|
// position) if the logs call fails or returns nothing.
|
||||||
// Despite the parameter name (kept for caller compatibility), this must be
|
// Handles both milerprofileid and userid inputs by resolving via getMilers().
|
||||||
// a milerprofileid — /admin/milers/:id/* routes 404 on a plain userid
|
export const getRiderPeriodicLogs = async (id) => {
|
||||||
// (confirmed live).
|
if (!id) return null;
|
||||||
export const getRiderPeriodicLogs = async (userid) => {
|
|
||||||
if (!userid) return null;
|
let profileId = id;
|
||||||
|
let milerObj = null;
|
||||||
|
|
||||||
|
// Resolve milerprofileid if a userid or generic id was passed
|
||||||
try {
|
try {
|
||||||
const logs = await getMilerLogs(userid, undefined, undefined, 1);
|
const milers = await getMilers();
|
||||||
|
const found = (milers || []).find(
|
||||||
|
(m) =>
|
||||||
|
String(m.milerprofileid) === String(id) ||
|
||||||
|
String(m.userid) === String(id) ||
|
||||||
|
String(m.milerid) === String(id) ||
|
||||||
|
String(m.id) === String(id)
|
||||||
|
);
|
||||||
|
if (found) {
|
||||||
|
profileId = found.milerprofileid || found.id || id;
|
||||||
|
milerObj = found;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.debug('getRiderPeriodicLogs: milers lookup fallback', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Fetch the latest log via /admin/milers/:profileId/logs?limit=1
|
||||||
|
try {
|
||||||
|
const logs = await getMilerLogs(profileId, undefined, undefined, 1);
|
||||||
const latest = Array.isArray(logs) ? logs[0] : logs;
|
const latest = Array.isArray(logs) ? logs[0] : logs;
|
||||||
if (latest) return latest;
|
if (latest && typeof latest === 'object' && Object.keys(latest).length > 0) {
|
||||||
} catch {
|
return {
|
||||||
// Falls through to the getMiler() fallback below — this is polled every
|
...milerObj,
|
||||||
// 15s by the live map, so a toast here would spam the operator on every
|
...latest,
|
||||||
// failed tick. Only surface an error if the fallback also fails.
|
userid: latest.userid ?? milerObj?.userid ?? id,
|
||||||
|
username:
|
||||||
|
(latest.username && latest.username.trim()) ||
|
||||||
|
milerObj?.displayname ||
|
||||||
|
milerObj?.name ||
|
||||||
|
(latest.userid ? `Rider #${latest.userid}` : `Rider #${id}`)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return (await getMiler(userid)) || null;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
logger.debug(`getRiderPeriodicLogs: getMilerLogs failed for profileId ${profileId}`, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Fallback to /admin/milers/:profileId if no logs or logs call failed
|
||||||
|
try {
|
||||||
|
const miler = milerObj || (await getMiler(profileId));
|
||||||
|
if (miler) {
|
||||||
|
return {
|
||||||
|
...miler,
|
||||||
|
userid: miler.userid ?? id,
|
||||||
|
username: miler.displayname || miler.name || miler.authname || `Rider #${miler.userid ?? id}`,
|
||||||
|
latitude: miler.currentlatitude ?? miler.latitude,
|
||||||
|
longitude: miler.currentlongitude ?? miler.longitude,
|
||||||
|
status: miler.availabilitystatus ?? miler.status ?? 'offline',
|
||||||
|
logdate: miler.lastpingat ?? miler.updatedat ?? miler.createdat
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.debug(`getRiderPeriodicLogs: getMiler fallback failed for profileId ${profileId}`, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ==============================|| fetchAppLocations (zone/location picker) ||============================== //
|
// ==============================|| fetchAppLocations (zone/location picker) ||============================== //
|
||||||
|
|||||||
@@ -1113,7 +1113,9 @@ const Dispatch = ({
|
|||||||
// changing riderInfoUserid itself, which is compared against elsewhere
|
// changing riderInfoUserid itself, which is compared against elsewhere
|
||||||
// in this file for sidebar row highlighting in userid-space.
|
// in this file for sidebar row highlighting in userid-space.
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
const match = liveRiderLocations.find((r) => String(r.userid) === String(riderInfoUserid));
|
const match =
|
||||||
|
liveRiderLocations.find((r) => String(r.userid) === String(riderInfoUserid) || String(r.milerprofileid) === String(riderInfoUserid)) ||
|
||||||
|
(ridersList || []).find((r) => String(r.userid) === String(riderInfoUserid) || String(r.milerprofileid) === String(riderInfoUserid));
|
||||||
return getRiderPeriodicLogs(match?.milerprofileid ?? riderInfoUserid);
|
return getRiderPeriodicLogs(match?.milerprofileid ?? riderInfoUserid);
|
||||||
},
|
},
|
||||||
enabled: viewMode === 'rider-info' && riderInfoUserid != null,
|
enabled: viewMode === 'rider-info' && riderInfoUserid != null,
|
||||||
@@ -3055,11 +3057,9 @@ const Dispatch = ({
|
|||||||
const flagSvg = o.orderstatus
|
const flagSvg = o.orderstatus
|
||||||
? `<svg class="cmark-flag" viewBox="0 0 18 22" xmlns="http://www.w3.org/2000/svg">
|
? `<svg class="cmark-flag" viewBox="0 0 18 22" xmlns="http://www.w3.org/2000/svg">
|
||||||
<line x1="1.5" y1="0" x2="1.5" y2="22" stroke="#0f172a" stroke-width="1.6" stroke-linecap="round"/>
|
<line x1="1.5" y1="0" x2="1.5" y2="22" stroke="#0f172a" stroke-width="1.6" stroke-linecap="round"/>
|
||||||
<polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="${
|
<polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="${statusStyle.bg
|
||||||
statusStyle.bg
|
|
||||||
}" stroke="#0f172a" stroke-width="0.6" stroke-linejoin="round"/>
|
}" stroke="#0f172a" stroke-width="0.6" stroke-linejoin="round"/>
|
||||||
${
|
${isDelivered
|
||||||
isDelivered
|
|
||||||
? '<polyline points="5,5.5 7,7.5 11,3.5" fill="none" stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>'
|
? '<polyline points="5,5.5 7,7.5 11,3.5" fill="none" stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>'
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
@@ -3075,10 +3075,8 @@ const Dispatch = ({
|
|||||||
iconSize: [sz, sz],
|
iconSize: [sz, sz],
|
||||||
iconAnchor: [sz / 2, sz / 2],
|
iconAnchor: [sz / 2, sz / 2],
|
||||||
popupAnchor: [0, -28],
|
popupAnchor: [0, -28],
|
||||||
html: `<div class="cmark is-rider-focused${
|
html: `<div class="cmark is-rider-focused${isPulsing ? ' pulse' : ''
|
||||||
isPulsing ? ' pulse' : ''
|
}" style="background:${color};width:${sz}px;height:${sz}px;font-size:${seq > 9 ? 12 : 14}px;opacity:${active ? 1 : 0.75}">${seq > 0 ? seq : ''
|
||||||
}" style="background:${color};width:${sz}px;height:${sz}px;font-size:${seq > 9 ? 12 : 14}px;opacity:${active ? 1 : 0.75}">${
|
|
||||||
seq > 0 ? seq : ''
|
|
||||||
}${flagSvg}</div>`
|
}${flagSvg}</div>`
|
||||||
});
|
});
|
||||||
})()
|
})()
|
||||||
@@ -3087,8 +3085,7 @@ const Dispatch = ({
|
|||||||
iconSize: [24, 30],
|
iconSize: [24, 30],
|
||||||
iconAnchor: [2, 30],
|
iconAnchor: [2, 30],
|
||||||
popupAnchor: [10, -25], // Lift popup above the flag, not just the larger 32px marker
|
popupAnchor: [10, -25], // Lift popup above the flag, not just the larger 32px marker
|
||||||
html: `<div class="cmark${isPulsing ? ' pulse' : ''}" style="width:24px;height:30px;opacity:${
|
html: `<div class="cmark${isPulsing ? ' pulse' : ''}" style="width:24px;height:30px;opacity:${active ? 1 : 0.75
|
||||||
active ? 1 : 0.75
|
|
||||||
}">${flagSvg}</div>`
|
}">${flagSvg}</div>`
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3455,24 +3452,21 @@ const Dispatch = ({
|
|||||||
setFocusedZone(null);
|
setFocusedZone(null);
|
||||||
setBatchMenuOpen(false);
|
setBatchMenuOpen(false);
|
||||||
}}
|
}}
|
||||||
className={`w-full flex items-center justify-between gap-3 px-2.5 py-2 rounded-lg text-left transition-colors cursor-pointer ${
|
className={`w-full flex items-center justify-between gap-3 px-2.5 py-2 rounded-lg text-left transition-colors cursor-pointer ${isSelected
|
||||||
isSelected
|
|
||||||
? 'bg-slate-900 text-white font-bold'
|
? 'bg-slate-900 text-white font-bold'
|
||||||
: 'text-slate-700 hover:bg-slate-100/80 font-medium'
|
: 'text-slate-700 hover:bg-slate-100/80 font-medium'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2.5 min-w-0">
|
<div className="flex items-center gap-2.5 min-w-0">
|
||||||
<span
|
<span
|
||||||
className={`w-2 h-2 rounded-full shrink-0 ${
|
className={`w-2 h-2 rounded-full shrink-0 ${isSelected ? 'bg-emerald-400' : 'bg-slate-300'
|
||||||
isSelected ? 'bg-emerald-400' : 'bg-slate-300'
|
|
||||||
}`}
|
}`}
|
||||||
/>
|
/>
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<div className="text-xs truncate">{b.label}</div>
|
<div className="text-xs truncate">{b.label}</div>
|
||||||
{b.range && (
|
{b.range && (
|
||||||
<div
|
<div
|
||||||
className={`text-[10px] ${
|
className={`text-[10px] ${isSelected ? 'text-slate-300' : 'text-slate-400'
|
||||||
isSelected ? 'text-slate-300' : 'text-slate-400'
|
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{b.range}
|
{b.range}
|
||||||
@@ -3481,8 +3475,7 @@ const Dispatch = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span
|
<span
|
||||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-full shrink-0 ${
|
className={`text-[10px] font-bold px-2 py-0.5 rounded-full shrink-0 ${isSelected
|
||||||
isSelected
|
|
||||||
? 'bg-white/20 text-white'
|
? 'bg-white/20 text-white'
|
||||||
: count > 0
|
: count > 0
|
||||||
? 'bg-amber-100 text-amber-800'
|
? 'bg-amber-100 text-amber-800'
|
||||||
@@ -4075,8 +4068,7 @@ const Dispatch = ({
|
|||||||
) : (
|
) : (
|
||||||
<div
|
<div
|
||||||
id="body"
|
id="body"
|
||||||
className={`${sidebarCollapsed ? 'sidebar-collapsed' : ''} ${compareOpen ? 'compare-mode' : ''} ${
|
className={`${sidebarCollapsed ? 'sidebar-collapsed' : ''} ${compareOpen ? 'compare-mode' : ''} ${compareOpen && compareDataCollapsed ? 'compare-data-collapsed' : ''
|
||||||
compareOpen && compareDataCollapsed ? 'compare-data-collapsed' : ''
|
|
||||||
}`.trim()}
|
}`.trim()}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@@ -4349,8 +4341,7 @@ const Dispatch = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||||
isGoingOn ? 'going-on' : ''
|
|
||||||
} ${isUndeliveredInTimeMode ? 'is-pending-time' : ''}`}
|
} ${isUndeliveredInTimeMode ? 'is-pending-time' : ''}`}
|
||||||
role={canFocus ? 'button' : undefined}
|
role={canFocus ? 'button' : undefined}
|
||||||
tabIndex={canFocus ? 0 : undefined}
|
tabIndex={canFocus ? 0 : undefined}
|
||||||
@@ -4564,8 +4555,7 @@ const Dispatch = ({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={o.orderid}
|
key={o.orderid}
|
||||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||||
isGoingOn ? 'going-on' : ''
|
|
||||||
}`}
|
}`}
|
||||||
role={canFocus ? 'button' : undefined}
|
role={canFocus ? 'button' : undefined}
|
||||||
tabIndex={canFocus ? 0 : undefined}
|
tabIndex={canFocus ? 0 : undefined}
|
||||||
@@ -4760,8 +4750,7 @@ const Dispatch = ({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={o.orderid}
|
key={o.orderid}
|
||||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||||
isGoingOn ? 'going-on' : ''
|
|
||||||
}`}
|
}`}
|
||||||
role={canFocus ? 'button' : undefined}
|
role={canFocus ? 'button' : undefined}
|
||||||
tabIndex={canFocus ? 0 : undefined}
|
tabIndex={canFocus ? 0 : undefined}
|
||||||
|
|||||||
Reference in New Issue
Block a user