// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; import WebrtcStore from 'stores/webrtc_store.jsx'; import AboutBuildModal from './about_build_modal.jsx'; import SidebarHeaderDropdownButton from './sidebar_header_dropdown_button.jsx'; import TeamMembersModal from './team_members_modal.jsx'; import UserSettingsModal from './user_settings/user_settings_modal.jsx'; import AddUsersToTeam from './add_users_to_team.jsx'; import {Constants, WebrtcActionTypes} from 'utils/constants.jsx'; import {Dropdown} from 'react-bootstrap'; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router/es6'; import React from 'react'; export default class SidebarHeaderDropdown extends React.Component { static propTypes = { teamType: React.PropTypes.string, teamDisplayName: React.PropTypes.string, teamName: React.PropTypes.string, currentUser: React.PropTypes.object }; static defaultProps = { teamType: '' }; constructor(props) { super(props); this.toggleDropdown = this.toggleDropdown.bind(this); this.handleAboutModal = this.handleAboutModal.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); this.toggleAccountSettingsModal = this.toggleAccountSettingsModal.bind(this); this.showAddUsersToTeamModal = this.showAddUsersToTeamModal.bind(this); this.hideAddUsersToTeamModal = this.hideAddUsersToTeamModal.bind(this); this.showInviteMemberModal = this.showInviteMemberModal.bind(this); this.showGetTeamInviteLinkModal = this.showGetTeamInviteLinkModal.bind(this); this.showTeamMembersModal = this.showTeamMembersModal.bind(this); this.hideTeamMembersModal = this.hideTeamMembersModal.bind(this); this.onTeamChange = this.onTeamChange.bind(this); this.openAccountSettings = this.openAccountSettings.bind(this); this.renderCustomEmojiLink = this.renderCustomEmojiLink.bind(this); this.handleClick = this.handleClick.bind(this); this.state = { teamMembers: TeamStore.getMyTeamMembers(), teamListings: TeamStore.getTeamListings(), showAboutModal: false, showDropdown: false, showTeamMembersModal: false, showUserSettingsModal: false, showAddUsersToTeamModal: false }; } handleClick(e) { if (WebrtcStore.isBusy()) { WebrtcStore.emitChanged({action: WebrtcActionTypes.IN_PROGRESS}); e.preventDefault(); } } toggleDropdown(e) { if (e) { e.preventDefault(); } this.setState({showDropdown: !this.state.showDropdown}); } handleAboutModal(e) { e.preventDefault(); this.setState({ showAboutModal: true, showDropdown: false }); } aboutModalDismissed() { this.setState({showAboutModal: false}); } toggleAccountSettingsModal(e) { e.preventDefault(); this.setState({ showUserSettingsModal: !this.state.showUserSettingsModal, showDropdown: false }); } showAddUsersToTeamModal(e) { e.preventDefault(); this.setState({ showAddUsersToTeamModal: true, showDropdown: false }); } hideAddUsersToTeamModal() { this.setState({ showAddUsersToTeamModal: false }); } showInviteMemberModal(e) { e.preventDefault(); this.setState({showDropdown: false}); GlobalActions.showInviteMemberModal(); } showGetTeamInviteLinkModal(e) { e.preventDefault(); this.setState({showDropdown: false}); GlobalActions.showGetTeamInviteLinkModal(); } showTeamMembersModal(e) { e.preventDefault(); this.setState({ showTeamMembersModal: true }); } hideTeamMembersModal() { this.setState({ showTeamMembersModal: false }); } componentDidMount() { TeamStore.addChangeListener(this.onTeamChange); document.addEventListener('keydown', this.openAccountSettings); } onTeamChange() { this.setState({ teamMembers: TeamStore.getMyTeamMembers(), teamListings: TeamStore.getTeamListings() }); } componentWillUnmount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); TeamStore.removeChangeListener(this.onTeamChange); document.removeEventListener('keydown', this.openAccountSettings); } openAccountSettings(e) { if (Utils.cmdOrCtrlPressed(e) && e.shiftKey && e.keyCode === Constants.KeyCodes.A) { this.toggleAccountSettingsModal(e); } } renderCustomEmojiLink() { if (window.mm_config.EnableCustomEmoji !== 'true' || !Utils.canCreateCustomEmoji(this.props.currentUser)) { return null; } return (