Client: refactor + minor changes

This commit is contained in:
Sam 2018-06-07 13:34:12 +02:00
parent 424df3b721
commit c314c79f86
5 changed files with 97 additions and 115 deletions

View File

@ -9,31 +9,28 @@ import ActivityEdit from './ActivityEdit'
import NotFound from './../Others/NotFound'
import { isLoggedIn } from '../../utils'
class Activity extends React.Component {
componentDidMount() {}
render() {
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
{isLoggedIn() ? (
<Switch>
<Route exact path="/activities/add" component={ActivityAdd} />
<Route
exact path="/activities/:activityId"
component={ActivityDisplay}
/>
<Route
exact path="/activities/:activityId/edit"
component={ActivityEdit}
/>
<Route component={NotFound} />
</Switch>
) : (<Redirect to="/login" />)}
</div>
)
}
function Activity () {
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
{isLoggedIn() ? (
<Switch>
<Route exact path="/activities/add" component={ActivityAdd} />
<Route
exact path="/activities/:activityId"
component={ActivityDisplay}
/>
<Route
exact path="/activities/:activityId/edit"
component={ActivityEdit}
/>
<Route component={NotFound} />
</Switch>
) : (<Redirect to="/login" />)}
</div>
)
}
export default connect(

View File

@ -1,45 +1,35 @@
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">
<div className="card-body">
<ul className="admin-items">
<li>
<Link
to={{
pathname: '/admin/sports',
}}
>
Sports
</Link>
</li>
</ul>
</div>
export default function AdminMenu () {
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">
<div className="card-body">
<ul className="admin-items">
<li>
<Link
to={{
pathname: '/admin/sports',
}}
>
Sports
</Link>
</li>
</ul>
</div>
<div className="col-md-2" />
</div>
<div className="col-md-2" />
</div>
</div>
)
}
</div>
)
}
export default connect(
state => ({
user: state.user,
})
)(AdminMenu)

View File

@ -11,37 +11,34 @@ import AccessDenied from './../Others/AccessDenied'
import NotFound from './../Others/NotFound'
import { isLoggedIn } from '../../utils'
class Admin extends React.Component {
componentDidMount() {}
render() {
const { user } = this.props
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
{isLoggedIn() ? (
user.isAdmin ? (
<Switch>
<Route exact path="/admin" component={AdminMenu} />
<Route exact path="/admin/sports" component={AdminSports} />
<Route
exact path="/admin/sports/add"
component={AdminSportsAdd}
/>
<Route
exact path="/admin/sports/:sportId"
component={AdminSport}
/>
<Route component={NotFound} />
</Switch>
) : (
<AccessDenied />
)
) : (<Redirect to="/login" />)}
</div>
)
}
function Admin (props) {
const { user } = props
return (
<div>
<Helmet>
<title>mpwo - Admin</title>
</Helmet>
{isLoggedIn() ? (
user.isAdmin ? (
<Switch>
<Route exact path="/admin" component={AdminMenu} />
<Route exact path="/admin/sports" component={AdminSports} />
<Route
exact path="/admin/sports/add"
component={AdminSportsAdd}
/>
<Route
exact path="/admin/sports/:sportId"
component={AdminSport}
/>
<Route component={NotFound} />
</Switch>
) : (
<AccessDenied />
)
) : (<Redirect to="/login" />)}
</div>
)
}
export default connect(

View File

@ -1,6 +1,7 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import ActivityCard from './ActivityCard'
import Calendar from './../Others/Calendar'
@ -56,7 +57,14 @@ class DashBoard extends React.Component {
sports={sports}
/>)
)) : (
'No activities. Upload one !'
<div className="card text-center">
<div className="card-body">
No workouts. {' '}
<Link to={{ pathname: '/activities/add' }}>
Upload one !
</Link>
</div>
</div>
)}
{!paginationEnd &&
<input

View File

@ -1,26 +1,16 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
class AccessDenied extends React.Component {
componentDidMount() {}
render() {
return (
<div>
<Helmet>
<title>mpwo - Access denied</title>
</Helmet>
<h1 className="page-title">Access denied</h1>
<p className="App-center">
{'You don\'t have permissions to access this page.'}
</p>
</div>
)
}
export default function AccessDenied () {
return (
<div>
<Helmet>
<title>mpwo - Access denied</title>
</Helmet>
<h1 className="page-title">Access denied</h1>
<p className="App-center">
{'You don\'t have permissions to access this page.'}
</p>
</div>
)
}
export default connect(
state => ({
user: state.user,
})
)(AccessDenied)