diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-03-14 00:56:37 -0400 |
commit | 975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165 (patch) | |
tree | a0852f9faf6de9962b5478ed3f1bbaccd71062c0 /web/react/components/navbar_dropdown.jsx | |
parent | 160e1a8bea6d8280ef3b41a4a9f80674b75f3eb0 (diff) | |
parent | d7cdcf082fab6c0cb7c2fe4bed821bd1a8000e69 (diff) | |
download | chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.gz chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.tar.bz2 chat-975159b52ac6bf0ee6b2d5b73d2391b2e0c6e165.zip |
Merge pull request #2331 from mattermost/plt-1680
PLT-1680 Converting client to react-router. Stage 1
Diffstat (limited to 'web/react/components/navbar_dropdown.jsx')
-rw-r--r-- | web/react/components/navbar_dropdown.jsx | 88 |
1 files changed, 14 insertions, 74 deletions
diff --git a/web/react/components/navbar_dropdown.jsx b/web/react/components/navbar_dropdown.jsx index 0ddd6ff4f..12227fd13 100644 --- a/web/react/components/navbar_dropdown.jsx +++ b/web/react/components/navbar_dropdown.jsx @@ -2,10 +2,7 @@ // See License.txt for license information. import * as Utils from '../utils/utils.jsx'; -import * as client from '../utils/client.jsx'; -import UserStore from '../stores/user_store.jsx'; -import TeamStore from '../stores/team_store.jsx'; -import * as EventHelpers from '../dispatcher/event_helpers.jsx'; +import * as GlobalActions from '../action_creators/global_actions.jsx'; import AboutBuildModal from './about_build_modal.jsx'; import TeamMembersModal from './team_members_modal.jsx'; @@ -15,38 +12,20 @@ import UserSettingsModal from './user_settings/user_settings_modal.jsx'; import Constants from '../utils/constants.jsx'; import {FormattedMessage} from 'mm-intl'; - -function getStateFromStores() { - const teams = []; - const teamsObject = UserStore.getTeams(); - for (const teamId in teamsObject) { - if (teamsObject.hasOwnProperty(teamId)) { - teams.push(teamsObject[teamId]); - } - } - - teams.sort(Utils.sortByDisplayName); - return {teams}; -} +import {Link} from 'react-router'; export default class NavbarDropdown extends React.Component { constructor(props) { super(props); this.blockToggle = false; - this.handleLogoutClick = this.handleLogoutClick.bind(this); this.handleAboutModal = this.handleAboutModal.bind(this); - this.onListenerChange = this.onListenerChange.bind(this); this.aboutModalDismissed = this.aboutModalDismissed.bind(this); - const state = getStateFromStores(); - state.showUserSettingsModal = false; - state.showAboutModal = false; - this.state = state; - } - handleLogoutClick(e) { - e.preventDefault(); - client.logout(); + this.state = { + showUserSettingsModal: false, + showAboutModal: false + }; } handleAboutModal() { this.setState({showAboutModal: true}); @@ -55,9 +34,6 @@ export default class NavbarDropdown extends React.Component { this.setState({showAboutModal: false}); } componentDidMount() { - UserStore.addTeamsChangeListener(this.onListenerChange); - TeamStore.addChangeListener(this.onListenerChange); - $(ReactDOM.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => { $('.sidebar--left .dropdown-menu').scrollTop(0); this.blockToggle = true; @@ -67,24 +43,15 @@ export default class NavbarDropdown extends React.Component { }); } componentWillUnmount() { - UserStore.removeTeamsChangeListener(this.onListenerChange); - TeamStore.removeChangeListener(this.onListenerChange); - $(ReactDOM.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown'); } - onListenerChange() { - var newState = getStateFromStores(); - if (!Utils.areObjectsEqual(newState, this.state)) { - this.setState(newState); - } - } render() { var teamLink = ''; var inviteLink = ''; var manageLink = ''; var sysAdminLink = ''; var adminDivider = ''; - var currentUser = UserStore.getCurrentUser(); + var currentUser = this.props.currentUser; var isAdmin = false; var isSystemAdmin = false; var teamSettings = null; @@ -97,7 +64,7 @@ export default class NavbarDropdown extends React.Component { <li> <a href='#' - onClick={EventHelpers.showInviteMemberModal} + onClick={GlobalActions.showInviteMemberModal} > <FormattedMessage id='navbar_dropdown.inviteMember' @@ -112,7 +79,7 @@ export default class NavbarDropdown extends React.Component { <li> <a href='#' - onClick={EventHelpers.showGetTeamInviteLinkModal} + onClick={GlobalActions.showGetTeamInviteLinkModal} > <FormattedMessage id='navbar_dropdown.teamLink' @@ -158,7 +125,7 @@ export default class NavbarDropdown extends React.Component { sysAdminLink = ( <li> <a - href={'/admin_console?' + Utils.getSessionIndex()} + href={'/admin_console'} > <FormattedMessage id='navbar_dropdown.console' @@ -171,31 +138,6 @@ export default class NavbarDropdown extends React.Component { var teams = []; - if (this.state.teams.length > 1) { - teams.push( - <li - className='divider' - key='div' - > - </li> - ); - - this.state.teams.forEach((team) => { - if (team.name !== this.props.teamName) { - teams.push( - <li key={team.name}><a href={Utils.getWindowLocationOrigin() + '/' + team.name}> - <FormattedMessage - id='navbar_dropdown.switchTeam' - defaultMessage='Switch to {team}' - values={{ - team: team.display_name - }} - /> - </a></li>); - } - }); - } - if (global.window.mm_config.EnableTeamCreation === 'true') { teams.push( <li key='newTeam_li'> @@ -283,15 +225,12 @@ export default class NavbarDropdown extends React.Component { {inviteLink} {teamLink} <li> - <a - href='#' - onClick={this.handleLogoutClick} - > + <Link to={'/' + this.props.teamName + '/logout'}> <FormattedMessage id='navbar_dropdown.logout' defaultMessage='Logout' /> - </a> + </Link> </li> {adminDivider} {teamSettings} @@ -333,5 +272,6 @@ NavbarDropdown.defaultProps = { NavbarDropdown.propTypes = { teamType: React.PropTypes.string, teamDisplayName: React.PropTypes.string, - teamName: React.PropTypes.string + teamName: React.PropTypes.string, + currentUser: React.PropTypes.object }; |