blob: e6179a2fd8c3b348d67a3a223a7d82c8e0111317 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
// 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 ErrorBar from 'components/error_bar.jsx';
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 React from 'react';
import logoImage from 'images/logo.png';
export default class SelectTeam extends React.Component {
static propTypes = {
actions: React.PropTypes.shape({
getTeams: React.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(
<SelectTeamItem
key={'team_' + openTeam.name}
team={openTeam}
url={`/signup_user_complete/?id=${openTeam.invite_id}`}
onTeamClick={this.handleTeamClick}
loading={this.state.loadingTeamId === openTeam.id}
/>
);
}
}
if (openTeamContents.length === 0 && (global.window.mm_config.EnableTeamCreation === 'true' || isSystemAdmin)) {
openTeamContents = (
<div className='signup-team-dir-err'>
<div>
<FormattedMessage
id='signup_team.no_open_teams_canCreate'
defaultMessage='No teams are available to join. Please create a new team or ask your administrator for an invite.'
/>
</div>
</div>
);
} else if (openTeamContents.length === 0) {
openTeamContents = (
<div className='signup-team-dir-err'>
<div>
<FormattedMessage
id='signup_team.no_open_teams'
defaultMessage='No teams are available to join. Please ask your administrator for an invite.'
/>
</div>
</div>
);
}
if (Array.isArray(openTeamContents)) {
openTeamContents = openTeamContents.sort(this.teamContentsCompare);
}
let openContent = (
<div className='signup__content'>
<h4>
<FormattedMessage
id='signup_team.join_open'
defaultMessage='Teams you can join: '
/>
</h4>
<div className='signup-team-all'>
{openTeamContents}
</div>
</div>
);
if (!this.state.loaded) {
openContent = <LoadingScreen/>;
}
let teamHelp = null;
if (isSystemAdmin && (global.window.mm_config.EnableTeamCreation === 'false')) {
teamHelp = (
<FormattedMessage
id='login.createTeamAdminOnly'
defaultMessage='This option is only available for System Administrators, and does not show up for other users.'
/>
);
}
let teamSignUp;
if (isSystemAdmin || global.window.mm_config.EnableTeamCreation === 'true') {
teamSignUp = (
<div className='margin--extra'>
<Link
to='/create_team'
className='signup-team-login'
>
<FormattedMessage
id='login.createTeam'
defaultMessage='Create a new team'
/>
</Link>
<div>
{teamHelp}
</div>
</div>
);
}
let adminConsoleLink;
if (isSystemAdmin && !UserAgent.isMobileApp()) {
adminConsoleLink = (
<div className='margin--extra hidden-xs'>
<Link
to='/admin_console'
className='signup-team-login'
>
<FormattedMessage
id='signup_team_system_console'
defaultMessage='Go to System Console'
/>
</Link>
</div>
);
}
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 = (
<FormattedMessage
id='web.root.signup_info'
defaultMessage='All team communication in one place, searchable and accessible anywhere'
/>
);
}
let headerButton;
if (this.state.teamMembers.length) {
headerButton = (
<Link to='/'>
<span className='fa fa-chevron-left'/>
<FormattedMessage id='web.header.back'/>
</Link>
);
} else {
headerButton = (
<a
href='#'
onClick={() => GlobalActions.emitUserLoggedOutEvent()}
>
<span className='fa fa-chevron-left'/>
<FormattedMessage id='web.header.logout'/>
</a>
);
}
return (
<div>
<ErrorBar/>
<div className='signup-header'>
{headerButton}
</div>
<div className='col-sm-12'>
<div className={'signup-team__container'}>
<img
className='signup-team-logo'
src={logoImage}
/>
<h1>{global.window.mm_config.SiteName}</h1>
<h4 className='color--light'>
{description}
</h4>
{openContent}
{teamSignUp}
{adminConsoleLink}
</div>
</div>
</div>
);
}
}
|