// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as Utils from 'utils/utils.jsx'; import * as GlobalActions from 'action_creators/global_actions.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import AboutBuildModal from './about_build_modal.jsx'; import TeamMembersModal from './team_members_modal.jsx'; import ToggleModalButton from './toggle_modal_button.jsx'; import UserSettingsModal from './user_settings/user_settings_modal.jsx'; import Constants from 'utils/constants.jsx'; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router'; import React from 'react'; export default class NavbarDropdown extends React.Component { constructor(props) { super(props); this.blockToggle = false; this.handleAboutModal = this.handleAboutModal.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); this.onTeamChange = this.onTeamChange.bind(this); this.openAccountSettings = this.openAccountSettings.bind(this); this.state = { showUserSettingsModal: false, showAboutModal: false, teams: TeamStore.getAll(), teamMembers: TeamStore.getTeamMembers() }; } handleAboutModal() { this.setState({showAboutModal: true}); } aboutModalDismissed() { this.setState({showAboutModal: false}); } componentDidMount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => { $('.sidebar--left .dropdown-menu').scrollTop(0); this.blockToggle = true; setTimeout(() => { this.blockToggle = false; }, 100); }); TeamStore.addChangeListener(this.onTeamChange); document.addEventListener('keydown', this.openAccountSettings); } onTeamChange() { this.setState({ teams: TeamStore.getAll(), teamMembers: TeamStore.getTeamMembers() }); } componentWillUnmount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); TeamStore.removeChangeListener(this.onTeamChange); document.removeEventListener('keydown', this.openAccountSettings); } openAccountSettings(e) { if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.keyCode === Constants.KeyCodes.A) { e.preventDefault(); this.setState({showUserSettingsModal: true}); } } render() { var teamLink = ''; var inviteLink = ''; var manageLink = ''; var sysAdminLink = ''; var adminDivider = ''; var currentUser = this.props.currentUser; var isAdmin = false; var isSystemAdmin = false; var teamSettings = null; let integrationsLink = null; if (currentUser != null) { isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); inviteLink = (