updates on the api integration and the design changes on the whole website
This commit is contained in:
@@ -68,7 +68,7 @@ import { MobileCard, MobileCardList, MobileField, MobileFieldGrid } from 'compon
|
||||
import DebounceSearchBar from 'components/nearle_components/DebounceSearchBar';
|
||||
import CircularLoader from 'components/CircularLoader';
|
||||
import { fetchAllRiders, getallridersummary } from 'pages/api/api';
|
||||
import { getMilers, blockMiler, assignMilerVehicle, getVehicles } from 'pages/api/doormileApi';
|
||||
import { getMilers, blockMiler, assignMilerVehicle, getVehicles, getMilerLogs, getMiler } from 'pages/api/doormileApi';
|
||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import LoaderWithImage from 'components/nearle_components/LoaderWithImage';
|
||||
import { OrdersTableSkeleton } from '../orders/OrdersTableSkeleton';
|
||||
@@ -144,6 +144,10 @@ const STATUS_META = {
|
||||
available: { label: 'Available', color: '#10b981', icon: MdCheckCircle },
|
||||
assigned: { label: 'Assigned', color: '#6366f1', icon: MdTwoWheeler },
|
||||
on_pickup: { label: 'On Pickup', color: '#14b8a6', icon: MdTwoWheeler },
|
||||
// Confirmed live: PUT /admin/milers/:id/block sets availabilitystatus to
|
||||
// "Blocked" — a value this map didn't have, so a blocked rider fell
|
||||
// through to "unknown" instead of clearly reading as blocked.
|
||||
blocked: { label: 'Blocked', color: '#7f1d1d', icon: MdBlock },
|
||||
idle: { label: 'Idle', color: '#f59e0b', icon: MdAccessTime },
|
||||
unknown: { label: 'Unknown', color: '#94a3b8', icon: MdInventory2 }
|
||||
};
|
||||
@@ -178,7 +182,7 @@ const Riders = () => {
|
||||
const roleid = localStorage.getItem('roleid');
|
||||
const totalCols = roleid == 1 ? 11 : 10;
|
||||
const [logsRow, setLogsRow] = useState(null);
|
||||
const [riderLogsdata] = useState(null);
|
||||
const [riderLogsdata, setRiderLogsdata] = useState(null);
|
||||
const [historyDate, setHistoryDate] = useState(dayjs());
|
||||
const [historyStatus, setHistoryStatus] = useState('all');
|
||||
const [selectedDate, setSelectedDate] = useState(dayjs());
|
||||
@@ -281,10 +285,37 @@ const Riders = () => {
|
||||
});
|
||||
|
||||
// ==============================|| getRiderLogs (riders)||============================== //
|
||||
// No live GPS/battery/periodic-log endpoint in the new API — the expanded
|
||||
// row still opens, showing the panel's built-in "—" placeholders.
|
||||
const getRiderLogs = async () => {
|
||||
OpenToast('Live rider logs are not available on the Doormile Express API yet.', 'warning', 2500);
|
||||
// GET /admin/milers/:id/logs is confirmed live (Status: Done) — id is
|
||||
// milerprofileid, not userid. A log entry's own field names are still
|
||||
// unconfirmed (every rider in the tenant we tested against had an empty
|
||||
// log history), so this falls back to the miler's own last-known position
|
||||
// (currentlatitude/currentlongitude/lastlocationupdatedat/
|
||||
// availabilitystatus — all confirmed fields) when there's no ping yet,
|
||||
// rather than showing nothing.
|
||||
const getRiderLogs = async (milerprofileid) => {
|
||||
if (!milerprofileid) return;
|
||||
setRiderLogsdata(null);
|
||||
try {
|
||||
const logs = await getMilerLogs(milerprofileid, undefined, undefined, 1);
|
||||
const latest = Array.isArray(logs) ? logs[0] : null;
|
||||
if (latest) {
|
||||
setRiderLogsdata(latest);
|
||||
} else {
|
||||
const miler = await getMiler(milerprofileid);
|
||||
setRiderLogsdata(
|
||||
miler
|
||||
? {
|
||||
latitude: miler.currentlatitude,
|
||||
longitude: miler.currentlongitude,
|
||||
logdate: miler.lastlocationupdatedat || miler.lastpingat,
|
||||
status: miler.availabilitystatus
|
||||
}
|
||||
: null
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
OpenToast('Could not load rider logs', 'error', 2000);
|
||||
}
|
||||
};
|
||||
|
||||
// ==============================|| fetchAllRiders||============================== //
|
||||
@@ -312,8 +343,10 @@ const Riders = () => {
|
||||
// no-ops until filtered client-side here.
|
||||
const filteredRows = rows.filter((row) => {
|
||||
// "Active" here means currently online/working (Available/Assigned/
|
||||
// On_Pickup) — the only real "not working" state is Offline.
|
||||
if (tabvalue === 1 && String(row.availabilitystatus || '').toLowerCase() === 'offline') return false;
|
||||
// On_Pickup) — Offline and Blocked (confirmed live enum) both mean not
|
||||
// working.
|
||||
const status = String(row.availabilitystatus || '').toLowerCase();
|
||||
if (tabvalue === 1 && (status === 'offline' || status === 'blocked')) return false;
|
||||
if (!debouncedSearch) return true;
|
||||
const q = debouncedSearch.toLowerCase();
|
||||
return [row.displayname, row.phone].some((v) => String(v || '').toLowerCase().includes(q));
|
||||
@@ -992,7 +1025,7 @@ const Riders = () => {
|
||||
filteredRows?.map((row, index) => {
|
||||
const statusMeta = getRowStatusMeta(row);
|
||||
const StatusIcon = statusMeta.icon;
|
||||
const expanded = logsRow === row.userid;
|
||||
const expanded = logsRow === row.milerprofileid;
|
||||
return (
|
||||
<MobileCard
|
||||
key={row.userid ?? index}
|
||||
@@ -1099,11 +1132,11 @@ const Riders = () => {
|
||||
'&:hover': { bgcolor: '#0ea5e9', color: '#fff' }
|
||||
}}
|
||||
onClick={() => {
|
||||
if (row.userid == logsRow) {
|
||||
if (row.milerprofileid == logsRow) {
|
||||
setLogsRow(null);
|
||||
} else {
|
||||
setLogsRow(row.userid);
|
||||
getRiderLogs(row.userid);
|
||||
setLogsRow(row.milerprofileid);
|
||||
getRiderLogs(row.milerprofileid);
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -1343,7 +1376,7 @@ const Riders = () => {
|
||||
filteredRows?.map((row, index) => {
|
||||
const statusMeta = getRowStatusMeta(row);
|
||||
const StatusIcon = statusMeta.icon;
|
||||
const expanded = logsRow === row.userid;
|
||||
const expanded = logsRow === row.milerprofileid;
|
||||
return (
|
||||
<Fragment key={row.userid ?? index}>
|
||||
<TableRow
|
||||
@@ -1570,11 +1603,11 @@ const Riders = () => {
|
||||
'&:hover': { bgcolor: '#0ea5e9', color: '#fff' }
|
||||
}}
|
||||
onClick={() => {
|
||||
if (row.userid == logsRow) {
|
||||
if (row.milerprofileid == logsRow) {
|
||||
setLogsRow(null);
|
||||
} else {
|
||||
setLogsRow(row.userid);
|
||||
getRiderLogs(row.userid);
|
||||
setLogsRow(row.milerprofileid);
|
||||
getRiderLogs(row.milerprofileid);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user