Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Bug w/ RoleProvider Role Being Undefined #174

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading