// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. var utils = require('../utils/utils.jsx'); var client = require('../utils/client.jsx'); var UserStore = require('../stores/user_store.jsx'); function getStateFromStores() { return { teams: UserStore.getTeams() }; } var NavbarDropdown = React.createClass({ handleLogoutClick: function(e) { e.preventDefault(); client.logout(); }, componentDidMount: function() { UserStore.addTeamsChangeListener(this._onChange); }, componentWillUnmount: function() { UserStore.removeTeamsChangeListener(this._onChange); }, _onChange: function() { if (this.isMounted()) { var newState = getStateFromStores(); if (!utils.areStatesEqual(newState, this.state)) { this.setState(newState); } } }, getInitialState: function() { return getStateFromStores(); }, render: function() { var team_link = ""; var invite_link = ""; var manage_link = ""; var rename_link = ""; var currentUser = UserStore.getCurrentUser(); var isAdmin = false; if (currentUser != null) { isAdmin = currentUser.roles.indexOf("admin") > -1; invite_link = (
  • Invite New Member
  • ); if (this.props.teamType == "O") { team_link = (
  • Get Team Invite Link
  • ); } } if (isAdmin) { manage_link = (
  • Manage Team
  • ); rename_link = (
  • Rename
  • ); } var teams = []; if (this.state.teams.length > 1) { for (var i = 0; i < this.state.teams.length; i++) { var domain = this.state.teams[i]; if (domain == utils.getSubDomain()) continue; if (teams.length == 0) teams.push(
  • ); teams.push(
  • Switch to { domain }
  • ); } } return ( ); } }); module.exports = React.createClass({ displayName: 'SidebarHeader', getDefaultProps: function() { return { teamName: config.SiteName }; }, render: function() { var me = UserStore.getCurrentUser(); if (!me) { return null; } return (
    {'@' + me.username}
    {this.props.teamName}
    ); } });