From 9a1efbf532d1be11c2c336008e5c3051433c5e96 Mon Sep 17 00:00:00 2001 From: Lixian Zhou Date: Thu, 12 Mar 2026 17:31:06 -0400 Subject: [PATCH] fix --- .../trans-routes/RoutesDashboard.js | 2 + .../components/trans-routes/TransRoutes.js | 69 ++++++++++++------- 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/client/src/components/trans-routes/RoutesDashboard.js b/client/src/components/trans-routes/RoutesDashboard.js index 5c69a27..92658fd 100644 --- a/client/src/components/trans-routes/RoutesDashboard.js +++ b/client/src/components/trans-routes/RoutesDashboard.js @@ -530,6 +530,8 @@ const RoutesDashboard = () => { }; const routeNote = normalizeNullableNote(customerInRoute?.customer_note); const dbNoteToDriver = normalizeNullableNote(customerProfile?.notes_for_driver); + // Ignore empty-note comparisons during route checks. + if (!routeNote || !dbNoteToDriver) return; if (routeNote === dbNoteToDriver) return; const existing = mismatchMap.get(customerId) || { diff --git a/client/src/components/trans-routes/TransRoutes.js b/client/src/components/trans-routes/TransRoutes.js index 63de51a..6eeaf64 100644 --- a/client/src/components/trans-routes/TransRoutes.js +++ b/client/src/components/trans-routes/TransRoutes.js @@ -16,31 +16,50 @@ const TransRoutes = () => { navigate('/admin'); } useEffect(() => { - if ( - !AuthService.canAddOrEditRoutes() && - !AuthService.canViewRoutes() && - !AuthService.canViewRouteTemplates() && - !AuthService.canEditRouteTemplates() - ) { - window.alert('You haven\'t login yet OR this user does not have access to this page. Please change a dispatcher or admin account to login.') - AuthService.logout(); - navigate(`/login`); - } - dispatch(fetchAllDrivers()); - dispatch(fetchAllVehicles()); - dispatch(fetchAllRoutes()); - const params = new URLSearchParams(window.location.search); - const scheduleDate = params.get('dateSchedule'); - const requestBody = scheduleDate ? {dateText: moment(scheduleDate).format('MM/DD/YYYY')}: {}; - dispatch(fetchAllTomorrowRoutes(requestBody)); - dispatch(fetchAllRouteTemplates()); - dispatch(fetchAllBreakfastRecords()); - dispatch(fetchAllLunchRecords()); - dispatch(fetchAllSnackRecords()); - const timeInterval = setInterval( - () => { dispatch(fetchAllRoutes()); }, 180000 - ); - return () => clearInterval(timeInterval); + let isMounted = true; + let timeInterval; + const initPage = async () => { + try { + // Ensure permission checks use latest server-side permissions on refresh. + await AuthService.refreshCurrentUserPermissions(); + } catch (error) { + console.log(error); + } + + if (!isMounted) return; + if ( + !AuthService.canAddOrEditRoutes() && + !AuthService.canViewRoutes() && + !AuthService.canViewRouteTemplates() && + !AuthService.canEditRouteTemplates() + ) { + window.alert('You haven\'t login yet OR this user does not have access to this page. Please change a dispatcher or admin account to login.') + AuthService.logout(); + navigate(`/login`); + return; + } + dispatch(fetchAllDrivers()); + dispatch(fetchAllVehicles()); + dispatch(fetchAllRoutes()); + const params = new URLSearchParams(window.location.search); + const scheduleDate = params.get('dateSchedule'); + const requestBody = scheduleDate ? {dateText: moment(scheduleDate).format('MM/DD/YYYY')}: {}; + dispatch(fetchAllTomorrowRoutes(requestBody)); + dispatch(fetchAllRouteTemplates()); + dispatch(fetchAllBreakfastRecords()); + dispatch(fetchAllLunchRecords()); + dispatch(fetchAllSnackRecords()); + timeInterval = setInterval( + () => { dispatch(fetchAllRoutes()); }, 180000 + ); + }; + initPage(); + return () => { + isMounted = false; + if (timeInterval) { + clearInterval(timeInterval); + } + }; }, []) return (