updates on the dispatch page and redesigned the maximum pages
This commit is contained in:
@@ -184,10 +184,12 @@ export const gettenantlocations = async ({ queryKey }) => {
|
||||
const [, searchLocation] = queryKey;
|
||||
try {
|
||||
const response = await axios.get(`${process.env.REACT_APP_URL}/tenants/gettenantlocations?tenantid=${tenid}&keyword=${searchLocation}`);
|
||||
return response.data?.details || []; // safe fallback
|
||||
return response.data?.details || [];
|
||||
} catch (error) {
|
||||
// Must return an array — downstream consumers do `.map`/`.length` and a
|
||||
// string here crashes the entire Locations page.
|
||||
console.error('Error fetching tenant locations:', error);
|
||||
return error.message;
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -306,3 +308,126 @@ export const fetchRidersLogs = async ({ queryKey }) => {
|
||||
console.log('fetchRidersLogs', riderLogsResponse.data.details);
|
||||
return riderLogsResponse.data.details;
|
||||
};
|
||||
|
||||
// ==============================|| Dispatch / Preview APIs (ported from xpressconsole) ||============================== //
|
||||
|
||||
// Returns the rider's latest periodic log entry — battery, GPS, status,
|
||||
// current order. Used by the Rider Info modal on the Dispatch page.
|
||||
export const getRiderPeriodicLogs = async (userid) => {
|
||||
const url = `${process.env.REACT_APP_URL}/utils/getriderperiodiclogs${userid ? `?userid=${userid}` : ''}`;
|
||||
const response = await axios.get(url);
|
||||
if (response.data && response.data.status) return response.data.data;
|
||||
return null;
|
||||
};
|
||||
|
||||
// Fetches the riders dropdown list for an app location.
|
||||
export const fetchRidersList = async ({ queryKey }) => {
|
||||
try {
|
||||
const [, appId] = queryKey;
|
||||
const { data } = await axios.get(`${process.env.REACT_APP_URL}/partners/getriders/?applocationid=${appId}`);
|
||||
const response = data?.details
|
||||
? data.details.map((val) => ({
|
||||
...val,
|
||||
label: `${val.firstname} ${val.lastname} | ${val.contactno}`
|
||||
}))
|
||||
: [];
|
||||
return response;
|
||||
} catch (err) {
|
||||
OpenToast(err.message, 'error', 2000);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
// Optimise the orders (bike solver).
|
||||
export const createOptimisationDeliveries = async (deliveryData) => {
|
||||
const response = await axios.post(`https://routes.workolik.com/api/v1/optimization/createdeliveries`, deliveryData.deliveries);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Server-side step reconciliation after manual edits in Preview.
|
||||
export const reconcileSteps = async ({ riders }) => {
|
||||
const response = await axios.post(`https://routes.workolik.com/api/v1/optimization/reconcile-steps`, { riders });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Batch efficiency analysis — batch ∈ 'morning' | 'afternoon' | 'evening'.
|
||||
export const fetchBatchEfficiency = async ({ batch, tenantId }) => {
|
||||
const response = await axios.post(
|
||||
`https://routes.workolik.com/api/v1/batch/efficiency`,
|
||||
{ batch, tenant_id: tenantId },
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
validateStatus: () => true
|
||||
}
|
||||
);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Final commit of dispatched deliveries — coerces userid/rider_id to int at
|
||||
// the boundary so a string upstream can't cause a 500 unmarshal error.
|
||||
export const finalCreatedeliveries = async (deliveryData) => {
|
||||
const toInt = (v) => {
|
||||
const n = Number(v);
|
||||
return Number.isFinite(n) ? n : v;
|
||||
};
|
||||
const deliveries = (deliveryData.deliveries || []).map((d) => ({
|
||||
...d,
|
||||
userid: toInt(d.userid),
|
||||
rider_id: toInt(d.rider_id)
|
||||
}));
|
||||
const response = await axios.post(`https://jupiter.nearle.app/live/api/v1/deliveries/createdeliveries`, deliveries);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Auto rider assignment via either the bike solver or the auto/multi-trip
|
||||
// solver. Body shape differs per mode; absent_riders is merged through.
|
||||
export const createAutomationDeliveries = async (variables) => {
|
||||
const absentRiders = Array.isArray(variables.absent_riders) ? variables.absent_riders : [];
|
||||
|
||||
const url =
|
||||
variables.selectedMode.value == 1
|
||||
? `https://routes.workolik.com/api/v1/optimization/riderassign?hypertuning_params=${variables.hypertuning_params}`
|
||||
: `https://routemate.workolik.com/api/v1/optimization/riderassign?strategy=multi_trip`;
|
||||
|
||||
const body =
|
||||
variables.selectedMode.value == 1
|
||||
? { deliveries: variables.deliveries, absent_riders: absentRiders }
|
||||
: { ...(variables.data || {}), absent_riders: absentRiders };
|
||||
|
||||
const response = await axios.post(url, body);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Push a notification to a rider after assignment.
|
||||
export const notifyRider = async (riderToken) => {
|
||||
if (!riderToken) {
|
||||
throw new Error('Invalid rider token');
|
||||
}
|
||||
const response = await axios.post(`${process.env.REACT_APP_URL}/utils/notifyuser`, {
|
||||
token: riderToken,
|
||||
notification: {
|
||||
title: 'NearleXpress',
|
||||
body: 'Orders have been placed for delivery. Kindly accept and process deliveries',
|
||||
sound: 'ring',
|
||||
image: ''
|
||||
}
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Paginated deliveries fetch — supports both "All zones" (appId === 0) and
|
||||
// per-zone scoping. Returns { rows, nextPage } for useInfiniteQuery.
|
||||
export const fetchDeliveries = async ({ pageParam = 1, queryKey }) => {
|
||||
let [, appId, userid, currentStatus, startdate, enddate, rowsPerPage, searchword, tenantid, locationid, riderid] = queryKey;
|
||||
currentStatus = currentStatus == 'All' ? 'all' : currentStatus;
|
||||
const url =
|
||||
appId === 0
|
||||
? `${process.env.REACT_APP_URL}/deliveries/getdeliveries/?appuserid=${userid}&status=${currentStatus}&fromdate=${startdate}&todate=${enddate}&pageno=${pageParam}&pagesize=${rowsPerPage}&keyword=${searchword}&tenantid=${tenantid}&locationid=${locationid}&userid=${riderid}`
|
||||
: `${process.env.REACT_APP_URL}/deliveries/getdeliveries/?applocationid=${appId}&status=${currentStatus}&fromdate=${startdate}&todate=${enddate}&pageno=${pageParam}&pagesize=${rowsPerPage}&keyword=${searchword}&tenantid=${tenantid}&locationid=${locationid}&userid=${riderid}`;
|
||||
const response = await axios.get(url);
|
||||
|
||||
return {
|
||||
rows: response.data.details,
|
||||
nextPage: response.data.details.length === Number(rowsPerPage) ? pageParam + 1 : undefined
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user