-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/admin-system' into dev
- Loading branch information
Showing
9 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import Navbar from 'react-bootstrap/lib/Navbar'; | ||
import Grid from 'react-bootstrap/lib/Grid'; | ||
import Row from 'react-bootstrap/lib/Row'; | ||
import Col from 'react-bootstrap/lib/Col'; | ||
import Nav from 'react-bootstrap/lib/Nav'; | ||
import NavItem from 'react-bootstrap/lib/NavItem'; | ||
import ErrorList from '../utils/ErrorList'; | ||
|
||
const AdminPageLayout = ({ children, ...rest }) => ( | ||
<div> | ||
<Navbar fluid> | ||
<Navbar.Header> | ||
<Navbar.Brand> | ||
<a href="/admin">Express-React-HMR-Boilerplate Admin System</a> | ||
</Navbar.Brand> | ||
<Navbar.Toggle /> | ||
</Navbar.Header> | ||
<Navbar.Collapse> | ||
</Navbar.Collapse> | ||
</Navbar> | ||
<Grid fluid> | ||
<Row> | ||
<Col md={2}> | ||
<Nav bsStyle="pills" stacked activeKey={1}> | ||
<NavItem eventKey={1} href="/admin/user">User</NavItem> | ||
<NavItem eventKey={2} href="/">Go back to site</NavItem> | ||
</Nav> | ||
</Col> | ||
<Col md={10} {...rest}> | ||
<ErrorList /> | ||
{children} | ||
</Col> | ||
</Row> | ||
</Grid> | ||
</div> | ||
); | ||
|
||
export default AdminPageLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import React from 'react'; | ||
import Grid from 'react-bootstrap/lib/Grid'; | ||
import Navigation from '../utils/Navigation'; | ||
import ErrorList from '../utils/ErrorList'; | ||
|
||
const PageLayout = ({ children, ...rest }) => ( | ||
<Grid {...rest}> | ||
{children} | ||
</Grid> | ||
<div> | ||
<Navigation /> | ||
<ErrorList /> | ||
<Grid {...rest}> | ||
{children} | ||
</Grid> | ||
</div> | ||
); | ||
|
||
export default PageLayout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { withRouter } from 'react-router'; | ||
import PageHeader from 'react-bootstrap/lib/PageHeader'; | ||
import Table from 'react-bootstrap/lib/Table'; | ||
import Resources from '../../../../constants/Resources'; | ||
import userAPI from '../../../../api/user'; | ||
import { pushErrors } from '../../../../actions/errorActions'; | ||
import { setCrrentPage, setPage } from '../../../../actions/pageActions'; | ||
import PageLayout from '../../../layouts/AdminPageLayout'; | ||
import Pagination from '../../../utils/BsPagination'; | ||
|
||
class ListPage extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
users: [], | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
let { dispatch, location } = this.props; | ||
dispatch(setCrrentPage(Resources.USER, location.query.page || 1)); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
let { dispatch, apiEngine, page, router, location } = this.props; | ||
|
||
if (prevProps.page.current !== page.current) { | ||
userAPI(apiEngine) | ||
.list({ page: page.current }) | ||
.catch((err) => { | ||
dispatch(pushErrors(err)); | ||
throw err; | ||
}) | ||
.then((json) => { | ||
this.setState({ users: json.users }); | ||
dispatch(setPage(Resources.USER, json.page)); | ||
router.push({ | ||
pathname: location.pathname, | ||
query: { page: json.page.current }, | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
let { users } = this.state; | ||
|
||
return ( | ||
<PageLayout> | ||
<PageHeader>User List</PageHeader> | ||
<Table striped bordered> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Email</th> | ||
<th>Role</th> | ||
<th>Created At</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{users.map((user) => ( | ||
<tr key={user._id}> | ||
<td>{user._id}</td> | ||
<td>{user.name}</td> | ||
<td>{user.email.value}</td> | ||
<td>{user.role}</td> | ||
<td>{user.createdAt}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
<Pagination resourceName={Resources.USER} /> | ||
</PageLayout> | ||
); | ||
} | ||
} | ||
|
||
export default withRouter(connect(state => ({ | ||
apiEngine: state.apiEngine, | ||
page: state.pages[Resources.USER] || {}, | ||
}))(ListPage)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export default { | ||
USER: 'USER', | ||
TODO: 'TODO', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Roles from '../../constants/Roles'; | ||
import compose from '../../utils/composeEnterHooks'; | ||
|
||
export default (store) => ({ | ||
path: 'admin', | ||
getIndexRoute(location, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, { | ||
component: | ||
require('../../components/pages/admin/user/ListPage').default, | ||
}); | ||
}); | ||
}, | ||
getChildRoutes(location, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, [ | ||
require('./user').default(store), | ||
]); | ||
}); | ||
}, | ||
onEnter: compose.series( | ||
require('../../utils/authRequired').default(store), | ||
require('../../utils/roleRequired').default(store)(Roles.ADMIN), | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default (store) => ({ | ||
path: 'user', | ||
getIndexRoute(location, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, { | ||
component: | ||
require('../../../components/pages/admin/user/ListPage').default, | ||
}); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters