Skip to content
Snippets Groups Projects
TopMenu.js 4.34 KiB
Newer Older
Orlando Piñero's avatar
Orlando Piñero committed
import React, { Component } from "react";
import Nav from 'react-bootstrap/Nav';
import Navbar from 'react-bootstrap/Navbar';
import NavDropdown from 'react-bootstrap/NavDropdown';
import UserSessionWidget from "./UserComponents/userSessionWidget";
Orlando Piñero's avatar
Orlando Piñero committed
import Container from 'react-bootstrap/Container';
Orlando Piñero's avatar
Orlando Piñero committed
import { LinkContainer } from 'react-router-bootstrap';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as authenticationActions from '../actions/AuthenticationActions'
import * as userManagementActions from '../actions/UserManagementActions';
import * as degreeCourseManagementActions from '../actions/DegreeCourseManagementActions';
Orlando Piñero's avatar
Orlando Piñero committed

const mapStateToProps = state => {
    return {
        accessToken: state.AuthenticationReducer.accessToken,
        isAdmin: state.AuthenticationReducer.isAdmin
    };
Orlando Piñero's avatar
Orlando Piñero committed
}

Orlando Piñero's avatar
Orlando Piñero committed

class TopMenu extends Component {
Orlando Piñero's avatar
Orlando Piñero committed

    constructor(props) {
        super(props)

        this.handleUserManagementButtonAction = this.handleUserManagementButtonAction.bind(this);
Orlando Piñero's avatar
Orlando Piñero committed
        this.handleDegreeCourseManagementButtonAction = this.handleDegreeCourseManagementButtonAction.bind(this)
Orlando Piñero's avatar
Orlando Piñero committed
    };

    async handleUserManagementButtonAction() {
        const { showAllUsers } = this.props;
        await showAllUsers(this.props.accessToken)
    }

    async handleDegreeCourseManagementButtonAction() {
        const { showAllDegreeCourses } = this.props;
        await showAllDegreeCourses(this.props.accessToken)
    }

Orlando Piñero's avatar
Orlando Piñero committed
    render() {
Orlando Piñero's avatar
Orlando Piñero committed
        let OpenManagementPageButtons;
        console.log(this.props.isAdmin)
Orlando Piñero's avatar
Orlando Piñero committed
        if (this.props.isAdmin) {
Orlando Piñero's avatar
Orlando Piñero committed
            OpenManagementPageButtons =
                <>
                    <LinkContainer to="/userManagement" id="OpenUserManagementPageButton" onClick={this.handleUserManagementButtonAction}>
                        <Nav.Link>User-Management</Nav.Link>
                    </LinkContainer>
                    <LinkContainer to="/degreeCourseManagement" id="OpenDegreeCourseManagementPageButton" onClick={this.handleDegreeCourseManagementButtonAction}>
                        <Nav.Link>DegreeCourse-Management</Nav.Link>
                    </LinkContainer>
                </>
Orlando Piñero's avatar
Orlando Piñero committed
        } else { }
Orlando Piñero's avatar
Orlando Piñero committed
        
Orlando Piñero's avatar
Orlando Piñero committed
        return (
            <div>
                <Navbar bg="light" expand="lg">
Orlando Piñero's avatar
Orlando Piñero committed
                    <Container style={{ margin: 0 }}>
                        <LinkContainer to="/" id="OpenStartPageButton">
                            <Navbar.Brand>BHT</Navbar.Brand>
                        </LinkContainer>
Orlando Piñero's avatar
Orlando Piñero committed
                        <Navbar.Toggle aria-controls="basic-navbar-nav" />
Orlando Piñero's avatar
Orlando Piñero committed
                        <Navbar.Collapse id="basic-navbar-nav" style={{ display: 'flex', flexWrap: 'row', justifyContent: 'space-between', width: '100%' }}>
Orlando Piñero's avatar
Orlando Piñero committed
                            <Nav className="mr-auto">
Orlando Piñero's avatar
Orlando Piñero committed
                                <LinkContainer to="/" id="OpenStartPageButton">
                                    <Nav.Link>Home</Nav.Link>
                                </LinkContainer>
Orlando Piñero's avatar
Orlando Piñero committed
                                {OpenManagementPageButtons}
Orlando Piñero's avatar
Orlando Piñero committed
                                <NavDropdown title="Dropdown" id="basic-nav-dropdown">
                                    <NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
                                    <NavDropdown.Item href="#action/3.2">
                                        Another action
                                    </NavDropdown.Item>
                                    <NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
                                    <NavDropdown.Divider />
                                    <NavDropdown.Item href="#action/3.4">
                                        Separated link
                                    </NavDropdown.Item>
                                </NavDropdown>
                            </Nav>
                            <UserSessionWidget />
                        </Navbar.Collapse>
                    </Container>
Orlando Piñero's avatar
Orlando Piñero committed
                </Navbar>
            </div>
        )
    }
}

Orlando Piñero's avatar
Orlando Piñero committed
const mapDispatchToProps = dispatch => bindActionCreators({
    authenticateUserAction: authenticationActions.authenticateUser,
    showAllUsers: userManagementActions.displayUsers,
    showAllDegreeCourses: degreeCourseManagementActions.displayDegreeCourses
Orlando Piñero's avatar
Orlando Piñero committed
}, dispatch)

const ConnectedTopMenu = connect(mapStateToProps, mapDispatchToProps)(TopMenu);
export default ConnectedTopMenu;