-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathApp.jsx
104 lines (97 loc) · 3.79 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import "./App.css";
import CssBaseline from "@material-ui/core/CssBaseline";
import React, { useEffect, useState } from "react";
import { BrowserRouter as Router, Redirect, Switch } from "react-router-dom";
import { OrganizationContext, Organization } from "./app/model";
import { routes, AppRoute } from "./app/routing";
import ThemeProvider from "./app/component/ThemeProvider";
import {
AboutPage,
Dashboard,
DonationPage,
ErrorLanding,
Home,
Login,
Logout,
MissionCreate,
MissionDetails,
MissionsCompleted,
MissionsDelivered,
OrganizerSignupPage,
RequestPage,
Signup,
Status,
UserProfile,
RecipientDashboard,
VolunteerHome,
} from "./app/page";
import Snackbar from "./app/component/Snackbars";
import theme from "./theme";
import { LinearProgress } from "@material-ui/core";
// grab from domain or some service
const ORGANIZATION_ID = "1";
function App() {
const [org, setOrg] = useState();
useEffect(() => {
Organization.init(ORGANIZATION_ID)
.then((org) => setOrg(org))
.catch((error) => {
console.error(error);
setOrg(null);
});
}, []);
if (org === undefined) {
return <LinearProgress />;
}
return (
<>
<ThemeProvider theme={theme}>
<CssBaseline />
<Router>
<div className="App">
<OrganizationContext.Provider value={org}>
<Snackbar.Context.SnackbarProvider>
{org === null && <Redirect to={routes.organizer.signup} />}
<Switch>
<AppRoute exact path={routes.home} component={Home} />
<AppRoute path={routes.about} component={AboutPage} />
<AppRoute path={routes.login} component={Login} />
<AppRoute path={routes.logout} component={Logout} />
<AppRoute path={routes.organizer.signup} component={OrganizerSignupPage} />
<AppRoute path={routes.volunteer.status} component={Status} />
<AppRoute path={routes.user.signup} component={Signup} />
<AppRoute path={routes.request.start} component={RequestPage} />
<AppRoute path={routes.donate} component={DonationPage} />
<AppRoute path={routes.missions.createNew} component={MissionCreate} />
<AppRoute path={routes.missions.completed} component={MissionsCompleted} />
<AppRoute path={routes.missions.delivered} component={MissionsDelivered} />
<AppRoute path={routes.missions.details} component={MissionDetails} />
<AppRoute path={routes.user.profile} component={UserProfile} />
{/* ⬇ BASE routes below ⬇ */}
<AppRoute path={routes.organizer.dashboard.home} component={Dashboard} />
<AppRoute path={routes.recipient.dashboard.home} component={RecipientDashboard} />
<AppRoute path={routes.volunteer.dashboard.home} component={VolunteerHome} />
<AppRoute path={routes.unauthorized}>
<ErrorLanding errorCode={401} />
</AppRoute>
<AppRoute path={routes.pageNotFound}>
<ErrorLanding errorCode={404} />
</AppRoute>
<AppRoute path="*">
<ErrorLanding errorCode={404} />
</AppRoute>
</Switch>
<Snackbar.Context.SnackbarConsumer>
{(value) => {
return <Snackbar handleClose={value.closeSnackbar} {...value.snackbar} />;
}}
</Snackbar.Context.SnackbarConsumer>
</Snackbar.Context.SnackbarProvider>
</OrganizationContext.Provider>
</div>
</Router>
</ThemeProvider>
</>
);
}
export default App;