diff --git a/mpwo_client/src/components/Admin/index.jsx b/mpwo_client/src/components/Admin/index.jsx new file mode 100644 index 00000000..ec171e37 --- /dev/null +++ b/mpwo_client/src/components/Admin/index.jsx @@ -0,0 +1,30 @@ +import React from 'react' +import { Helmet } from 'react-helmet' +import { connect } from 'react-redux' + +import AccessDenied from './../Others/AccessDenied' + +class Admin extends React.Component { + componentDidMount() {} + render() { + const { user } = this.props + return ( +
+ + mpwo - Admin + + {!user.isAdmin ? ( + + ) : ( +

Admin

+ )} +
+ ) + } +} + +export default connect( + state => ({ + user: state.user, + }) +)(Admin) diff --git a/mpwo_client/src/components/App.jsx b/mpwo_client/src/components/App.jsx index 7ac929c9..666df375 100644 --- a/mpwo_client/src/components/App.jsx +++ b/mpwo_client/src/components/App.jsx @@ -2,10 +2,11 @@ import React from 'react' import { Redirect, Route, Switch } from 'react-router-dom' import './App.css' +import Admin from './Admin' import Dashboard from './Dashboard' import Logout from './User/Logout' import NavBar from './NavBar' -import NotFound from './NotFound' +import NotFound from './Others/NotFound' import Profile from './User/Profile' import ProfileEdit from './User/ProfileEdit' import UserForm from './User/UserForm' @@ -82,6 +83,18 @@ export default class App extends React.Component { ) )} /> + ( + isLoggedIn() ? ( + + ) : ( + + ) + )} + /> diff --git a/mpwo_client/src/components/Dashboard/index.jsx b/mpwo_client/src/components/Dashboard/index.jsx index b922fb24..cfaf3bfb 100644 --- a/mpwo_client/src/components/Dashboard/index.jsx +++ b/mpwo_client/src/components/Dashboard/index.jsx @@ -2,7 +2,7 @@ import React from 'react' import { Helmet } from 'react-helmet' import { connect } from 'react-redux' -class Logout extends React.Component { +class DashBoard extends React.Component { componentDidMount() {} render() { return ( @@ -20,4 +20,4 @@ export default connect( state => ({ user: state.user, }) -)(Logout) +)(DashBoard) diff --git a/mpwo_client/src/components/NavBar/index.jsx b/mpwo_client/src/components/NavBar/index.jsx index 153b4ad5..51343ecb 100644 --- a/mpwo_client/src/components/NavBar/index.jsx +++ b/mpwo_client/src/components/NavBar/index.jsx @@ -33,6 +33,18 @@ function NavBar (props) { Dashboard + {props.user.isAdmin && ( +
  • + + Admin + +
  • + )}
      {!props.user.isAuthenticated && ( diff --git a/mpwo_client/src/components/Others/AccessDenied.jsx b/mpwo_client/src/components/Others/AccessDenied.jsx new file mode 100644 index 00000000..4f156e97 --- /dev/null +++ b/mpwo_client/src/components/Others/AccessDenied.jsx @@ -0,0 +1,26 @@ +import React from 'react' +import { Helmet } from 'react-helmet' +import { connect } from 'react-redux' + +class AccessDenied extends React.Component { + componentDidMount() {} + render() { + return ( +
      + + mpwo - Access denied + +

      Access denied

      +

      + {'You don\'t have permissions to access this page.'} +

      +
      + ) + } +} + +export default connect( + state => ({ + user: state.user, + }) +)(AccessDenied) diff --git a/mpwo_client/src/components/NotFound.jsx b/mpwo_client/src/components/Others/NotFound.jsx similarity index 100% rename from mpwo_client/src/components/NotFound.jsx rename to mpwo_client/src/components/Others/NotFound.jsx diff --git a/mpwo_client/src/reducers/index.js b/mpwo_client/src/reducers/index.js index 32a46597..bb48280e 100644 --- a/mpwo_client/src/reducers/index.js +++ b/mpwo_client/src/reducers/index.js @@ -84,7 +84,7 @@ const user = (state = initial.user, action) => { case 'LOGOUT': window.localStorage.removeItem('authToken') return initial.user - case 'PROFILE_SUCCESS': + case 'PROFILE_SUCCESS': return { id: action.message.data.id, username: action.message.data.username,