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
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as Utils from '../utils/utils.jsx';
import * as Client from '../utils/client.jsx';
import BrowserStore from '../stores/browser_store.jsx';
import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl';
const holders = defineMessages({
storageError: {
id: 'team_signup_welcome.storageError',
defaultMessage: 'This service requires local storage to be enabled. Please enable it or exit private browsing.'
},
validEmailError: {
id: 'team_signup_welcome.validEmailError',
defaultMessage: 'Please enter a valid email address'
},
address: {
id: 'team_signup_welcome.address',
defaultMessage: 'Email Address'
}
});
class TeamSignupWelcomePage extends React.Component {
constructor(props) {
super(props);
this.submitNext = this.submitNext.bind(this);
this.handleDiffEmail = this.handleDiffEmail.bind(this);
this.handleDiffSubmit = this.handleDiffSubmit.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this);
this.state = {useDiff: false};
document.addEventListener('keyup', this.handleKeyPress, false);
}
submitNext(e) {
if (!BrowserStore.isLocalStorageSupported()) {
this.setState({storageError: this.props.intl.formatMessage(holders.storageError)});
return;
}
e.preventDefault();
this.props.state.wizard = 'team_display_name';
this.props.updateParent(this.props.state);
}
handleDiffEmail(e) {
e.preventDefault();
this.setState({useDiff: true});
}
handleDiffSubmit(e) {
e.preventDefault();
const {formatMessage} = this.props.intl;
var state = {useDiff: true, serverError: ''};
var email = ReactDOM.findDOMNode(this.refs.email).value.trim().toLowerCase();
if (!email || !Utils.isEmail(email)) {
state.emailError = formatMessage(holders.validEmailError);
this.setState(state);
return;
} else if (!BrowserStore.isLocalStorageSupported()) {
state.emailError = formatMessage(holders.storageError);
this.setState(state);
return;
}
state.emailError = '';
Client.signupTeam(email,
function success(data) {
if (data.follow_link) {
window.location.href = data.follow_link;
} else {
this.props.state.wizard = 'finished';
this.props.updateParent(this.props.state);
window.location.href = '/signup_team_confirm/?email=' + encodeURIComponent(email);
}
}.bind(this),
function error(err) {
let errorMsg = err.message;
if (err.detailed_error.indexOf('Invalid RCPT TO address provided') >= 0) {
errorMsg = formatMessage(holders.validEmailError);
}
this.setState({emailError: '', serverError: errorMsg});
}.bind(this)
);
}
handleKeyPress(event) {
if (event.keyCode === 13) {
this.submitNext(event);
}
}
componentWillUnmount() {
document.removeEventListener('keyup', this.handleKeyPress, false);
}
render() {
Client.track('signup', 'signup_team_01_welcome');
var storageError = null;
if (this.state.storageError) {
storageError = <label className='control-label'>{this.state.storageError}</label>;
}
var emailError = null;
var emailDivClass = 'form-group';
if (this.state.emailError) {
emailError = <label className='control-label'>{this.state.emailError}</label>;
emailDivClass += ' has-error';
}
var serverError = null;
if (this.state.serverError) {
serverError = (
<div className='form-group has-error'>
<label className='control-label'>{this.state.serverError}</label>
</div>
);
}
var differentEmailLinkClass = '';
var emailDivContainerClass = 'hidden';
if (this.state.useDiff) {
differentEmailLinkClass = 'hidden';
emailDivContainerClass = '';
}
return (
<div>
<img
className='signup-team-logo'
src='/static/images/logo.png'
/>
<h3 className='sub-heading'>
<FormattedMessage
id='team_signup_welcome.welcome'
defaultMessage='Welcome to:'
/>
</h3>
<h1 className='margin--top-none'>{global.window.mm_config.SiteName}</h1>
<p className='margin--less'>
<FormattedMessage
id='team_signup_welcome.lets'
defaultMessage="Let's set up your new team"
/>
</p>
<div>
<FormattedMessage
id='team_signup_welcome.confirm'
defaultMessage='Please confirm your email address:'
/>
<br />
<div className='inner__content'>
<div className='block--gray'>{this.props.state.team.email}</div>
</div>
</div>
<p className='margin--extra color--light'>
<FormattedHTMLMessage
id='team_signup_welcome.admin'
defaultMessage='Your account will administer the new team site. <br />
You can add other administrators later.'
/>
</p>
<div className='form-group'>
<button
className='btn-primary btn form-group'
type='submit'
onClick={this.submitNext}
>
<i className='glyphicon glyphicon-ok'></i>
<FormattedMessage
id='team_signup_welcome.yes'
defaultMessage='Yes, this address is correct'
/>
</button>
{storageError}
</div>
<hr />
<div className={emailDivContainerClass}>
<div className={emailDivClass}>
<div className='row'>
<div className='col-sm-9'>
<input
type='email'
ref='email'
className='form-control'
placeholder={this.props.intl.formatMessage(holders.address)}
maxLength='128'
spellCheck='false'
/>
</div>
</div>
{emailError}
</div>
{serverError}
<button
className='btn btn-md btn-primary'
type='button'
onClick={this.handleDiffSubmit}
>
<FormattedMessage
id='team_signup_welcome.instead'
defaultMessage='Use this instead'
/>
</button>
</div>
<a
href='#'
onClick={this.handleDiffEmail}
className={differentEmailLinkClass}
>
<FormattedMessage
id='team_signup_welcome.different'
defaultMessage='Use a different email'
/>
</a>
</div>
);
}
}
TeamSignupWelcomePage.defaultProps = {
state: {}
};
TeamSignupWelcomePage.propTypes = {
intl: intlShape.isRequired,
updateParent: React.PropTypes.func.isRequired,
state: React.PropTypes.object
};
export default injectIntl(TeamSignupWelcomePage);
|