// 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 AddUsersToTeam from 'components/add_users_to_team'; import {Constants, WebrtcActionTypes} from 'utils/constants.jsx'; import {Dropdown} from 'react-bootstrap'; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router/es6'; import PropTypes from 'prop-types'; import React from 'react'; export default class SidebarHeaderDropdown extends React.Component { static propTypes = { teamType: PropTypes.string, teamDisplayName: PropTypes.string, teamName: PropTypes.string, currentUser: 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.showAccountSettingsModal = this.showAccountSettingsModal.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.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, showAddUsersToTeamModal: false }; } handleClick(e) { if (WebrtcStore.isBusy()) { WebrtcStore.emitChanged({action: WebrtcActionTypes.IN_PROGRESS}); e.preventDefault(); } } toggleDropdown(val) { if (typeof (val) === 'boolean') { this.setState({showDropdown: val}); return; } if (val && val.preventDefault) { val.preventDefault(); } this.setState({showDropdown: !this.state.showDropdown}); } handleAboutModal(e) { e.preventDefault(); this.setState({ showAboutModal: true, showDropdown: false }); } aboutModalDismissed() { this.setState({showAboutModal: false}); } showAccountSettingsModal(e) { e.preventDefault(); this.setState({showDropdown: false}); GlobalActions.showAccountSettingsModal(); } 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); } onTeamChange() { this.setState({ teamMembers: TeamStore.getMyTeamMembers(), teamListings: TeamStore.getTeamListings(), showDropdown: false }); } componentWillUnmount() { $(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); TeamStore.removeChangeListener(this.onTeamChange); } renderCustomEmojiLink() { if (window.mm_config.EnableCustomEmoji !== 'true' || !Utils.canCreateCustomEmoji(this.props.currentUser)) { return null; } return (