This commit is contained in:
@@ -205,21 +205,42 @@ const RouteView = () => {
|
||||
}
|
||||
return;
|
||||
}
|
||||
const dateArr = moment(currentRoute.schedule_date)?.format('MM/DD/YYYY')?.split('/') || [];
|
||||
const month = dateArr[0];
|
||||
const day = dateArr[1];
|
||||
const routeId = currentRoute.id;
|
||||
const toDateTokens = (dateValue) => {
|
||||
const tokenSet = new Set();
|
||||
const localFormatted = moment(dateValue)?.format('MM/DD/YYYY');
|
||||
const utcFormatted = moment.utc(dateValue)?.format('MM/DD/YYYY');
|
||||
[localFormatted, utcFormatted].forEach((formatted) => {
|
||||
if (!formatted || formatted.toLowerCase().includes('invalid')) return;
|
||||
const [month, day] = formatted.split('/');
|
||||
if (month && day) {
|
||||
tokenSet.add(`${month}_${day}`);
|
||||
}
|
||||
});
|
||||
return Array.from(tokenSet).map((token) => token.split('_'));
|
||||
};
|
||||
|
||||
const tryLoadSignature = async (driverIds = []) => {
|
||||
const tryLoadSignature = async (driverIds = [], dateValues = []) => {
|
||||
const uniqueDriverIds = Array.from(new Set((driverIds || []).filter(Boolean)));
|
||||
const datePairs = [];
|
||||
(dateValues || []).forEach((dateValue) => {
|
||||
toDateTokens(dateValue).forEach((pair) => datePairs.push(pair));
|
||||
});
|
||||
if (datePairs.length === 0) {
|
||||
toDateTokens(currentRoute.schedule_date).forEach((pair) => datePairs.push(pair));
|
||||
}
|
||||
const uniqueDatePairs = Array.from(new Set(datePairs.map((pair) => `${pair[0]}_${pair[1]}`)))
|
||||
.map((token) => token.split('_'));
|
||||
for (const driverId of uniqueDriverIds) {
|
||||
try {
|
||||
const data = await CustomerService.getAvatar(`${routeId}_${driverId}_${month}_${day}`);
|
||||
if (data?.data) {
|
||||
return data.data;
|
||||
for (const [month, day] of uniqueDatePairs) {
|
||||
try {
|
||||
const data = await CustomerService.getAvatar(`${routeId}_${driverId}_${month}_${day}`);
|
||||
if (data?.data) {
|
||||
return data.data;
|
||||
}
|
||||
} catch (error) {
|
||||
// Try next candidate key.
|
||||
}
|
||||
} catch (error) {
|
||||
// Try next candidate key.
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
@@ -229,6 +250,8 @@ const RouteView = () => {
|
||||
resolvedDriverId,
|
||||
currentRoute?.driver,
|
||||
routeSnapshot?.driver
|
||||
], [
|
||||
currentRoute?.schedule_date
|
||||
]);
|
||||
if (isMounted) {
|
||||
setSignature(initialSignature);
|
||||
@@ -236,15 +259,17 @@ const RouteView = () => {
|
||||
|
||||
try {
|
||||
const requestRes = await SignatureRequestService.getAllSignatureRequests({
|
||||
route_id: routeId,
|
||||
route_date: currentRoute.schedule_date
|
||||
route_id: routeId
|
||||
});
|
||||
const firstRequest = requestRes?.data?.[0];
|
||||
const requestList = requestRes?.data || [];
|
||||
const firstRequest = requestList[0];
|
||||
if (isMounted) {
|
||||
setSignatureRequest(firstRequest);
|
||||
}
|
||||
if (!initialSignature && firstRequest?.driver_id) {
|
||||
const signatureFromRequestDriver = await tryLoadSignature([firstRequest.driver_id]);
|
||||
if (!initialSignature) {
|
||||
const requestDriverIds = requestList.map((item) => item?.driver_id).filter(Boolean);
|
||||
const requestDates = requestList.map((item) => item?.route_date).filter(Boolean);
|
||||
const signatureFromRequestDriver = await tryLoadSignature(requestDriverIds, requestDates);
|
||||
if (isMounted) {
|
||||
setSignature(signatureFromRequestDriver);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,11 @@ const deleteClient = (id, data) => {
|
||||
}
|
||||
|
||||
const uploadAvatar = (filename, data) => {
|
||||
return http.post(`/files/upload/${filename}`, data)
|
||||
const safeFilename = `${filename || ''}`.trim();
|
||||
if (!safeFilename || safeFilename.includes('undefined') || safeFilename.includes('null')) {
|
||||
throw new Error('Invalid upload filename for avatar/signature.');
|
||||
}
|
||||
return http.post(`/files/upload/${encodeURIComponent(safeFilename)}`, data)
|
||||
}
|
||||
|
||||
const getAvatar = (filename) => {
|
||||
|
||||
Reference in New Issue
Block a user