diff --git a/client/src/components/trans-routes/RouteView.js b/client/src/components/trans-routes/RouteView.js index 5fbcd18..b8a35ff 100644 --- a/client/src/components/trans-routes/RouteView.js +++ b/client/src/components/trans-routes/RouteView.js @@ -28,6 +28,7 @@ const RouteView = () => { const [isSavingRouteStatus, setIsSavingRouteStatus] = useState(false); const [latestRouteForStatus, setLatestRouteForStatus] = useState(undefined); const [routeSnapshot, setRouteSnapshot] = useState(undefined); + const [customerMetaById, setCustomerMetaById] = useState(new Map()); const paramsQuery = new URLSearchParams(window.location.search); const scheduleDate = paramsQuery.get('dateSchedule'); @@ -42,7 +43,22 @@ const RouteView = () => { { value: ROUTE_STATUS.SIGN_OFF, label: 'Signed Off' }, { value: ROUTE_STATUS.UNEXPECTED_ABSENT, label: 'Unexpected Absent' }, ]; - const routeForStatusView = latestRouteForStatus || currentRoute; + const mergeRouteCustomerMeta = (route) => { + if (!route || !Array.isArray(route?.route_customer_list) || customerMetaById.size === 0) { + return route; + } + return Object.assign({}, route, { + route_customer_list: route.route_customer_list.map((customerInRoute) => { + const customerMeta = customerMetaById.get(customerInRoute?.customer_id); + if (!customerMeta) return customerInRoute; + return Object.assign({}, customerInRoute, { + customer_program_type: customerMeta.program_type || '', + customer_pay_source: customerMeta.pay_source || '' + }); + }) + }); + }; + const routeForStatusView = mergeRouteCustomerMeta(latestRouteForStatus || routeSnapshot || currentRoute); const routeForAssignmentView = routeSnapshot || currentRoute; const closeModal = () => { setShowVehicleDetails(false); @@ -146,6 +162,23 @@ const RouteView = () => { }); }, [currentRoute?.id, params?.id]); + useEffect(() => { + CustomerService.getAllCustomers() + .then((res) => { + const nextMap = new Map(); + (res?.data || []).forEach((customer) => { + nextMap.set(customer?.id, { + program_type: customer?.program_type || '', + pay_source: customer?.pay_source || '' + }); + }); + setCustomerMetaById(nextMap); + }) + .catch(() => { + setCustomerMetaById(new Map()); + }); + }, []); + useEffect(() => { if (!currentRoute?.driver || currentDriver?.id) { setFallbackDriver(undefined);