text: // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
  // See LICENSE.txt for license information.
  
  import {connect} from 'react-redux';
  import {bindActionCreators} from 'redux';
  import {withRouter} from 'react-router-dom';
  
  import {getTeams} from 'mattermost-redux/actions/teams';
  import {loadRolesIfNeeded} from 'mattermost-redux/actions/roles';
  import {getConfig} from 'mattermost-redux/selectors/entities/general';
  import {Permissions} from 'mattermost-redux/constants';
  import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles';
  import {getSortedJoinableTeams, getTeamMemberships} from 'mattermost-redux/selectors/entities/teams';
  import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
  
  import {addUserToTeamFromInvite} from 'actions/team_actions';
  
  import SelectTeam from './select_team.jsx';
  
  function mapStateToProps(state) {
      const config = getConfig(state);
      const currentUser = getCurrentUser(state);
      const myTeamMemberships = Object.values(getTeamMemberships(state));
  
      return {
          currentUserRoles: currentUser.roles || '',
          customDescriptionText: config.CustomDescriptionText,
          isMemberOfTeam: myTeamMemberships && myTeamMemberships.length > 0,
          joinableTeams: getSortedJoinableTeams(state, currentUser.locale),
          siteName: config.SiteName,
          canCreateTeams: haveISystemPermission(state, {permission: Permissions.CREATE_TEAM}),
          canManageSystem: haveISystemPermission(state, {permission: Permissions.MANAGE_SYSTEM}),
      };
  }
  
  function mapDispatchToProps(dispatch) {
      return {
          actions: bindActionCreators({
              getTeams,
              loadRolesIfNeeded,
              addUserToTeamFromInvite,
          }, dispatch),
      };
  }
  
  export default withRouter(connect(mapStateToProps, mapDispatchToProps)(SelectTeam));
  