Skip to content

Commit

Permalink
show dashboard also to admins
Browse files Browse the repository at this point in the history
  • Loading branch information
georgesimos committed Nov 9, 2019
1 parent 691b215 commit 52b75ff
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
43 changes: 27 additions & 16 deletions client/src/layouts/Dashboard/components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { NavLink } from 'react-router-dom';
import {
withStyles,
Expand All @@ -18,7 +19,7 @@ import styles from './styles';

class Sidebar extends Component {
render() {
const { classes } = this.props;
const { classes, user } = this.props;
return (
<section className={classes.root}>
<List component="div" disablePadding>
Expand Down Expand Up @@ -87,20 +88,21 @@ class Sidebar extends Component {
primary="Reservations"
/>
</ListItem>
<ListItem
activeClassName={classes.activeListItem}
className={classes.listItem}
component={NavLink}
to="/admin/users">
<ListItemIcon className={classes.listItemIcon}>
<PeopleIcon />
</ListItemIcon>
<ListItemText
classes={{ primary: classes.listItemText }}
primary="Users"
/>
</ListItem>

{user && user.role === 'superadmin' && (
<ListItem
activeClassName={classes.activeListItem}
className={classes.listItem}
component={NavLink}
to="/admin/users">
<ListItemIcon className={classes.listItemIcon}>
<PeopleIcon />
</ListItemIcon>
<ListItemText
classes={{ primary: classes.listItemText }}
primary="Users"
/>
</ListItem>
)}
<ListItem
activeClassName={classes.activeListItem}
className={classes.listItem}
Expand Down Expand Up @@ -156,4 +158,13 @@ class Sidebar extends Component {
}
}

export default withStyles(styles)(Sidebar);
const mapStateToProps = state => ({
user: state.authState.user
});

const mapDispatchToProps = {};

export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(Sidebar));
2 changes: 1 addition & 1 deletion client/src/layouts/Dashboard/components/Topbar/Topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Topbar extends Component {
</div>

<NavLink className={classes.title} to="/">
Return
Cinema App
</NavLink>

<IconButton
Expand Down
4 changes: 2 additions & 2 deletions client/src/layouts/Public/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Navbar extends Component {
<Link className={classes.navLink} to="/">
Home
</Link>
{user && user.role === 'superadmin' && (
{user && user.role !== 'guest' && (
<Link className={classes.navLink} to="/admin/dashboard">
Dashboard
</Link>
Expand Down Expand Up @@ -102,7 +102,7 @@ class Navbar extends Component {
Home
</Link>
</li>
{user && user.role === 'superadmin' && (
{user && user.role !== 'guest' && (
<li className={classes.innerNavListItem}>
<Link className={classes.innerNavLink} to="/admin/dashboard">
Dashboard
Expand Down
4 changes: 3 additions & 1 deletion client/src/pages/Public/Login/components/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function LoginForm(props) {
const handleFieldChange = e =>
setValues({
...values,
[e.target.name]: [e.target.value]
[e.target.name]: e.target.value
});

return (
Expand All @@ -110,6 +110,7 @@ function LoginForm(props) {
type="text"
value={values.username}
variant="outlined"
placeholder="Use demo1"
/>
<TextField
className={classes.textField}
Expand All @@ -119,6 +120,7 @@ function LoginForm(props) {
type="password"
value={values.password}
variant="outlined"
placeholder="Use demo123456"
/>
</div>

Expand Down
3 changes: 2 additions & 1 deletion server/src/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ router.patch("/users/:id", auth, async (req, res) => {
"phone",
"username",
"email",
"password"
"password",
"role"
];
const isValidOperation = updates.every(update =>
allowedUpdates.includes(update)
Expand Down

0 comments on commit 52b75ff

Please sign in to comment.