From 4ac9e4e9251bce84d7145fa1db1c4825028fd816 Mon Sep 17 00:00:00 2001 From: samau3 Date: Wed, 18 Sep 2024 17:01:37 -0700 Subject: [PATCH] Redirect first responders to a patient not found page --- client/src/App.jsx | 14 +++++------ .../patients/notFound/PatientNotFound.jsx | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 client/src/pages/patients/notFound/PatientNotFound.jsx diff --git a/client/src/App.jsx b/client/src/App.jsx index a37a531c..986c19a7 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -16,6 +16,7 @@ import Login from './pages/auth/login/login'; import Register from './pages/auth/register/register'; import Dashboard from './pages/dashboard/dashboard'; import AdminPatientsGenerate from './pages/admin/patients/AdminPatientsGenerate'; +import PatientNotFound from './pages/patients/notFound/PatientNotFound'; import { AdminUsers } from './pages/admin/users/AdminUsers'; import Context from './Context'; @@ -76,16 +77,14 @@ function ProtectedRoute({ role, children }) { const navigate = useNavigate(); useEffect(() => { if (role === 'FIRST_RESPONDER') { - navigate('/login', { replace: true }); - return; + navigate('/patients/not-found', { + replace: true, + state: { fromRedirect: true }, + }); } }, [role, navigate]); - if (role === 'FIRST_RESPONDER' || !role) { - return ; - } else { - return children; - } + return role === 'FIRST_RESPONDER' ? : children; } ProtectedRoute.propTypes = ProtectedRouteProps; @@ -135,6 +134,7 @@ function App() { } /> + } /> } /> { + if (!location.state?.fromRedirect) { + navigate('/', { replace: true }); + } + }, [navigate, location]); + + return ( + +

Patient Does Not Exist

+

The patient you are looking for does not exist yet.

+
+ ); +} \ No newline at end of file