// Copyright (c) 2015 Mattermost, 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 AboutBuildModal = require('./about_build_modal.jsx'); var Constants = require('../utils/constants.jsx'); function getStateFromStores() { const teams = []; const teamsObject = UserStore.getTeams(); for (const teamId in teamsObject) { if (teamsObject.hasOwnProperty(teamId)) { teams.push(teamsObject[teamId]); } } teams.sort(Utils.sortByDisplayName); return {teams}; } export default class NavbarDropdown extends React.Component { constructor(props) { super(props); this.blockToggle = false; this.handleLogoutClick = this.handleLogoutClick.bind(this); this.handleAboutModal = this.handleAboutModal.bind(this); this.onListenerChange = this.onListenerChange.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); this.state = getStateFromStores(); } handleLogoutClick(e) { e.preventDefault(); client.logout(); } handleAboutModal() { this.setState({showAboutModal: true}); } aboutModalDismissed() { this.setState({showAboutModal: false}); } componentDidMount() { UserStore.addTeamsChangeListener(this.onListenerChange); TeamStore.addChangeListener(this.onListenerChange); $(ReactDOM.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => { $('.sidebar--left .dropdown-menu').scrollTop(0); this.blockToggle = true; setTimeout(() => { this.blockToggle = false; }, 100); }); } componentWillUnmount() { UserStore.removeTeamsChangeListener(this.onListenerChange); TeamStore.removeChangeListener(this.onListenerChange); $(ReactDOM.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 sysAdminLink = ''; var adminDivider = ''; var currentUser = UserStore.getCurrentUser(); var isAdmin = false; var isSystemAdmin = false; var teamSettings = null; if (currentUser != null) { isAdmin = Utils.isAdmin(currentUser.roles); isSystemAdmin = Utils.isSystemAdmin(currentUser.roles); inviteLink = (