// 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 UserAgent from 'utils/user_agent.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 SelectTeamItem from './components/select_team_item.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);
this.handleTeamClick = this.handleTeamClick.bind(this);
const state = this.getStateFromStores(false);
state.loadingTeamId = '';
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.getMyTeamMembers(),
teamListings: TeamStore.getTeamListings(),
loaded
};
}
handleTeamClick(team) {
this.setState({loadingTeamId: team.id});
}
render() {
let content = null;
let teamContents = [];
const isAlreadyMember = new Map();
const isSystemAdmin = Utils.isSystemAdmin(UserStore.getCurrentUser().roles);
let teamMembersCount = 0;
for (const teamMember of this.state.teamMembers) {
const teamId = teamMember.team_id;
const team = this.state.teams[teamId];
isAlreadyMember[teamId] = true;
teamMembersCount++;
teamContents.push(