Skip to content
Snippets Groups Projects
Navigation.jsx 1.77 KiB
Newer Older
import React from 'react'
john's avatar
john committed
import { browserHistory } from 'react-router'
import { LinkContainer } from 'react-router-bootstrap'
import { Navbar, Nav, NavItem, NavbarBrand } from 'react-bootstrap'

import Authorize from 'pubsweet-frontend/src/helpers/Authorize'
import NavbarUser from 'pubsweet-component-navigation/NavbarUser'

export default class Navigation extends React.Component {
john's avatar
john committed
  constructor (props) {
    super(props)
    this.logout = this.logout.bind(this)
  }

  logout () {
    const { logoutUser } = this.props.actions
    logoutUser()
chris's avatar
chris committed
    browserHistory.push('/login')
john's avatar
john committed
  }
john's avatar
john committed
    const { currentUser } = this.props
    let logoutButtonIfAuthenticated
john's avatar
john committed

    if (currentUser.isAuthenticated) {
john's avatar
john committed
      logoutButtonIfAuthenticated = (
        <NavbarUser
          user={currentUser.user}
          onLogoutClick={this.logout}
        />
      )
john's avatar
john committed

    // TODO --  fix object properties underneath
    return (
      <Navbar fluid>
john's avatar
john committed

        <Navbar.Header>
          <NavbarBrand>
            <a href='#'><img src='/pubsweet.jpg' alt='pubsweet' /></a>
          </NavbarBrand>
        </Navbar.Header>
john's avatar
john committed

        <Nav>
          <LinkContainer to='/books'>
            <NavItem>Books</NavItem>
          </LinkContainer>
john's avatar
john committed

          <Authorize operation='read' object={currentUser.user}>
john's avatar
john committed
            <LinkContainer to='/users'>
              <NavItem>Users</NavItem>
            </LinkContainer>
          </Authorize>
john's avatar
john committed

john's avatar
john committed
          <Authorize operation='read'>
john's avatar
john committed
            <LinkContainer to='/teams'>
              <NavItem>Teams</NavItem>
            </LinkContainer>
          </Authorize>
john's avatar
john committed

john's avatar
john committed

        { logoutButtonIfAuthenticated }
john's avatar
john committed

      </Navbar>
    )
  }
}

Navigation.propTypes = {
  actions: React.PropTypes.object.isRequired,
  currentUser: React.PropTypes.object
}