Skip to content

Commit

Permalink
Redirect first responders to a patient not found page
Browse files Browse the repository at this point in the history
  • Loading branch information
samau3 committed Sep 19, 2024
1 parent 5aa70dd commit 4ac9e4e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <Loader />;
} else {
return children;
}
return role === 'FIRST_RESPONDER' ? <Loader /> : children;
}

ProtectedRoute.propTypes = ProtectedRouteProps;
Expand Down Expand Up @@ -135,6 +134,7 @@ function App() {
</ProtectedRoute>
}
/>
<Route path="/patients/not-found" element={<PatientNotFound />} />
<Route path="/admin/users" element={<AdminUsers />} />
<Route
path="/admin/pending-users"
Expand Down
25 changes: 25 additions & 0 deletions client/src/pages/patients/notFound/PatientNotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Container } from '@mantine/core';
import { useNavigate, useLocation } from 'react-router-dom';
import { useEffect } from 'react';

/**
* Patient not found page component
*
*/
export default function PatientNotFound() {
const navigate = useNavigate();
const location = useLocation();

useEffect(() => {
if (!location.state?.fromRedirect) {
navigate('/', { replace: true });
}
}, [navigate, location]);

return (
<Container>
<h1>Patient Does Not Exist</h1>
<p> The patient you are looking for does not exist yet.</p>
</Container>
);
}

0 comments on commit 4ac9e4e

Please sign in to comment.