-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRoot.js
More file actions
37 lines (33 loc) · 1.15 KB
/
Root.js
File metadata and controls
37 lines (33 loc) · 1.15 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
import React, { Component } from 'react'
import {Route} from 'react-router-dom'
import AdminPage from './routes/AdminPage'
import AuthPage from './routes/AuthPage'
import PersonPage from './routes/PersonPage'
import ProtectedRoute from './common/ProtectedRoute'
import {connect} from 'react-redux'
import {moduleName, signOut} from '../ducks/auth'
import {Link} from 'react-router-dom'
class Root extends Component {
static propTypes = {
};
render() {
const {signOut, signedIn} = this.props
const controls = signedIn
? (<div>
<Link to="/people">People</Link>
<button onClick = {signOut}>Sign out</button>
</div>)
: <Link to="/auth/signin">Sign in</Link>
return (
<div>
{controls}
<ProtectedRoute path="/admin" component={AdminPage}/>
<ProtectedRoute path="/people" component={PersonPage}/>
<Route path="/auth" component={AuthPage}/>
</div>
)
}
}
export default connect(state => ({
signedIn: !!state[moduleName].user
}), {signOut}, null, {pure: false})(Root)