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.
|
||||
// Falls back to the miler record itself (which may carry a last-known
|
||||
// position) if the logs call fails or returns nothing.
|
||||
// Despite the parameter name (kept for caller compatibility), this must be
|
||||
// a milerprofileid — /admin/milers/:id/* routes 404 on a plain userid
|
||||
// (confirmed live).
|
||||
export const getRiderPeriodicLogs = async (userid) => {
|
||||
if (!userid) return null;
|
||||
// Handles both milerprofileid and userid inputs by resolving via getMilers().
|
||||
export const getRiderPeriodicLogs = async (id) => {
|
||||
if (!id) return null;
|
||||
|
||||
let profileId = id;
|
||||
let milerObj = null;
|
||||
|
||||
// Resolve milerprofileid if a userid or generic id was passed
|
||||
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;
|
||||
if (latest) return latest;
|
||||
} catch {
|
||||
// Falls through to the getMiler() fallback below — this is polled every
|
||||
// 15s by the live map, so a toast here would spam the operator on every
|
||||
// failed tick. Only surface an error if the fallback also fails.
|
||||
if (latest && typeof latest === 'object' && Object.keys(latest).length > 0) {
|
||||
return {
|
||||
...milerObj,
|
||||
...latest,
|
||||
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) {
|
||||
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) ||============================== //
|
||||
|
||||
@@ -1113,7 +1113,9 @@ const Dispatch = ({
|
||||
// changing riderInfoUserid itself, which is compared against elsewhere
|
||||
// in this file for sidebar row highlighting in userid-space.
|
||||
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);
|
||||
},
|
||||
enabled: viewMode === 'rider-info' && riderInfoUserid != null,
|
||||
@@ -3055,11 +3057,9 @@ const Dispatch = ({
|
||||
const flagSvg = o.orderstatus
|
||||
? `<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"/>
|
||||
<polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="${
|
||||
statusStyle.bg
|
||||
<polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="${statusStyle.bg
|
||||
}" 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"/>'
|
||||
: ''
|
||||
}
|
||||
@@ -3075,10 +3075,8 @@ const Dispatch = ({
|
||||
iconSize: [sz, sz],
|
||||
iconAnchor: [sz / 2, sz / 2],
|
||||
popupAnchor: [0, -28],
|
||||
html: `<div class="cmark is-rider-focused${
|
||||
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 : ''
|
||||
html: `<div class="cmark is-rider-focused${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 : ''
|
||||
}${flagSvg}</div>`
|
||||
});
|
||||
})()
|
||||
@@ -3087,8 +3085,7 @@ const Dispatch = ({
|
||||
iconSize: [24, 30],
|
||||
iconAnchor: [2, 30],
|
||||
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:${
|
||||
active ? 1 : 0.75
|
||||
html: `<div class="cmark${isPulsing ? ' pulse' : ''}" style="width:24px;height:30px;opacity:${active ? 1 : 0.75
|
||||
}">${flagSvg}</div>`
|
||||
});
|
||||
|
||||
@@ -3455,24 +3452,21 @@ const Dispatch = ({
|
||||
setFocusedZone(null);
|
||||
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 ${
|
||||
isSelected
|
||||
className={`w-full flex items-center justify-between gap-3 px-2.5 py-2 rounded-lg text-left transition-colors cursor-pointer ${isSelected
|
||||
? 'bg-slate-900 text-white font-bold'
|
||||
: 'text-slate-700 hover:bg-slate-100/80 font-medium'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<span
|
||||
className={`w-2 h-2 rounded-full shrink-0 ${
|
||||
isSelected ? 'bg-emerald-400' : 'bg-slate-300'
|
||||
className={`w-2 h-2 rounded-full shrink-0 ${isSelected ? 'bg-emerald-400' : 'bg-slate-300'
|
||||
}`}
|
||||
/>
|
||||
<div className="min-w-0">
|
||||
<div className="text-xs truncate">{b.label}</div>
|
||||
{b.range && (
|
||||
<div
|
||||
className={`text-[10px] ${
|
||||
isSelected ? 'text-slate-300' : 'text-slate-400'
|
||||
className={`text-[10px] ${isSelected ? 'text-slate-300' : 'text-slate-400'
|
||||
}`}
|
||||
>
|
||||
{b.range}
|
||||
@@ -3481,8 +3475,7 @@ const Dispatch = ({
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-full shrink-0 ${
|
||||
isSelected
|
||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-full shrink-0 ${isSelected
|
||||
? 'bg-white/20 text-white'
|
||||
: count > 0
|
||||
? 'bg-amber-100 text-amber-800'
|
||||
@@ -4075,8 +4068,7 @@ const Dispatch = ({
|
||||
) : (
|
||||
<div
|
||||
id="body"
|
||||
className={`${sidebarCollapsed ? 'sidebar-collapsed' : ''} ${compareOpen ? 'compare-mode' : ''} ${
|
||||
compareOpen && compareDataCollapsed ? 'compare-data-collapsed' : ''
|
||||
className={`${sidebarCollapsed ? 'sidebar-collapsed' : ''} ${compareOpen ? 'compare-mode' : ''} ${compareOpen && compareDataCollapsed ? 'compare-data-collapsed' : ''
|
||||
}`.trim()}
|
||||
>
|
||||
<button
|
||||
@@ -4349,8 +4341,7 @@ const Dispatch = ({
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
||||
isGoingOn ? 'going-on' : ''
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||
} ${isUndeliveredInTimeMode ? 'is-pending-time' : ''}`}
|
||||
role={canFocus ? 'button' : undefined}
|
||||
tabIndex={canFocus ? 0 : undefined}
|
||||
@@ -4564,8 +4555,7 @@ const Dispatch = ({
|
||||
return (
|
||||
<div
|
||||
key={o.orderid}
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
||||
isGoingOn ? 'going-on' : ''
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||
}`}
|
||||
role={canFocus ? 'button' : undefined}
|
||||
tabIndex={canFocus ? 0 : undefined}
|
||||
@@ -4760,8 +4750,7 @@ const Dispatch = ({
|
||||
return (
|
||||
<div
|
||||
key={o.orderid}
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${
|
||||
isGoingOn ? 'going-on' : ''
|
||||
className={`zone-order-card ${canFocus ? 'clickable' : ''} ${isStopActive ? 'active' : ''} ${isGoingOn ? 'going-on' : ''
|
||||
}`}
|
||||
role={canFocus ? 'button' : undefined}
|
||||
tabIndex={canFocus ? 0 : undefined}
|
||||
|
||||
Reference in New Issue
Block a user