diff --git a/client/src/components/trans-routes/RouteEdit.js b/client/src/components/trans-routes/RouteEdit.js index 230d044..eca1975 100644 --- a/client/src/components/trans-routes/RouteEdit.js +++ b/client/src/components/trans-routes/RouteEdit.js @@ -125,18 +125,11 @@ const RouteEdit = () => { if (!validateRoute()) { return; } - // Merge attendance-based absences into the customer list for saving - const existingAbsentInRoute = (currentRoute?.route_customer_list || []).filter( - c => c?.customer_route_status === PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT + // Do not persist scheduled-absence entries into route_customer_list. + const filteredCustomerList = (newCustomerList || []).filter( + (customer) => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT ); - const existingAbsentIds = new Set(existingAbsentInRoute.map(a => a.customer_id)); - // Also exclude attendance-absent customers from newCustomerList (they shouldn't be in the main list) - const attendanceAbsentIds = new Set(attendanceAbsentCustomers.map(a => a.customer_id)); - const filteredCustomerList = (newCustomerList || []).filter(c => !attendanceAbsentIds.has(c.customer_id)); - // Add attendance-based absences that aren't already in existing absences - const newAttendanceAbsences = attendanceAbsentCustomers.filter(a => !existingAbsentIds.has(a.customer_id)); - const fullCustomerList = [...filteredCustomerList, ...existingAbsentInRoute, ...newAttendanceAbsences]; - let data = Object.assign({}, currentRoute, {name: routeName, driver: newDriver, vehicle: newVehicle, type: newRouteType, route_customer_list: fullCustomerList}); + let data = Object.assign({}, currentRoute, {name: routeName, driver: newDriver, vehicle: newVehicle, type: newRouteType, route_customer_list: filteredCustomerList}); if (estimatedStartTime && estimatedStartTime !== '') { data = Object.assign({}, data, {estimated_start_time: combineDateAndTime(currentRoute.schedule_date, estimatedStartTime)}) } @@ -595,8 +588,7 @@ const RouteEdit = () => { currentRoute={currentRoute ? { ...currentRoute, route_customer_list: currentRoute.route_customer_list?.filter( - customer => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT && - !attendanceAbsentCustomers.some(a => a.customer_id === customer.customer_id) + customer => customer?.customer_route_status !== PERSONAL_ROUTE_STATUS.SCHEDULED_ABSENT ) || [] } : undefined} setNewCustomerList={setNewCustomerList}