// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import AppDispatcher from 'dispatcher/app_dispatcher.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 AboutBuildModal from './about_build_modal.jsx'; import AddUsersToTeam from './add_users_to_team.jsx'; import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import SearchStore from 'stores/search_store.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import WebrtcStore from 'stores/webrtc_store.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {getFlaggedPosts} from 'actions/post_actions.jsx'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; import {Constants, WebrtcActionTypes} from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; const Preferences = Constants.Preferences; const TutorialSteps = Constants.TutorialSteps; import {FormattedMessage} from 'react-intl'; import {Link} from 'react-router/es6'; import {createMenuTip} from 'components/tutorial/tutorial_tip.jsx'; import React from 'react'; export default class SidebarRightMenu extends React.Component { constructor(props) { super(props); this.onChange = this.onChange.bind(this); this.handleClick = this.handleClick.bind(this); this.handleAboutModal = this.handleAboutModal.bind(this); this.showAddUsersToTeamModal = this.showAddUsersToTeamModal.bind(this); this.hideAddUsersToTeamModal = this.hideAddUsersToTeamModal.bind(this); this.searchMentions = this.searchMentions.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); this.getFlagged = this.getFlagged.bind(this); const state = this.getStateFromStores(); state.showUserSettingsModal = false; state.showAboutModal = false; state.showAddUsersToTeamModal = false; this.state = state; } handleClick(e) { if (WebrtcStore.isBusy()) { WebrtcStore.emitChanged({action: WebrtcActionTypes.IN_PROGRESS}); e.preventDefault(); } } handleAboutModal() { this.setState({showAboutModal: true}); } aboutModalDismissed() { this.setState({showAboutModal: false}); } showAddUsersToTeamModal(e) { e.preventDefault(); this.setState({ showAddUsersToTeamModal: true, showDropdown: false }); } hideAddUsersToTeamModal() { this.setState({ showAddUsersToTeamModal: false }); } getFlagged(e) { e.preventDefault(); getFlaggedPosts(); this.hideSidebars(); } componentDidMount() { TeamStore.addChangeListener(this.onChange); PreferenceStore.addChangeListener(this.onChange); } componentWillUnmount() { TeamStore.removeChangeListener(this.onChange); PreferenceStore.removeChangeListener(this.onChange); } getStateFromStores() { const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999); return { currentUser: UserStore.getCurrentUser(), teamMembers: TeamStore.getMyTeamMembers(), teamListings: TeamStore.getTeamListings(), showTutorialTip: tutorialStep === TutorialSteps.MENU_POPOVER && Utils.isMobile() }; } onChange() { this.setState(this.getStateFromStores()); } searchMentions(e) { e.preventDefault(); const user = this.state.currentUser; if (SearchStore.isMentionSearch) { GlobalActions.toggleSideBarAction(false); } else { GlobalActions.emitSearchMentionsEvent(user); this.hideSidebars(); } } closeLeftSidebar() { if (Utils.isMobile()) { setTimeout(() => { document.querySelector('.app__body .inner-wrap').classList.remove('move--right'); document.querySelector('.app__body .sidebar--left').classList.remove('move--right'); }); } } openRightSidebar() { if (Utils.isMobile()) { setTimeout(() => { document.querySelector('.app__body .inner-wrap').classList.add('move--left-small'); document.querySelector('.app__body .sidebar--menu').classList.add('move--left'); }); } } hideSidebars() { if (Utils.isMobile()) { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH, results: null }); AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_POST_SELECTED, postId: null }); document.querySelector('.app__body .inner-wrap').classList.remove('move--right', 'move--left', 'move--left-small'); document.querySelector('.app__body .sidebar--left').classList.remove('move--right'); document.querySelector('.app__body .sidebar--right').classList.remove('move--left'); document.querySelector('.app__body .sidebar--menu').classList.remove('move--left'); } } render() { const currentUser = UserStore.getCurrentUser(); let teamLink; let inviteLink; let addUserToTeamLink; let teamSettingsLink; let manageLink; let consoleLink; let joinAnotherTeamLink; let isAdmin = false; let isSystemAdmin = false; if (currentUser != null) { isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); inviteLink = (