11import "bootstrap/dist/css/bootstrap.min.css" ;
2- import React , { useState , useReducer } from "react" ;
2+ import React , { useState } from "react" ;
33import { BrowserRouter as Router , Route , Switch } from "react-router-dom" ;
44import TeamMembersPage from "./components/pages/TeamMembersPage" ;
55
66import Default from "./pages/Default" ;
77import LoginPage from "./pages/LoginPage" ;
8- import Signup from "./components/auth/Signup" ;
98import ForgotPasswordPage from "./pages/ForgotPasswordPage" ;
109import ResetPasswordPage from "./pages/ResetPasswordPage" ;
1110import PrivateRoute from "./components/auth/PrivateRoute" ;
12- import CreatePage from "./pages/CreatePage" ;
1311import PetListPage from "./pages/PetListPage" ;
14- import DisplayPage from "./pages/DisplayPage" ;
15- import SimpleEntityCreatePage from "./pages/SimpleEntityCreatePage" ;
16- import SimpleEntityDisplayPage from "./pages/SimpleEntityDisplayPage" ;
1712import TaskManagementPage from "./pages/TaskManagementPage" ;
1813import AddTaskTemplatePage from "./pages/AddTaskTemplatePage" ;
1914import NotFoundPage from "./pages/NotFoundPage" ;
20- import UpdatePage from "./pages/UpdatePage" ;
21- import SimpleEntityUpdatePage from "./pages/SimpleEntityUpdatePage" ;
2215import CreatePasswordPage from "./pages/CreatePasswordPage" ;
2316import * as Routes from "./constants/Routes" ;
2417import * as AuthConstants from "./constants/AuthConstants" ;
2518import AUTHENTICATED_USER_KEY from "./constants/AuthConstants" ;
2619import AuthContext from "./contexts/AuthContext" ;
2720import { getLocalStorageObj } from "./utils/LocalStorageUtils" ;
28- import SampleContext , {
29- DEFAULT_SAMPLE_CONTEXT ,
30- } from "./contexts/SampleContext" ;
31- import sampleContextReducer from "./reducers/SampleContextReducer" ;
32- import SampleContextDispatcherContext from "./contexts/SampleContextDispatcherContext" ;
33- import EditTeamInfoPage from "./pages/EditTeamPage" ;
34- import HooksDemo from "./pages/HooksDemo" ;
3521import InteractionLogPage from "./pages/InteractionLogPage" ;
3622import ProfilePage from "./pages/ProfilePage" ;
3723import PetProfilePage from "./pages/PetProfilePage" ;
@@ -42,7 +28,6 @@ import Layout from "./Layout";
4228import PageTitleUpdater from "./components/common/PageTitleUpdater" ;
4329
4430import { AuthenticatedUser } from "./types/AuthTypes" ;
45- import DevFileStorageUpload from "./pages/DevFileStorageUpload" ;
4631
4732import VolunteerViewEditUserProfilePage from "./pages/VolunteerViewEditUserProfilePage" ;
4833
@@ -54,181 +39,111 @@ const App = (): React.ReactElement => {
5439 const [ authenticatedUser , setAuthenticatedUser ] =
5540 useState < AuthenticatedUser > ( currentUser ) ;
5641
57- // Some sort of global state. Context API replaces redux.
58- // Split related states into different contexts as necessary.
59- // Split dispatcher and state into separate contexts as necessary.
60- const [ sampleContext , dispatchSampleContextUpdate ] = useReducer (
61- sampleContextReducer ,
62- DEFAULT_SAMPLE_CONTEXT ,
63- ) ;
64-
6542 return (
66- < SampleContext . Provider value = { sampleContext } >
67- < SampleContextDispatcherContext . Provider
68- value = { dispatchSampleContextUpdate }
69- >
70- < AuthContext . Provider
71- value = { { authenticatedUser, setAuthenticatedUser } }
72- >
73- < Router >
74- < PageTitleUpdater />
43+ < AuthContext . Provider value = { { authenticatedUser, setAuthenticatedUser } } >
44+ < Router >
45+ < PageTitleUpdater />
46+ < Switch >
47+ < Route exact path = { Routes . LOGIN_PAGE } component = { LoginPage } />
48+ < Route
49+ exact
50+ path = { Routes . FORGOT_PASSWORD_PAGE }
51+ component = { ForgotPasswordPage }
52+ />
53+ < Route
54+ exact
55+ path = { Routes . RESET_PASSWORD_PAGE }
56+ component = { ResetPasswordPage }
57+ />
58+ < PrivateRoute
59+ exact
60+ path = { Routes . CREATE_PASSWORD_PAGE }
61+ component = { CreatePasswordPage }
62+ allowedRoles = { AuthConstants . ALL_ROLES }
63+ />
64+ { /* Protected Routes Wrapped in Layout */ }
65+ < Layout >
7566 < Switch >
76- < Route exact path = { Routes . LOGIN_PAGE } component = { LoginPage } />
77- < Route exact path = { Routes . SIGNUP_PAGE } component = { Signup } />
78- < Route
67+ < PrivateRoute
68+ exact
69+ path = { Routes . HOME_PAGE }
70+ component = { PetListPage }
71+ allowedRoles = { AuthConstants . ALL_ROLES }
72+ />
73+ { /* Starter Code Route */ }
74+ < PrivateRoute
75+ exact
76+ path = { Routes . DEV_UTILITY_PAGE }
77+ component = { Default }
78+ allowedRoles = { AuthConstants . ALL_ROLES }
79+ />
80+ < PrivateRoute
81+ exact
82+ path = { Routes . INTERACTION_LOG_PAGE }
83+ component = { InteractionLogPage }
84+ allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
85+ />
86+ < PrivateRoute
87+ exact
88+ path = { `${ Routes . PROFILE_PAGE } /:id` }
89+ component = { ProfilePage }
90+ allowedRoles = { AuthConstants . ALL_ROLES }
91+ />
92+ < PrivateRoute
7993 exact
80- path = { Routes . FORGOT_PASSWORD_PAGE }
81- component = { ForgotPasswordPage }
94+ path = { `${ Routes . PET_PROFILE_PAGE } /:id` }
95+ component = { PetProfilePage }
96+ allowedRoles = { AuthConstants . ALL_ROLES }
97+ />
98+ < PrivateRoute
99+ exact
100+ path = { Routes . ADMIN_PAGE }
101+ component = { AdminPage }
102+ allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
103+ />
104+ < PrivateRoute
105+ exact
106+ path = { Routes . USER_MANAGEMENT_PAGE }
107+ component = { UserManagementPage }
108+ allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
109+ />
110+ < PrivateRoute
111+ exact
112+ path = { `${ Routes . ADMIN_EDIT_USER_PROFILE_PAGE } /:userId` }
113+ component = { AdminViewEditUserProfilePage }
114+ allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
82115 />
83- < Route
116+ < PrivateRoute
117+ exact
118+ path = { Routes . TASK_MANAGEMENT_PAGE }
119+ component = { TaskManagementPage }
120+ allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
121+ />
122+ < PrivateRoute
84123 exact
85- path = { Routes . RESET_PASSWORD_PAGE }
86- component = { ResetPasswordPage }
124+ path = { Routes . ADD_TASK_TEMPLATE_PAGE }
125+ component = { AddTaskTemplatePage }
126+ allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
127+ />
128+ < PrivateRoute
129+ exact
130+ path = { `${ Routes . VOLUNTEER_EDIT_USER_PROFILE_PAGE } /:userId` }
131+ component = { VolunteerViewEditUserProfilePage }
132+ allowedRoles = { AuthConstants . ALL_ROLES }
87133 />
88134 < PrivateRoute
89135 exact
90- path = { Routes . CREATE_PASSWORD_PAGE }
91- component = { CreatePasswordPage }
136+ path = { Routes . TEAM_MEMBERS }
137+ component = { TeamMembersPage }
92138 allowedRoles = { AuthConstants . ALL_ROLES }
93139 />
94- { /* Protected Routes Wrapped in Layout */ }
95- < Layout >
96- < Switch >
97- < PrivateRoute
98- exact
99- path = { Routes . HOME_PAGE }
100- component = { PetListPage }
101- allowedRoles = { AuthConstants . ALL_ROLES }
102- />
103- < PrivateRoute
104- exact
105- path = { Routes . CREATE_ENTITY_PAGE }
106- component = { CreatePage }
107- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
108- />
109- < PrivateRoute
110- exact
111- path = { Routes . UPDATE_ENTITY_PAGE }
112- component = { UpdatePage }
113- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
114- />
115- < PrivateRoute
116- exact
117- path = { Routes . DISPLAY_ENTITY_PAGE }
118- component = { DisplayPage }
119- allowedRoles = { AuthConstants . ALL_ROLES }
120- />
121- < PrivateRoute
122- exact
123- path = { Routes . CREATE_SIMPLE_ENTITY_PAGE }
124- component = { SimpleEntityCreatePage }
125- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
126- />
127- < PrivateRoute
128- exact
129- path = { Routes . UPDATE_SIMPLE_ENTITY_PAGE }
130- component = { SimpleEntityUpdatePage }
131- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
132- />
133- < PrivateRoute
134- exact
135- path = { Routes . DISPLAY_SIMPLE_ENTITY_PAGE }
136- component = { SimpleEntityDisplayPage }
137- allowedRoles = { AuthConstants . ALL_ROLES }
138- />
139- < PrivateRoute
140- exact
141- path = { Routes . EDIT_TEAM_PAGE }
142- component = { EditTeamInfoPage }
143- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
144- />
145- < PrivateRoute
146- exact
147- path = { Routes . HOOKS_PAGE }
148- component = { HooksDemo }
149- allowedRoles = { AuthConstants . ALL_ROLES }
150- />
151- < PrivateRoute
152- exact
153- path = { Routes . DEV_UTILITY_PAGE }
154- component = { Default }
155- allowedRoles = { AuthConstants . ALL_ROLES }
156- />
157- < PrivateRoute
158- exact
159- path = { Routes . DEV_FILE_STORAGE_UPLOAD_PAGE }
160- component = { DevFileStorageUpload }
161- allowedRoles = { AuthConstants . ALL_ROLES }
162- />
163- < PrivateRoute
164- exact
165- path = { Routes . INTERACTION_LOG_PAGE }
166- component = { InteractionLogPage }
167- allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
168- />
169- < PrivateRoute
170- exact
171- path = { `${ Routes . PROFILE_PAGE } /:id` }
172- component = { ProfilePage }
173- allowedRoles = { AuthConstants . ALL_ROLES }
174- />
175- < PrivateRoute
176- exact
177- path = { `${ Routes . PET_PROFILE_PAGE } /:id` }
178- component = { PetProfilePage }
179- allowedRoles = { AuthConstants . ALL_ROLES }
180- />
181- < PrivateRoute
182- exact
183- path = { Routes . ADMIN_PAGE }
184- component = { AdminPage }
185- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
186- />
187- < PrivateRoute
188- exact
189- path = { Routes . USER_MANAGEMENT_PAGE }
190- component = { UserManagementPage }
191- allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
192- />
193- < PrivateRoute
194- exact
195- path = { `${ Routes . ADMIN_EDIT_USER_PROFILE_PAGE } /:userId` }
196- component = { AdminViewEditUserProfilePage }
197- allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
198- />
199- < PrivateRoute
200- exact
201- path = { Routes . TASK_MANAGEMENT_PAGE }
202- component = { TaskManagementPage }
203- allowedRoles = { AuthConstants . STAFF_BEHAVIOURISTS_ADMIN }
204- />
205- < PrivateRoute
206- exact
207- path = { Routes . ADD_TASK_TEMPLATE_PAGE }
208- component = { AddTaskTemplatePage }
209- allowedRoles = { AuthConstants . ADMIN_AND_BEHAVIOURISTS }
210- />
211- < PrivateRoute
212- exact
213- path = { `${ Routes . VOLUNTEER_EDIT_USER_PROFILE_PAGE } /:userId` }
214- component = { VolunteerViewEditUserProfilePage }
215- allowedRoles = { AuthConstants . ALL_ROLES }
216- />
217- < PrivateRoute
218- exact
219- path = { Routes . TEAM_MEMBERS }
220- component = { TeamMembersPage }
221- allowedRoles = { AuthConstants . ALL_ROLES }
222- />
223- { /* Fallback Route */ }
224- < Route path = "*" component = { NotFoundPage } />
225- </ Switch >
226- </ Layout >
140+ { /* Fallback Route */ }
141+ < Route path = "*" component = { NotFoundPage } />
227142 </ Switch >
228- </ Router >
229- </ AuthContext . Provider >
230- </ SampleContextDispatcherContext . Provider >
231- </ SampleContext . Provider >
143+ </ Layout >
144+ </ Switch >
145+ </ Router >
146+ </ AuthContext . Provider >
232147 ) ;
233148} ;
234149
0 commit comments