// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import TeamStore from 'stores/team_store.jsx'; import Constants from 'utils/constants.jsx'; import AboutBuildModal from 'components/about_build_modal.jsx'; import {sortTeamsByDisplayName} from 'utils/team_utils.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router/es6'; import React from 'react'; import * as Utils from 'utils/utils.jsx'; export default class AdminNavbarDropdown extends React.Component { constructor(props) { super(props); this.blockToggle = false; this.onTeamChange = this.onTeamChange.bind(this); this.handleAboutModal = this.handleAboutModal.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); this.state = { teams: TeamStore.getAll(), teamMembers: TeamStore.getMyTeamMembers(), showAboutModal: false }; } componentDidMount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => { this.blockToggle = true; setTimeout(() => { this.blockToggle = false; }, 100); }); TeamStore.addChangeListener(this.onTeamChange); } componentWillUnmount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); TeamStore.removeChangeListener(this.onTeamChange); } handleAboutModal(e) { e.preventDefault(); this.setState({showAboutModal: true}); } aboutModalDismissed() { this.setState({showAboutModal: false}); } onTeamChange() { this.setState({ teams: TeamStore.getAll(), teamMembers: TeamStore.getMyTeamMembers() }); } render() { var teamsArray = []; // Array of team objects var teams = []; // Array of team components let switchTeams; if (this.state.teamMembers && this.state.teamMembers.length > 0) { for (const index in this.state.teamMembers) { if (this.state.teamMembers.hasOwnProperty(index)) { const teamMember = this.state.teamMembers[index]; const team = this.state.teams[teamMember.team_id]; teamsArray.push(team); } } // Sort teams alphabetically with display_name teamsArray = teamsArray.sort(sortTeamsByDisplayName); for (const team of teamsArray) { teams.push(