// Copyright (c) 2015 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 Utils from 'utils/utils.jsx'; import ErrorBar from 'components/error_bar.jsx'; import LoadingScreen from 'components/loading_screen.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {Link} from 'react-router/es6'; import {FormattedMessage} from 'react-intl'; import React from 'react'; import logoImage from 'images/logo.png'; export default class SelectTeam extends React.Component { constructor(props) { super(props); this.onTeamChange = this.onTeamChange.bind(this); const state = this.getStateFromStores(false); this.state = state; } componentDidMount() { TeamStore.addChangeListener(this.onTeamChange); AsyncClient.getAllTeamListings(); } componentWillUnmount() { TeamStore.removeChangeListener(this.onTeamChange); } onTeamChange() { this.setState(this.getStateFromStores(true)); } getStateFromStores(loaded) { return { teams: TeamStore.getAll(), teamMembers: TeamStore.getTeamMembers(), teamListings: TeamStore.getTeamListings(), loaded }; } render() { let content = null; let teamContents = []; const isAlreadyMember = new Map(); const isSystemAdmin = Utils.isSystemAdmin(UserStore.getCurrentUser().roles); for (var index in this.state.teamMembers) { if (this.state.teamMembers.hasOwnProperty(index)) { var teamMember = this.state.teamMembers[index]; var team = this.state.teams[teamMember.team_id]; isAlreadyMember[teamMember.team_id] = true; teamContents.push(
{team.display_name}
); } } var openTeamContents = []; for (var id in this.state.teamListings) { if (this.state.teamListings.hasOwnProperty(id) && !isAlreadyMember[id]) { var openTeam = this.state.teamListings[id]; openTeamContents.push(
{openTeam.display_name}
); } } if (this.state.teamMembers.length === 0 && teamContents.length === 0 && openTeamContents.length === 0 && (global.window.mm_config.EnableTeamCreation === 'true' || isSystemAdmin)) { teamContents = (
); } else if (this.state.teamMembers.length === 0 && teamContents.length === 0 && openTeamContents.length === 0) { teamContents = (
); } else if (teamContents.length === 0 && openTeamContents.length > 0) { teamContents = null; } if (teamContents) { content = (

{teamContents}
); } var openContent; if (openTeamContents.length > 0) { 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' && !Utils.isMobileApp())) { teamSignUp = (
{teamHelp}
); } let adminConsoleLink; if (isSystemAdmin) { adminConsoleLink = (
); } return (

{global.window.mm_config.SiteName}

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