// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var Utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); var TeamStore = require('../stores/team_store.jsx'); var Constants = require('../utils/constants.jsx'); import {config} from '../utils/config.js'; function getStateFromStores() { return {teams: UserStore.getTeams(), currentTeam: TeamStore.getCurrent()}; } export default class NavbarDropdown extends React.Component { constructor(props) { super(props); this.blockToggle = false; this.handleLogoutClick = this.handleLogoutClick.bind(this); this.onListenerChange = this.onListenerChange.bind(this); this.state = getStateFromStores(); } handleLogoutClick(e) { e.preventDefault(); client.logout(); } componentDidMount() { UserStore.addTeamsChangeListener(this.onListenerChange); TeamStore.addChangeListener(this.onListenerChange); $(React.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', function resetDropdown() { this.blockToggle = true; setTimeout(function blockTimeout() { this.blockToggle = false; }.bind(this), 100); }.bind(this)); } componentWillUnmount() { UserStore.removeTeamsChangeListener(this.onListenerChange); TeamStore.removeChangeListener(this.onListenerChange); $(React.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); } onListenerChange() { var newState = getStateFromStores(); if (!Utils.areStatesEqual(newState, this.state)) { this.setState(newState); } } render() { var teamLink = ''; var inviteLink = ''; var manageLink = ''; var currentUser = UserStore.getCurrentUser(); var isAdmin = false; var teamSettings = null; if (currentUser != null) { isAdmin = currentUser.roles.indexOf('admin') > -1; inviteLink = (
  • Invite New Member
  • ); if (this.props.teamType === 'O') { teamLink = (
  • Manage Team
  • ); teamSettings = (
  • Team Settings
  • ); } var teams = []; teams.push(
  • ); if (this.state.teams.length > 1 && this.state.currentTeam) { var curTeamName = this.state.currentTeam.name; this.state.teams.forEach(function listTeams(teamName) { if (teamName !== curTeamName) { teams.push(
  • Switch to {teamName}
  • ); } }); } teams.push(
  • Create a New Team
  • ); return ( ); } } NavbarDropdown.defaultProps = { teamType: '' }; NavbarDropdown.propTypes = { teamType: React.PropTypes.string };