-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathApp.js
More file actions
executable file
·639 lines (605 loc) · 22.1 KB
/
Copy pathApp.js
File metadata and controls
executable file
·639 lines (605 loc) · 22.1 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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
import React, { Component } from "react";
import { Router, Route, NavLink, Switch } from "react-router-dom";
import Home from "./pages/home";
import EventHome from "./pages/eventHome";
import Login from "./pages/login";
import ResetPassword from "./pages/resetPassword";
import CreateAccount from "./pages/createAccount";
import EventConfig from "./pages/eventConfig";
import VerifyEmail from "./pages/verifyEmail";
import Profile from "./pages/profile";
import { PrivateRoute } from "./components";
import UserDropdown from "./components/User";
import ViewFile from "./components/ViewFile";
import Reference from "./pages/references";
import CookieConsent from "react-cookie-consent";
import ResponseList from './pages/ResponseList/ResponseList';
import { AdminMenu } from './utils/adminMenu';
import { Payment, Success, Failed } from './pages/payment';
import ReactGA from "react-ga";
import "./App.css";
import history from "./History";
import { isEventAdmin, isRegistrationAdmin, isRegistrationVolunteer, isEventReviewer, isActionEditor } from "./utils/user";
import { withTranslation } from 'react-i18next';
import { userService } from "./services/user";
ReactGA.initialize("UA-136093201-1", {
debug: false,
testMode: process.env.NODE_ENV === "test"
});
ReactGA.pageview(window.location.pathname + window.location.search);
history.listen(location => {
ReactGA.pageview(location.pathname + location.search);
});
class EventNav extends Component {
constructor(props) {
super(props);
this.state = {
collapsed: true
};
}
render() {
const t = this.props.t;
return (
<nav className="navbar navbar-expand-sm bg-white navbar-light">
<a href={`/${this.props.eventKey}`} className="navbar-brand">{this.props.event.name}</a>
<div className={
"collapse navbar-collapse" +
(this.state.collapsed ? " collapsed" : "")
} id="eventNavbar">
<ul className="navbar-nav">
{this.props.user &&
this.props.event &&
this.props.event.is_application_open && (
<li className="nav-item">
<NavLink
to={`/${this.props.eventKey}/apply`}
activeClassName="nav-link active"
className="nav-link"
onClick={this.props.toggleMenu}
>
{t('Apply')}
</NavLink>
</li>
)}
{this.props.user && this.props.event && this.props.event.is_offer_open && (
<li className="nav-item">
<NavLink
to={`/${this.props.eventKey}/offer`}
activeClassName="nav-link active"
className="nav-link"
onClick={this.props.toggleMenu}
>
{t('Offer')}
</NavLink>
</li>
)}
{this.props.user &&
this.props.event &&
this.props.event.is_registration_open && (
<li className="nav-item dropdown ">
<div
className="nav-link dropdown-toggle"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
{t('Registration')}
</div>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<NavLink
to={`/${this.props.eventKey}/registration`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Registration Form')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/invitationLetter`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Invitation Letter')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/indemnity`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Indemnity Form')}
</NavLink>
{/* <NavLink
to={`/${this.props.eventKey}/invoices`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Invoices')}
</NavLink> */}
</div>
</li>
)}
{isEventAdmin(this.props.user, this.props.event) && (
<AdminMenu t={t} label="Event Admin">
<NavLink
to={`/${this.props.eventKey}/eventConfig`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Edit Event Details')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewAssignment`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review Assignment')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/invitedGuests`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Invited Guests')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/responseList`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Response List')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewDashboard`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review Dashboard')}
</NavLink>
<h6 className='dropdown-submenu-header'>Form Settings</h6>
<NavLink
to={`/${this.props.eventKey}/applicationform`}
className="dropdown-item dropdown-submenu-item"
onClick={this.props.toggleMenu}
>
{t('Application Form')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewForm`}
className="dropdown-item dropdown-submenu-item"
onClick={this.props.toggleMenu}
>
{t('Review Form')}
</NavLink>
</AdminMenu>
)}
{isEventReviewer(this.props.user, this.props.event) &&
this.props.event &&
this.props.event.is_review_open && (
<li className="nav-item dropdown">
<div
className="nav-link dropdown-toggle"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
{t('Reviews')}
</div>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<NavLink
to={`/${this.props.eventKey}/reviewlist`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewHistory`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review History')}
</NavLink>
</div>
</li>
)}
{isActionEditor(this.props.user, this.props.event) &&
this.props.event &&
this.props.event.is_review_open && (
<li className="nav-item dropdown">
<div
className="nav-link dropdown-toggle"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
{t('Reviews')}
</div>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
<NavLink
to={`/${this.props.eventKey}/responseList`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Response List')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewlist`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review')}
</NavLink>
<NavLink
to={`/${this.props.eventKey}/reviewHistory`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Review History')}
</NavLink>
</div>
</li>
)}
{(isRegistrationAdmin(this.props.user, this.props.event) || isRegistrationVolunteer(this.props.user, this.props.event)) &&
this.props.event &&
this.props.event.is_registration_open && (
<li className="nav-item dropdown">
<div
className="nav-link dropdown-toggle"
id="navbarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
{t('Registration Admin')}
</div>
<div className="dropdown-menu" aria-labelledby="navbarDropdown">
{isRegistrationAdmin(this.props.user, this.props.event) && <NavLink
to={`/${this.props.eventKey}/registrationAdmin`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Unconfirmed Registrations')}
</NavLink>}
{isRegistrationVolunteer(this.props.user, this.props.event) && (
<NavLink
to={`/${this.props.eventKey}/eventAttendance`}
className="dropdown-item"
onClick={this.props.toggleMenu}
>
{t('Event Attendance')}
</NavLink>
)}
</div>
</li>
)}
</ul>
</div>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#eventNavbar"
aria-controls="eventNavbar"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon" />
</button>
</nav>
);
}
}
const EventNavTranslation = withTranslation()(EventNav);
class LanguageSelectorComponent extends Component {
changeLanguage = (lang) => {
// Change the language using i18next
if (this.props.i18n) {
this.props.i18n.changeLanguage(lang).then(()=>{
const currentUser = JSON.parse(localStorage.getItem("user"))
if (currentUser) {
// We send a put request to the user service to update the language on the back-end.
// Note the language is automatically sent with every request through axios
userService.get().then(result => {
userService.update({
email: result.email,
firstName: result.firstname,
lastName: result.lastname,
title: result.user_title
});
});
}
window.location.reload(true);
});
}
}
render() {
if (this.props.organisation && this.props.organisation.languages.length > 1) {
return (
<ul className="navbar-nav language-navbar">
<li className="nav-item dropdown">
<button
className="nav-link dropdown-toggle link-style"
id="userDropdown"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
<i className="fas fa-globe menu-icon" />{" "}
{this.props.i18n.language}
</button>
<div className="dropdown-menu" aria-labelledby="userDropdown">
{this.props.organisation.languages.map(lang => (
<button className="dropdown-item cursor-pointer" onClick={() => this.changeLanguage(lang.code)} key={lang.code}>{lang.description}</button>
))}
</div>
</li>
</ul>)
}
return <div></div>
}
}
const LanguageSelector = withTranslation()(LanguageSelectorComponent);
class AppComponent extends Component {
constructor(props) {
super(props);
this.state = {
user: JSON.parse(localStorage.getItem("user")),
collapsed: true,
eventKey: null,
currentEvent: null,
error: null
};
this.refreshUser = this.refreshUser.bind(this);
}
componentDidMount() {
userService.authRefresh().then(user => {
if (!user.error) {
localStorage.setItem("user", JSON.stringify(user));
this.setState({
user: user
});
}
else {
localStorage.removeItem("user");
}
});
}
handleLogout = () => {
this.refreshUser();
window.location = '/';
}
refreshUser() {
const currentUser = JSON.parse(localStorage.getItem("user"));
this.setState({
user: currentUser
});
if (currentUser) {
// Send a user profile update to record the currently selected language
userService.get().then(result => {
userService.update({
email: result.email,
firstName: result.firstname,
lastName: result.lastname,
title: result.user_title
});
});
}
}
toggleMenu = () => {
this.setState({ collapsed: !this.state.collapsed });
};
setEvent = (eventKey, event) => {
this.setState({
eventKey: eventKey,
currentEvent: event
});
};
render() {
const t = this.props.t;
return (
<Router history={history}>
<div class="notranslate" translate="no">
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
<a className="navbar-brand navbar-brand-main" href="/">
<img
src={
this.props.organisation &&
require("./images/" + this.props.organisation.icon_logo)
}
width="30"
height="30"
className="d-inline-block align-top brand-image"
alt=""
/>
{this.props.organisation && this.props.organisation.system_name}
</a>
<div
className={
"collapse navbar-collapse" +
(this.state.collapsed ? " collapsed" : "")
}
id="navbarNav"
>
<ul className="navbar-nav mr-auto"></ul>
<LanguageSelector organisation={this.props.organisation} />
<UserDropdown
logout={this.handleLogout}
user={this.state.user}
onClick={this.toggleMenu}
/>
</div>
<div>
<ul className="navbar-nav mr-auto"></ul>
</div>
<button
className="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNav"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span className="navbar-toggler-icon" />
</button>
</nav>
{this.state.currentEvent && <EventNavTranslation
eventKey={this.state.eventKey}
event={this.state.currentEvent}
user={this.state.user} />}
<div className="Body">
<div className="container-fluid">
{this.state.error && <div className="alert alert-danger">{this.state.error}</div>}
<Switch>
<Route
exact
path="/"
render={props => (
<Home
{...props}
user={this.state.user}
setEvent={this.setEvent}
/>
)}
/>
<Route
exact
path="/login"
render={props => (
<Login {...props} loggedIn={this.refreshUser} organisation={this.props.organisation} />
)}
/>
<Route
exact
path="/createAccount"
render={props => (
<CreateAccount
{...props}
loggedIn={this.refreshUser}
organisation={this.props.organisation}
/>
)}
/>
<Route
exact
path="/eventConfig"
render={props => (
<EventConfig
{...props}
loggedIn={this.refreshUser}
organisation={this.props.organisation}
/>
)}
/>
<Route
exact
path="/resetPassword"
render={props => (
<ResetPassword {...props} loggedIn={this.refreshUser} />
)}
/>
<Route
exact
path="/responseList"
render={props => (
<ResponseList {...props} loggedIn={this.refreshUser} />
)}
/>
<Route exact path="/verifyEmail" component={VerifyEmail} />
<Route exact path="/file/:filename" component={ViewFile} />
<PrivateRoute exact path="/profile" component={Profile} />
<Route exact path="/reference/:token" component={Reference} />
<PrivateRoute exact path="/payment/:invoiceId" component={Payment} />
<Route exact path="/payment-success" component={Success} />
<Route exact path="/payment-cancel" component={Failed} />
<Route
path="/:eventKey"
render={props => (
<EventHome {...props}
setEvent={this.setEvent}
user={this.state.user}
eventKey={this.state.eventKey}
event={this.state.currentEvent}
organisation={this.props.organisation}
/>
)}
/>
</Switch>
</div>
</div>
<footer className="text-muted">
<div className="container-flex">
<div>
{this.props.organisation && this.props.organisation.system_name}
, © {new Date().getFullYear()} |{" "}
<a
href={this.props.organisation && this.props.organisation.url}
>
{this.props.organisation && this.props.organisation.name}
</a>{" "}
|{" "}
<a
href={
"/" +
(this.props.organisation
? this.props.organisation.privacy_policy
: "")
}
target="_blank"
rel="noopener noreferrer"
>
{t('Privacy Policy')}
</a>
{this.props.organisation &&
this.props.organisation.system_name !== "Baobab" && (
<div className="float-right powered-by">
{t('Powered by')}{" "}
<a
href="http://www.deeplearningindaba.com"
target="_blank"
rel="noopener noreferrer"
>
Baobab
</a>
</div>
)}
</div>
</div>
</footer>
<CookieConsent
cookieName="baobab-cookie-consent"
style={{ background: "#343a40" }}
buttonStyle={{ fontWeight: "bold" }}
buttonText={t("I understand")}
buttonClasses="btn btn-primary"
buttonId="btn-cookieConsent"
containerClasses="alert alert-warning col-lg-12"
>
<h5>{t('cookieTitle')}</h5>
<span style={{ fontSize: "0.8em" }}>
{t('cookieText')}{" "}
<a
href={
"/" +
(this.props.organisation
? this.props.organisation.privacy_policy
: "")
}
>
{t('Privacy Policy')}
</a>
</span>
</CookieConsent>
</div>
</Router>
);
}
}
const App = withTranslation()(AppComponent);
export default App;