This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
108 lines (98 loc) · 3.72 KB
/
App.js
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
import React, {Component} from 'react';
import './App.css';
import Cells from "./components/sprint/Cells";
import {BrowserRouter, Redirect, Route, Switch} from "react-router-dom";
import routes from './routes.js'
import Login from "./components/Login";
import {connect, Provider} from "react-redux";
import {auth} from "./actions/";
import {applyMiddleware, createStore} from "redux";
import thunk from "redux-thunk";
import reducer from "./reducers";
import Register from "./components/Register";
import Logout from "./components/Logout";
import VerifyEmail from "./components/VerifyEmail";
import Board from "./components/sprint/Board";
import UserBoard from "./components/sprint/UserBoard";
import SustainabilityBoard from "./components/sustainability/SustainabilityBoard";
import BudgetBoard from "./components/sustainability/BudgetBoard";
import {SPRINTS_DOCS} from "./constants";
let store = createStore(reducer, applyMiddleware(thunk));
export default class App extends Component {
render() {
return (
<BrowserRouter>
<Switch>
<Provider store={store}>
<Route component={RootContainer}/>
</Provider>
</Switch>
</BrowserRouter>
)
}
}
class RootContainerComponent extends Component {
componentDidMount() {
this.props.loadUser();
}
PrivateRoute = ({component: ChildComponent, ...rest}) => {
return <Route {...rest} render={props => {
if (this.props.auth.isLoading) {
return <em>Loading...</em>;
} else if (!this.props.auth.isAuthenticated) {
let next_path = this.props.location.pathname;
next_path = (next_path !== "/" && !next_path.startsWith("/login")) ? "?next=" + next_path : "";
return <Redirect to={routes.login + next_path}/>;
} else {
return <ChildComponent {...props} />
}
}}/>
};
render() {
let {PrivateRoute} = this;
return (
<div className="page app">
<div className="page interactions">
{
this.props.auth.isAuthenticated
? <div className="navbar">
<Logout/>
</div>
: <div/>
}
</div>
<h1>
OpenCraft <a href={SPRINTS_DOCS} target='_blank' rel='noopener noreferrer'>
Sprint Planning Report
</a>
</h1>
<BrowserRouter>
<Switch>
<PrivateRoute exact path={routes.cells} component={Cells}/>
<PrivateRoute path={routes.user_board} component={UserBoard}/>
<PrivateRoute path={routes.board} component={Board}/>
<Route path={routes.login} component={Login}/>
<Route path={routes.register} component={Register}/>
<Route path={routes.verify_email} component={VerifyEmail}/>
<Route component={Login}/>
</Switch>
</BrowserRouter>
<PrivateRoute component={SustainabilityBoard}/>
<PrivateRoute component={BudgetBoard}/>
</div>
);
}
}
const mapStateToProps = state => {
return {
auth: state.auth,
}
};
const mapDispatchToProps = dispatch => {
return {
loadUser: () => {
return dispatch(auth.loadUser());
}
}
};
let RootContainer = connect(mapStateToProps, mapDispatchToProps)(RootContainerComponent);