// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; import AnnouncementBar from 'components/announcement_bar'; import LoadingScreen from 'components/loading_screen.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import SelectTeamItem from './components/select_team_item.jsx'; import {Link} from 'react-router/es6'; import {FormattedMessage} from 'react-intl'; import PropTypes from 'prop-types'; import React from 'react'; import logoImage from 'images/logo.png'; export default class SelectTeam extends React.Component { static propTypes = { actions: PropTypes.shape({ getTeams: PropTypes.func.isRequired }).isRequired } constructor(props) { super(props); this.onTeamChange = this.onTeamChange.bind(this); this.handleTeamClick = this.handleTeamClick.bind(this); this.teamContentsCompare = this.teamContentsCompare.bind(this); const state = this.getStateFromStores(false); state.loadingTeamId = ''; this.state = state; } componentDidMount() { TeamStore.addChangeListener(this.onTeamChange); this.props.actions.getTeams(0, 200); } componentWillUnmount() { TeamStore.removeChangeListener(this.onTeamChange); } onTeamChange() { this.setState(this.getStateFromStores(true)); } getStateFromStores(loaded) { return { teams: TeamStore.getAll(), teamMembers: TeamStore.getMyTeamMembers(), teamListings: TeamStore.getTeamListings(), loaded }; } handleTeamClick(team) { this.setState({loadingTeamId: team.id}); } teamContentsCompare(teamItemA, teamItemB) { return teamItemA.props.team.display_name.localeCompare(teamItemB.props.team.display_name); } render() { let openTeamContents = []; const isAlreadyMember = new Map(); const isSystemAdmin = Utils.isSystemAdmin(UserStore.getCurrentUser().roles); for (const teamMember of this.state.teamMembers) { const teamId = teamMember.team_id; isAlreadyMember[teamId] = true; } for (const id in this.state.teamListings) { if (this.state.teamListings.hasOwnProperty(id) && !isAlreadyMember[id]) { const openTeam = this.state.teamListings[id]; openTeamContents.push( ); } } if (openTeamContents.length === 0 && (global.window.mm_config.EnableTeamCreation === 'true' || isSystemAdmin)) { openTeamContents = (
); } else if (openTeamContents.length === 0) { openTeamContents = (
); } if (Array.isArray(openTeamContents)) { openTeamContents = openTeamContents.sort(this.teamContentsCompare); } let openContent = (

{openTeamContents}
); if (!this.state.loaded) { openContent = ; } let teamHelp = null; if (isSystemAdmin && (global.window.mm_config.EnableTeamCreation === 'false')) { teamHelp = ( ); } let teamSignUp; if (isSystemAdmin || global.window.mm_config.EnableTeamCreation === 'true') { teamSignUp = (
{teamHelp}
); } let adminConsoleLink; if (isSystemAdmin && !UserAgent.isMobileApp()) { adminConsoleLink = (
); } let description = null; if (global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.CustomBrand === 'true' && global.window.mm_config.EnableCustomBrand === 'true') { description = global.window.mm_config.CustomDescriptionText; } else { description = ( ); } let headerButton; if (this.state.teamMembers.length) { headerButton = ( ); } else { headerButton = ( GlobalActions.emitUserLoggedOutEvent()} > ); } return (
{headerButton}

{global.window.mm_config.SiteName}

{description}

{openContent} {teamSignUp} {adminConsoleLink}
); } }