diff --git a/client/src/App.js b/client/src/App.js index 1044c36..4c0220e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -11,7 +11,6 @@ import TransRoutes from './components/trans-routes/TransRoutes'; import RoutesDashboard from "./components/trans-routes/RoutesDashboard"; import RouteView from "./components/trans-routes/RouteView"; import RouteEdit from "./components/trans-routes/RouteEdit"; -import RoutesSchedule from "./components/trans-routes/RoutesSchedule"; import CreateVehicle from "./components/vehicles/CreateVehicle"; import UpdateVehicle from "./components/vehicles/UpdateVehicle"; import AddVehicleInspection from "./components/vehicles/AddVehicleInspection"; @@ -211,7 +210,7 @@ function App() { } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/client/src/components/trans-routes/RouteReportWithSignature.js b/client/src/components/trans-routes/RouteReportWithSignature.js index 5aac580..ab2a01d 100644 --- a/client/src/components/trans-routes/RouteReportWithSignature.js +++ b/client/src/components/trans-routes/RouteReportWithSignature.js @@ -24,7 +24,6 @@ const RouteReportWithSignature = () => { const [directorSignature, setDirectorSignature] = useState(undefined); const [customerMetaById, setCustomerMetaById] = useState(new Map()); - const [customerMetaByName, setCustomerMetaByName] = useState(new Map()); const site = EventsService.site; @@ -130,28 +129,17 @@ const RouteReportWithSignature = () => { CustomerService.getAllCustomers() .then((res) => { const nextMap = new Map(); - const nextByNameMap = new Map(); (res?.data || []).forEach((customer) => { const meta = { program_type: customer?.program_type || '', - pay_source: customer?.pay_source || '', - notes_for_driver: customer?.notes_for_driver || '' + pay_source: customer?.pay_source || '' }; nextMap.set(customer?.id, meta); - const nameKey = (customer?.name || '').toString().trim().toLowerCase(); - if (nameKey) { - const previous = nextByNameMap.get(nameKey); - if (!previous || (customer?.status || '').toString().toLowerCase() === 'active') { - nextByNameMap.set(nameKey, meta); - } - } }); setCustomerMetaById(nextMap); - setCustomerMetaByName(nextByNameMap); }) .catch(() => { setCustomerMetaById(new Map()); - setCustomerMetaByName(new Map()); }); }, []); const normalizeChecklistText = (value = '') => @@ -243,12 +231,11 @@ const RouteReportWithSignature = () => { return { y: '', n: '✗' }; }; - const getRouteNoteToDriverText = (customerId, ...customerCandidates) => { - const profileNote = (customerMetaById.get(customerId)?.notes_for_driver || '').toString().trim(); - if (profileNote) return profileNote; - const firstCustomerName = (customerCandidates?.[0]?.customer_name || '').toString().trim().toLowerCase(); - const profileNoteByName = (customerMetaByName.get(firstCustomerName)?.notes_for_driver || '').toString().trim(); - if (profileNoteByName) return profileNoteByName; + const getTransferToRouteText = (...customerCandidates) => { + for (const customerCandidate of customerCandidates) { + const transferToRoute = (customerCandidate?.customer_transfer_to_route || '').toString().trim(); + if (transferToRoute) return transferToRoute; + } return ''; }; @@ -378,7 +365,7 @@ const RouteReportWithSignature = () => { const customerInOtherRoute = otherRouteWithThisCustomer?.route_customer_list?.find(cust => cust?.customer_id === customer?.customer_id); const otherOutboundRoute = getOtherOutboundRouteWithThisCustomer(customer?.customer_id); const attendanceDisplay = getAttendanceDisplayByReportLogic(customer, relativeRouteCustomer, customerInOtherRoute); - const routeNoteText = getRouteNoteToDriverText(customer?.customer_id, customer, relativeRouteCustomer, customerInOtherRoute); + const routeTransferToRouteText = getTransferToRouteText(customer, relativeRouteCustomer, customerInOtherRoute); return ( @@ -426,7 +413,7 @@ const RouteReportWithSignature = () => { : ''))} - {routeNoteText &&
{routeNoteText}
} + {routeTransferToRouteText &&
{routeTransferToRouteText}
} {customer?.customer_type !== CUSTOMER_TYPE.MEMBER &&
{CUSTOMER_TYPE_TEXT[customer?.customer_type]}
} {!relativeRouteCustomer && otherRouteWithThisCustomer && (
{`${currentRoute?.type === 'inbound' ? 'Switch to Route ' : 'Switch from Route '} ${otherRouteWithThisCustomer?.name}`}
diff --git a/client/src/components/trans-routes/RoutesDashboard.js b/client/src/components/trans-routes/RoutesDashboard.js index fe48e5b..84f5739 100644 --- a/client/src/components/trans-routes/RoutesDashboard.js +++ b/client/src/components/trans-routes/RoutesDashboard.js @@ -1024,19 +1024,29 @@ const RoutesDashboard = () => { // setSelectedDriver(undefined); } - const cleanupSchedule = () => { - const routesToDelete = deleteRouteType === 'inbound' - ? (tmrInboundRoutes || []) - : deleteRouteType === 'outbound' - ? (tmrOutboundRoutes || []) - : (allTomorrowRoutes || []); - routesToDelete.forEach((route) => { - TransRoutesService.deleteRoute(route.id); + const cleanupSchedule = async () => { + const routesToDelete = (routesForShowing || []).filter((route) => { + if (deleteRouteType === 'inbound') return route?.type === 'inbound'; + if (deleteRouteType === 'outbound') return route?.type === 'outbound'; + return true; }); - setTimeout(() => { - closeDeleteModal(); - window.location.reload(); - }, 1000) + + const deleteRequests = routesToDelete + .map((route) => route?.id || route?._id) + .filter(Boolean) + .map((routeId) => TransRoutesService.deleteRoute(routeId)); + + await Promise.allSettled(deleteRequests); + closeDeleteModal(); + + const selectedDateString = getDateString(dateSelected); + if (selectedDateString === getDateString(new Date())) { + dispatch(fetchAllRoutes()); + } else if (dateSelected > new Date()) { + dispatch(fetchAllTomorrowRoutes({ dateText: moment(dateSelected).format('MM/DD/YYYY') })); + } else { + dispatch(fetchAllHistoryRoutes({ dateText: getDateString(dateSelected) })); + } } const closeDeleteModal = () => {