only SuperUser can see navbar tag and access page

This commit is contained in:
Irtiza-h30
2020-05-19 16:04:52 -04:00
parent 29a47b4812
commit 69da810f49
2 changed files with 21 additions and 12 deletions

View File

@@ -71,7 +71,9 @@ const App = () => {
<ProtectedRouteWithLayout exact path="/profiles" component={Profiles} />
<ProtectedRouteWithLayout exact path="/alarms" component={Alarms} />
<ProtectedRouteWithLayout exact path="/account/edit" component={EditAccount} />
<ProtectedRouteWithLayout exact path="/accounts" component={Accounts} />
{user.role === 'SuperUser' && (
<ProtectedRouteWithLayout exact path="/accounts" component={Accounts} />
)}
</Switch>
</ThemeProvider>
</UserProvider>

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';
import { useApolloClient } from '@apollo/react-hooks';
@@ -9,7 +9,11 @@ import { AUTH_TOKEN } from 'constants/index';
import { removeItem } from 'utils/localStorage';
import UserContext from 'contexts/UserContext';
const MasterLayout = ({ children }) => {
const { role } = useContext(UserContext);
const client = useApolloClient();
const location = useLocation();
@@ -39,11 +43,6 @@ const MasterLayout = ({ children }) => {
path: '/alarms',
text: 'Alarms',
},
{
key: 'accounts',
path: '/accounts',
text: 'Accounts',
},
];
const mobileMenuItems = [
@@ -67,11 +66,6 @@ const MasterLayout = ({ children }) => {
path: '/alarms',
text: 'Alarms',
},
{
key: 'accounts',
path: '/accounts',
text: 'Accounts',
},
{
key: 'settings',
@@ -91,6 +85,19 @@ const MasterLayout = ({ children }) => {
},
];
if (role === 'SuperUser') {
menuItems.push({
key: 'accounts',
path: '/accounts',
text: 'Accounts',
});
mobileMenuItems.push({
key: 'accounts',
path: '/accounts',
text: 'Accounts',
});
}
return (
<Layout
onLogout={handleLogout}