I am trying to implement a role based access menu into my React app and have used a NavBar from Material UI. I had it working previously but since I removed the hooks when I changed it to a class component I can't get it isn't displaying correctly and I can't get the drop down to work.
I also have a problem as there is a 'user' json in my Redux and for some reason the componentDidMount isn't picking it up for me to pull the userRole number to display the correct options for a particular role.
Console error messages
Warning: Failed prop type: The prop `open` is marked as required in `ForwardRef(Menu)`, but its value is `null`
Warning: Failed prop type: The prop `open` is marked as required in `ForwardRef(Popover)`, but its value is `null`.
Warning: Failed prop type: The prop `open` is marked as required in `ForwardRef(SimpleBackdrop)`, but its value is `null`.
Warning: Failed prop type: The prop `open` is marked as required in `Unstable_TrapFocus`, but its value is `null`.
Warning: Failed prop type: Material-UI: You are providing an onClick event listener to a child of a button element.
Firefox will never trigger the event.
scubaNavBar.component.js
class ScubaNavbar extends Component {
constructor(props) {
super(props);
this.logOut = this.logOut.bind(this);
this.state = {
showUserLevelAccess: false,
showSchoolLevelAccess: false,
showAdminLevelAccess: false,
user: undefined,
anchorEl: null,
mobileMoreAnchorEl: null,
isMenuOpen: null,
isMobileMenuOpen: null,
};
history.listen((location) => {
props.dispatch(clearMessage());
});
}
componentDidMount() {
const user = this.props.user;
if (user) {
this.setState({
currentUser: user,
showUserLevelAccess: user.userRoles === 1,
showSchoolLevelAccess: user.userRoles === 2,
showSiteAdminLevelAccess: user.userRoles === 3,
});
}
}
logOut() {
this.props.dispatch(logout());
}
render() {
const {
// current user gives specific user details
currentUser,
// levels give role access
showUserLevelAccess,
showSchoolLevelAccess,
showSiteAdminLevelAccess,
} = this.state;
const { classes } = this.props;
**const handleProfileMenuOpen =() => {
this.setState({anchorEl: this.currentTarget, open: Boolean(this.currentTarget)});
};
const handleMenuClose = () => {
this.setState({anchorEl: this.currentTarget === null});
};
const handleMobileMenuOpen = () => {
this.setState({mobileMoreAnchorEl: this.currentTarget, open: Boolean(this.currentTarget)});
};
const handleMobileMenuClose = () => {
this.setState({mobileMoreAnchorEl: this.currentTarget === null});
};**
const menuId = 'dark-search-account-menu';
const renderMenu = (
<Menu
anchorEl={this.state.anchorEl}
anchorOrigin={{vertical: 'top', horizontal: 'right'}}
id={menuId}
keepMounted
transformOrigin={{vertical: 'top', horizontal: 'right'}}
open={this.state.isMenuOpen}
onClose={handleMenuClose}>