Skip to content

Commit

Permalink
Fixed Bug w/ RoleProvider Role Being Undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
brelieu05 committed Apr 20, 2024
1 parent 9ab2c56 commit 892e4fa
Show file tree
Hide file tree
Showing 4 changed files with 7,375 additions and 4,799 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
15 changes: 11 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import NavbarContext from './utils/NavbarContext';
import QRCodePage from './pages/QRCodePage';
import PastEvents from './pages/PastEvents';
import ViewEvents from './pages/ViewEvents';

import { useDisclosure, useBreakpointValue, Box } from '@chakra-ui/react';

const Layout = () => {
Expand Down Expand Up @@ -61,29 +60,35 @@ const Layout = () => {
import { theme } from './utils/chakraTheme';
import InputDataPage from './pages/InputDataPage';
import VolunteerHomePage from './pages/VolunteerHomePage';
import RoleConsumer from './components/RoleConsumer';


const App = () => {

return (
<ChakraProvider theme={theme}>
<Router>
<RoleProvider>
<UserProvider>
<RoleConsumer>
{role => (
<Routes>
<Route element={<Layout />}>
{/* Admin and Volunteer Pages */}
<Route
path="/"
element={
<ProtectedRoute pageType="volunteer">
{RoleProvider.role == 'admin' ? <HomePage /> : <VolunteerHomePage />}
{role == 'admin' ? <HomePage /> : <VolunteerHomePage />}
</ProtectedRoute>
}
/>

<Route
path="/event"
element={
<ProtectedRoute pageType="volunteer">
{RoleProvider.role == 'admin' ? <EventPage /> : <VolunteerEventPage />}
<ProtectedRoute pageType="volunteer" >
{role == 'admin' ? <EventPage /> : <VolunteerEventPage />}
</ProtectedRoute>
}
/>
Expand Down Expand Up @@ -265,6 +270,8 @@ const App = () => {
<Route path="/profiles" element={<DummyProfiles />} />
<Route path="/select-event" element={<SelectEvent />} />
</Routes>
)}
</RoleConsumer>
</UserProvider>
</RoleProvider>
</Router>
Expand Down
9 changes: 9 additions & 0 deletions src/components/RoleConsumer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useContext } from 'react';
import RoleContext from '../utils/RoleContext';

const RoleConsumer = ({ children }) => {
const { role } = useContext(RoleContext);
return children(role);
};

export default RoleConsumer;
Loading

0 comments on commit 892e4fa

Please sign in to comment.