scinote-web/app/javascript/packs/shared/navigation/index.jsx

167 lines
4.9 KiB
React
Raw Normal View History

2017-08-02 23:27:05 +08:00
import React, { Component } from "react";
2017-08-03 22:03:15 +08:00
import PropTypes from "prop-types";
2017-08-02 23:27:05 +08:00
import { connect } from "react-redux";
import { Navbar, Nav, NavItem } from "react-bootstrap";
import { FormattedMessage } from "react-intl";
2017-08-02 23:27:05 +08:00
import styled from "styled-components";
2017-08-09 15:08:13 +08:00
import {
MAIN_COLOR_BLUE,
WHITE_COLOR,
BORDER_GRAY_COLOR
2017-08-09 21:21:02 +08:00
} from "../../app/constants/colors";
2017-08-22 19:20:06 +08:00
import { getActivities, destroyActivities } from "../actions/ActivitiesActions";
2017-08-02 23:27:05 +08:00
import TeamSwitch from "./components/TeamSwitch";
import GlobalActivitiesModal from "./components/GlobalActivitiesModal";
2017-08-07 15:31:24 +08:00
import SearchDropdown from "./components/SearchDropdown";
2017-08-09 15:08:13 +08:00
import NotificationsDropdown from "./components/NotificationsDropdown";
import InfoDropdown from "./components/InfoDropdown";
import UserAccountDropdown from "./components/UserAccountDropdown";
const StyledNavbar = styled(Navbar)`
background-color: ${WHITE_COLOR};
border-color: ${BORDER_GRAY_COLOR};
`;
2017-08-02 23:27:05 +08:00
const StyledBrand = styled.a`
background-color: ${MAIN_COLOR_BLUE};
&:hover,
&:active,
&:focus {
background-color: ${MAIN_COLOR_BLUE} !important;
}
& > img {
2017-08-09 15:08:13 +08:00
margin-top: -4px;
max-width: 132px;
max-height: 26px;
2017-08-02 23:27:05 +08:00
}
`;
class Navigation extends Component {
constructor(props) {
super(props);
2017-08-02 23:27:05 +08:00
this.state = {
showActivitesModal: false,
page: "",
current_team: { id: 0 }
2017-08-02 23:27:05 +08:00
};
this.selectItemCallback = this.selectItemCallback.bind(this);
this.closeModalCallback = this.closeModalCallback.bind(this);
}
2017-08-02 23:27:05 +08:00
selectItemCallback(key, ev) {
2017-08-22 19:20:06 +08:00
switch (key) {
case 1:
window.location = "/";
break;
case 2:
window.location = "/protocols";
break;
case 3:
window.location = `/teams/${this.props.current_team.id}/repositories`;
break;
case 4:
ev.preventDefault();
this.setState({ showActivitesModal: !this.state.showActivitesModal });
// Call action creator to fetch activities from the server
this.props.fetchActivities();
break;
default:
2017-08-02 23:27:05 +08:00
}
}
closeModalCallback() {
this.setState({ showActivitesModal: false });
2017-08-22 19:20:06 +08:00
this.props.destroyActivities();
2017-08-02 23:27:05 +08:00
}
2017-08-02 23:27:05 +08:00
render() {
return (
<div>
2017-08-09 15:08:13 +08:00
<StyledNavbar onSelect={this.selectItemCallback}>
2017-08-02 23:27:05 +08:00
<Navbar.Header>
<Navbar.Brand>
<StyledBrand href="/" title="sciNote">
<img src="/images/logo.png" alt="Logo" />
</StyledBrand>
</Navbar.Brand>
</Navbar.Header>
<Nav>
2017-08-22 19:20:06 +08:00
<NavItem eventKey={1}>
<span className="glyphicon glyphicon-home" title="Home" />&nbsp;
<span className="visible-xs-inline visible-sm-inline">
<FormattedMessage id="navbar.home_label" />
</span>
2017-08-02 23:27:05 +08:00
</NavItem>
2017-08-22 19:20:06 +08:00
<NavItem eventKey={2}>
2017-08-02 23:27:05 +08:00
<span
className="glyphicon glyphicon-list-alt"
title="Protocol repositories"
/>&nbsp;
<span className="visible-xs-inline visible-sm-inline">
<FormattedMessage id="navbar.protocols_label" />
</span>
2017-08-02 23:27:05 +08:00
</NavItem>
2017-08-22 19:20:06 +08:00
<NavItem eventKey={3}>
2017-08-02 23:27:05 +08:00
<i
className="fa fa-cubes"
aria-hidden="true"
title="Repositories"
/>&nbsp;
<span className="visible-xs-inline visible-sm-inline">
<FormattedMessage id="navbar.repositories_label" />
</span>
2017-08-02 23:27:05 +08:00
</NavItem>
<NavItem eventKey={4}>
<span
className="glyphicon glyphicon-equalizer"
title="Activities"
/>&nbsp;
<span className="visible-xs-inline visible-sm-inline">
<FormattedMessage id="navbar.activities_label" />
</span>
2017-08-02 23:27:05 +08:00
</NavItem>
</Nav>
<Nav pullRight>
<TeamSwitch eventKey={5} />
2017-08-07 15:31:24 +08:00
<SearchDropdown />
2017-08-08 21:44:28 +08:00
<NotificationsDropdown />
2017-08-09 15:08:13 +08:00
<InfoDropdown />
<UserAccountDropdown />
2017-08-02 23:27:05 +08:00
</Nav>
2017-08-09 15:08:13 +08:00
</StyledNavbar>
2017-08-02 23:27:05 +08:00
<GlobalActivitiesModal
showModal={this.state.showActivitesModal}
onCloseModal={this.closeModalCallback}
/>
</div>
);
}
}
2017-08-03 22:03:15 +08:00
Navigation.propTypes = {
fetchActivities: PropTypes.func.isRequired,
2017-08-22 19:20:06 +08:00
destroyActivities: PropTypes.func.isRequired,
current_team: PropTypes.shape({
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
current_team: PropTypes.bool.isRequired
}).isRequired
2017-08-07 15:31:24 +08:00
};
2017-08-03 22:03:15 +08:00
// Map the states from store to component props
const mapStateToProps = ({ current_team }) => ({ current_team });
// Map the fetch activity action to component props
2017-08-02 23:27:05 +08:00
const mapDispatchToProps = dispatch => ({
fetchActivities() {
dispatch(getActivities());
2017-08-22 19:20:06 +08:00
},
destroyActivities() {
dispatch(destroyActivities());
2017-08-02 23:27:05 +08:00
}
});
export default connect(mapStateToProps, mapDispatchToProps)(Navigation);