2

I'm creating a menu that shows items based on user roles.

Some items must show if role is A OR B, but I cant make this work.

Code example :

      {
       (this.props.currentUser.role === 'admin') || ( this.props.currentUser.role === 'contra')  &&
        <Dropdown item text='ADMIN'>
          <Dropdown.Menu>
            {
              this.props.currentUser.role === 'admin' &&
            <div>
              <Dropdown.Item>
                <Link to="/companies/list">Companies</Link>
              </Dropdown.Item>
              <Dropdown.Item>
                <Link to="/obs-report">Obs Report</Link>
              </Dropdown.Item>
            </div>
            }
            <Dropdown.Item>
              <Link to="/users/list">Users</Link>
            </Dropdown.Item>
          </Dropdown.Menu>
        </Dropdown>
      }

This shows properly items only for "contra" role, not sure about why is not working with 'admin' role.

Tried with this too with no success :

this.props.currentUser.role === ('admin' || 'contra')
3
  • check by enclosing (this.props.currentUser.role === 'admin') || ( this.props.currentUser.role === 'contra') with another paranthesis like ((this.props.currentUser.role === 'admin') || ( this.props.currentUser.role === 'contra')) && .... Commented Mar 14, 2018 at 6:14
  • Yes!, just noted that. Thanks for your answer Commented Mar 14, 2018 at 6:15
  • happy that you noted that Commented Mar 14, 2018 at 6:15

1 Answer 1

10

Forgot to wrap :)

((this.props.currentUser.role == 'admin') || ( this.props.currentUser.role == 'contra'))  &&

hope it helps somebody

Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.