Client: admin menu init

This commit is contained in:
SamR1 2018-01-28 22:36:13 +01:00
parent edddfd0678
commit a23643b24d
4 changed files with 82 additions and 16 deletions

View File

@ -0,0 +1,43 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
class AdminMenu extends React.Component {
componentDidMount() {}
render() {
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
<h1 className="page-title">Administration</h1>
<div className="container">
<div className="row">
<div className="col-md-2" />
<div className="col-md-8 card">
<ul>
<li>
<Link
to={{
pathname: '/admin/sports',
}}
>
Sports
</Link>
</li>
</ul>
</div>
<div className="col-md-2" />
</div>
</div>
</div>
)
}
}
export default connect(
state => ({
user: state.user,
})
)(AdminMenu)

View File

@ -0,0 +1,23 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
class AdminSports extends React.Component {
componentDidMount() {}
render() {
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
<h1 className="page-title">Administration - Sports</h1>
</div>
)
}
}
export default connect(
state => ({
user: state.user,
})
)(AdminSports)

View File

@ -1,8 +1,13 @@
import React from 'react' import React from 'react'
import { Helmet } from 'react-helmet' import { Helmet } from 'react-helmet'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { Redirect, Route, Switch } from 'react-router-dom'
import AdminMenu from './AdminMenu'
import AdminSports from './AdminSports'
import AccessDenied from './../Others/AccessDenied' import AccessDenied from './../Others/AccessDenied'
import NotFound from './../Others/NotFound'
import { isLoggedIn } from '../../utils'
class Admin extends React.Component { class Admin extends React.Component {
componentDidMount() {} componentDidMount() {}
@ -13,11 +18,17 @@ class Admin extends React.Component {
<Helmet> <Helmet>
<title>mpwo - Admin</title> <title>mpwo - Admin</title>
</Helmet> </Helmet>
{!user.isAdmin ? ( {isLoggedIn() ? (
<AccessDenied /> user.isAdmin ? (
<Switch>
<Route exact path="/admin" component={AdminMenu} />
<Route path="/admin/sports" component={AdminSports} />
<Route component={NotFound} />
</Switch>
) : ( ) : (
<h1 className="page-title">Admin</h1> <AccessDenied />
)} )
) : (<Redirect to="/login" />)}
</div> </div>
) )
} }

View File

@ -83,18 +83,7 @@ export default class App extends React.Component {
) )
)} )}
/> />
<Route <Route path="/admin" component={Admin} />
exact path="/admin"
render={() => (
isLoggedIn() ? (
<Admin />
) : (
<UserForm
formType={'Login'}
/>
)
)}
/>
<Route component={NotFound} /> <Route component={NotFound} />
</Switch> </Switch>
</div> </div>