-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApp.tsx
More file actions
569 lines (554 loc) · 18.6 KB
/
App.tsx
File metadata and controls
569 lines (554 loc) · 18.6 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// import 'bootstrap/dist/css/bootstrap.min.css';
// import 'bootstrap/dist/js/bootstrap.bundle.min.js';
import './static/styles/App.scss';
// import './static/styles/Table.scss';
// import './static/styles/BaseCard.scss';
import React, { createContext } from 'react';
import ReactGA from 'react-ga';
import { Helmet } from 'react-helmet';
import {
BrowserRouter as Router,
Redirect,
Route,
Switch,
} from 'react-router-dom';
import Careers from './components/AboutUs/Careers';
import EULA from './components/AboutUs/EULA';
import OurPartners from './components/AboutUs/OurPartners';
import OurTeam from './components/AboutUs/OurTeam';
import PrivacyPolicy from './components/AboutUs/PrivacyPolicy';
import MyOrganization from './components/AccountSettings/MyOrganization';
import CreateApplication from './components/Applications/CreateApplication';
import ViewApplications from './components/Applications/ViewApplications';
import MyDocuments from './components/Documents/MyDocuments';
import UploadDocs from './components/Documents/UploadDocs';
import Error from './components/Error';
import Footer from './components/Footer';
import Header from './components/Header';
import Home from './components/Home/index';
import IssueReport from './components/IssueReport';
import AdminDashboard from './components/LandingPages/AdminDashboard';
import ClientLanding from './components/LandingPages/ClientLanding';
import DevPanel from './components/LandingPages/DeveloperLanding';
import WorkerLanding from './components/LandingPages/WorkerLanding';
import ProfilePage from './components/Profile/ProfilePage';
import QuickAccessRouter from './components/QuickAccess/QuickAccess.router';
import EnrollClientPage from './components/SignUp/EnrollClient';
import EnrollWorkerPage from './components/SignUp/EnrollWorker';
import SignUpRouter, {
paths as SignUpRouterPaths,
} from './components/SignUp/SignUp.router';
import AutoLogout from './components/UserAuthentication/AutoLogout';
import ForgotPassword from './components/UserAuthentication/ForgotPassword';
import ResetPassword from './components/UserAuthentication/ResetPassword';
import getServerURL from './serverOverride';
import Role from './static/Role';
window.onload = () => {
ReactGA.initialize('AW-391118279');
ReactGA.pageview(window.location.pathname + window.location.search);
};
interface State {
role: Role;
username: string;
name: string;
organization: string;
autoLogout: boolean;
}
interface ContextInterface {
username: string;
organization: string;
}
export const UserContext = React.createContext<ContextInterface>({
username: '',
organization: '',
});
class App extends React.Component<{}, State, {}> {
constructor(props: {}) {
super(props);
// set the original state based on session storage
const jsonData = sessionStorage.getItem('mySessionStorageData');
const jsonLogout = sessionStorage.getItem('autoLogout');
if (jsonData && jsonLogout) {
const data = JSON.parse(jsonData);
const logout = JSON.parse(jsonLogout);
this.state = {
role: data.role,
username: data.username,
name: data.name,
organization: data.organization,
autoLogout: logout,
};
} else {
this.state = {
role: Role.LoggedOut,
username: '',
name: '',
organization: '',
autoLogout: false,
};
}
this.logIn = this.logIn.bind(this);
this.logOut = this.logOut.bind(this);
this.setAutoLogout = this.setAutoLogout.bind(this);
}
// this function is needed to tell the home page that the user was logged out automatically
// or remove that notification
setAutoLogout(logout: boolean) {
this.setState({
autoLogout: logout,
});
const obj = { autoLogout: this.state.autoLogout };
sessionStorage.setItem('autoLogout', JSON.stringify(obj));
}
logIn(role: Role, username: string, organization: string, name: string) {
this.setState({
role,
username,
name,
organization,
});
const obj = { role, username, name, organization };
sessionStorage.setItem('mySessionStorageData', JSON.stringify(obj));
}
logOut() {
this.setState({
username: '',
name: '',
organization: '',
role: Role.LoggedOut,
});
fetch(`${getServerURL()}/logout`, {
method: 'GET',
credentials: 'include',
});
sessionStorage.clear();
}
componentDidMount() {
fetch(`${getServerURL()}/authenticate`, {
method: 'POST',
credentials: 'include',
})
.then((response) => response.json())
.then((responseJSON) => {
const {
status,
userRole,
organization,
username,
firstName,
lastName,
} = responseJSON;
if (status === 'AUTH_SUCCESS') {
const role = () => {
switch (userRole) {
case 'Director':
return Role.Director;
case 'Admin':
return Role.Admin;
case 'Worker':
return Role.Worker;
case 'Client':
return Role.Client;
case 'Developer':
return Role.Developer;
default:
return Role.LoggedOut;
}
};
// if the session storage does not match the authentication, logout
const jsonData = sessionStorage.getItem('mySessionStorageData');
if (jsonData) {
const data = JSON.parse(jsonData);
if (
!(
role() === data.role &&
username === data.username &&
organization === data.organization
) &&
data.name === `${firstName} ${lastName}`
) {
this.logOut();
}
} else {
// Server has a valid session but client has no local data.
// This happens after Google OAuth login redirect — trust the
// server and log in locally instead of destroying the session.
this.logIn(role(), username, organization, `${firstName} ${lastName}`);
}
} else {
this.logOut();
}
})
.catch((e) => {
console.log('Server is not running: ', e);
});
}
render() {
const { role, username, name, organization, autoLogout } = this.state;
const renderHome = () => (
<Home
logIn={this.logIn}
logOut={this.logOut}
role={role}
autoLogout={autoLogout}
setAutoLogout={this.setAutoLogout}
/>
);
return (
<Router>
<UserContext.Provider value={{ username: this.state.username, organization: this.state.organization }}>
<div className="App tw-flex tw-flex-col tw-min-h-screen">
<div className="app tw-flex-1 tw-pb-12">
<Helmet>
<title>Keep.id</title>
<meta
name="description"
content="Securely Combating Homelessness"
/>
</Helmet>
<Header
isLoggedIn={role !== Role.LoggedOut}
logIn={this.logIn}
logOut={this.logOut}
role={role}
/>
{role !== Role.LoggedOut ? (
<AutoLogout
logOut={this.logOut}
setAutoLogout={this.setAutoLogout}
timeUntilWarn={1000 * 60 * 60}
timeFromWarnToLogout={1000 * 60 * 15}
timeBeforeConsideredSleep={1000 * 60 * 60 * 24 * 30}
/>
) : null}
<Switch>
<Route exact path="/" render={() => <Redirect to="/home" />} />
<Route path="/our-team">
<OurTeam />
</Route>
<Route path="/our-partners">
<OurPartners />
</Route>
<Route path="/privacy-policy">
<PrivacyPolicy />
</Route>
<Route
path="/eula"
render={() => {
if (role !== Role.LoggedOut) {
return <EULA />;
}
return renderHome();
}}
/>
<Route
path="/eula"
render={() => {
if (role === Role.Admin || role === Role.Director) {
return <AdminDashboard />;
}
return renderHome();
}}
/>
<Route path="/careers">
<Careers />
</Route>
<Route path="/issue-report">
<IssueReport
designatedHeader="Report an Issue"
designatedSubHeader="Thank you for helping us identify issues with our platform."
/>
</Route>
<Route path="/leave-feedback">
<IssueReport
designatedHeader="Leave Feedback"
designatedSubHeader="Thank you for helping us with your personalized feedback about our platform."
/>
</Route>
<Route path="/forgot-password">
<ForgotPassword />
</Route>
<Route path="/reset-password/:jwt">
<ResetPassword />
</Route>
<Route
path="/home"
render={() => {
if (
role === Role.Director ||
role === Role.Admin ||
role === Role.Worker
) {
return (
<WorkerLanding
name={name}
organization={organization}
username={username}
role={role}
/>
);
}
if (role === Role.Client) {
return <ClientLanding name={name} username={username} />;
}
if (role === Role.Developer) {
return (
<DevPanel
name={name}
organization={organization}
username={username}
role={role}
/>
);
}
return renderHome();
}}
/>
<Route
path="/find-organizations"
render={() => <Redirect to="/home" />}
/>
<Route
path="/login"
render={() => <Redirect to="/home" />}
/>
{/* Admin Panel route removed - functionality moved to My Organization page */}
<Route
path="/dev-panel"
render={() => {
if (role === Role.Director || role === Role.Admin) {
return (
<DevPanel
userRole={role}
name={name}
organization={organization}
username={username}
/>
);
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/upload-document/:clientUsername"
render={(props) => {
const { clientUsername } = props.match.params;
if (
role === Role.Admin ||
role === Role.Director ||
role === Role.Worker ||
role === Role.Client
) {
return (
<UploadDocs
userRole={Role.Client}
username={clientUsername}
/>
);
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/upload-document"
render={() => {
if (
role === Role.Client ||
role === Role.Admin ||
role === Role.Director ||
role === Role.Worker ||
role === Role.Developer
) {
return <UploadDocs userRole={role} username={username} />;
}
return renderHome();
}}
/>
<Route
path="/my-documents/:clientUsername"
render={(props) => {
const { clientUsername } = props.match.params;
const locState = props.location.state as { clientName?: string } | undefined;
if (
role === Role.Admin ||
role === Role.Worker ||
role === Role.Developer ||
role === Role.Client
) {
return (
<MyDocuments
userRole={Role.Client}
viewerRole={role}
username={clientUsername}
clientName={locState?.clientName}
/>
);
}
return renderHome();
}}
/>
<Route
path="/my-documents"
render={() => {
if (
role === Role.Client ||
role === Role.Admin ||
role === Role.Director ||
role === Role.Worker ||
role === Role.Developer
) {
return <MyDocuments userRole={role} viewerRole={role} username={username} />;
}
return renderHome();
}}
/>
<Route
path="/applications/createnew"
render={() => {
if (
role === Role.Client ||
role === Role.Admin ||
role === Role.Worker ||
role === Role.Developer
) {
return (
<CreateApplication userRole={role} />
);
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/applications"
render={({ location }) => {
if (
role === Role.Client ||
role === Role.Admin ||
role === Role.Worker ||
role === Role.Developer
) {
return (
<ViewApplications
name={name}
organization={organization}
username={username}
role={role}
/>
);
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route path="/quick-access">
<QuickAccessRouter />
</Route>
<Route
path="/settings"
render={() => {
if (role !== Role.LoggedOut) {
return <Redirect to="/profile" />;
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/profile"
exact
render={() => {
if (role !== Role.LoggedOut) {
return <ProfilePage />;
}
return renderHome();
}}
/>
<Route
path="/my-organization"
render={() => {
if (role === Role.Director || role === Role.Admin) {
return (
<MyOrganization
name={name}
organization={organization}
role={role}
/>
);
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/profile/:username"
render={(props) => {
const clientUsername = props.match.params.username;
if (role !== Role.LoggedOut) {
return <ProfilePage targetUsername={clientUsername} />;
}
return renderHome();
}}
/>
<Route
path="/enroll-client"
render={() => {
if (
role === Role.Worker ||
role === Role.Admin ||
role === Role.Director
) {
return <EnrollClientPage />;
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<Route
path="/enroll-worker"
render={() => {
if (
role === Role.Admin ||
role === Role.Director
) {
return <EnrollWorkerPage />;
}
if (role === Role.LoggedOut) {
return renderHome();
}
return <Redirect to="/error" />;
}}
/>
<SignUpRouter role={role} />
<Route path="/error">
<Error />
</Route>
<Route>
<Redirect to="/error" />
</Route>
</Switch>
</div>
<Footer />
</div>
</UserContext.Provider>
</Router>
);
}
}
export default App;