summaryrefslogtreecommitdiffstats
path: root/web/react/components/signup_team_complete.jsx
blob: 4745e219d26f732fe006d7634fc941264d631ec1 (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.


var utils = require('../utils/utils.jsx');
var client = require('../utils/client.jsx');
var UserStore = require('../stores/user_store.jsx');
var BrowserStore = require('../stores/browser_store.jsx');
var constants = require('../utils/constants.jsx');

WelcomePage = React.createClass({
    submitNext: function (e) {
        if (!BrowserStore.isLocalStorageSupported()) {
            this.setState({ storage_error: "This service requires local storage to be enabled. Please enable it or exit private browsing."} );
            return;
        }
        e.preventDefault();
        this.props.state.wizard = "team_display_name";
        this.props.updateParent(this.props.state);
    },
    handleDiffEmail: function (e) {
        e.preventDefault();
        this.setState({ use_diff: true });
    },
    handleDiffSubmit: function (e) {
        e.preventDefault();

        var state = { use_diff: true, server_error: "" };

        var email = this.refs.email.getDOMNode().value.trim().toLowerCase();
        if (!email || !utils.isEmail(email)) {
            state.email_error = "Please enter a valid email address";
            this.setState(state);
            return;
        }
        else if (!BrowserStore.isLocalStorageSupported()) {
            state.email_error = "This service requires local storage to be enabled. Please enable it or exit private browsing.";
            this.setState(state);
            return;
        }
        else {
            state.email_error = "";
        }

        client.signupTeam(email,
            function(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(team.email);
                }
            }.bind(this),
            function(err) {
                this.state.server_error = err.message;
                this.setState(this.state);
            }.bind(this)
        );
    },
    getInitialState: function() {
        return { use_diff: false };
    },
    handleKeyPress: function(event) {
        if (event.keyCode == 13) {
            this.submitNext(event);
        }
    },
    componentWillMount: function() {
        document.addEventListener("keyup", this.handleKeyPress, false);
    },
    componentWillUnmount: function() {
        document.removeEventListener("keyup", this.handleKeyPress, false);
    },
    render: function() {

        client.track('signup', 'signup_team_01_welcome');

        var storage_error = this.state.storage_error ? <label className="control-label">{ this.state.storage_error }</label> : null;
        var email_error = this.state.email_error ? <label className="control-label">{ this.state.email_error }</label> : null;
        var server_error = this.state.server_error ? <div className={ "form-group has-error" }><label className="control-label">{ this.state.server_error }</label></div> : null;

        return (
            <div>
                <p>
                    <img className="signup-team-logo" src="/static/images/logo.png" />
                    <h3 className="sub-heading">Welcome to:</h3>
                    <h1 className="margin--top-none">{config.SiteName}</h1>
                </p>
                <p className="margin--less">Let's set up your new team</p>
                <p>
                    Please confirm your email address:<br />
                    <div className="inner__content">
                        <div className="block--gray">{ this.props.state.team.email }</div>
                    </div>
                </p>
                <p className="margin--extra color--light">
                    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>Yes, this address is correct</button>
                    { storage_error }
                </div>
                <hr />
                <div className={ this.state.use_diff ? "" : "hidden" }>
                    <div className={ email_error ? "form-group has-error" : "form-group" }>
                        <div className="row">
                            <div className="col-sm-9">
                                <input type="email" ref="email" className="form-control" placeholder="Email Address" maxLength="128" />
                            </div>
                        </div>
                        { email_error }
                    </div>
                    { server_error }
                    <button className="btn btn-md btn-primary" type="button" onClick={this.handleDiffSubmit} type="submit">Use this instead</button>
                </div>
                <a href="#" onClick={this.handleDiffEmail} className={ this.state.use_diff ? "hidden" : "" }>Use a different email</a>
            </div>
        );
    }
});

TeamDisplayNamePage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();
        this.props.state.wizard = "welcome";
        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        var display_name = this.refs.name.getDOMNode().value.trim();
        if (!display_name) {
            this.setState({name_error: "This field is required"});
            return;
        }

        this.props.state.wizard = "team_url";
        this.props.state.team.display_name = display_name;
        this.props.state.team.name = utils.cleanUpUrlable(display_name);
        this.props.updateParent(this.props.state);
    },
    getInitialState: function() {
        return {  };
    },
    handleFocus: function(e) {
        e.preventDefault();

        e.currentTarget.select();
    },
    render: function() {

        client.track('signup', 'signup_team_02_name');

        var name_error = this.state.name_error ? <label className="control-label">{ this.state.name_error }</label> : null;

        return (
            <div>
                <form>
                <img className="signup-team-logo" src="/static/images/logo.png" />

                <h2>{utils.toTitleCase(strings.Team) + " Name"}</h2>
                <div className={ name_error ? "form-group has-error" : "form-group" }>
                <div className="row">
                    <div className="col-sm-9">
                        <input type="text" ref="name" className="form-control" placeholder="" maxLength="128" defaultValue={this.props.state.team.display_name} autoFocus={true} onFocus={this.handleFocus} />
                    </div>
                </div>
                { name_error }
                </div>
                <div>{"Name your " + strings.Team + " in any language. Your " + strings.Team + " name shows in menus and headings."}</div>
                <button type="submit" className="btn btn-primary margin--extra" onClick={this.submitNext}>Next<i className="glyphicon glyphicon-chevron-right"></i></button>
                <div className="margin--extra">
                    <a href="#" onClick={this.submitBack}>Back to previous step</a>
                </div>
            </form>
            </div>
        );
    }
});

TeamURLPage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();
        this.props.state.wizard = "team_display_name";
        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        var name = this.refs.name.getDOMNode().value.trim();
        if (!name) {
            this.setState({name_error: "This field is required"});
            return;
        }

        var cleaned_name = utils.cleanUpUrlable(name);

        var urlRegex = /^[a-z0-9]+([a-z\-0-9]+|(__)?)[a-z0-9]+$/g;
        if (cleaned_name != name || !urlRegex.test(name)) {
            this.setState({name_error: "Must be lowercase alphanumeric characters"});
            return;
        }
        else if (cleaned_name.length <= 3 || cleaned_name.length > 15) {
            this.setState({name_error: "Name must be 4 or more characters up to a maximum of 15"})
            return;
        }

        for (var index = 0; index < constants.RESERVED_TEAM_NAMES.length; index++) {
            if (cleaned_name.indexOf(constants.RESERVED_TEAM_NAMES[index]) == 0) {
                this.setState({name_error: "This team name is unavailable"})
                return;
            }
        }

        client.findTeamByName(name,
            function(data) {
                if (!data) {
                    if (config.AllowSignupDomainsWizard) {
                        this.props.state.wizard = "allowed_domains";
                    } else {
                        this.props.state.wizard = "send_invites";
                        this.props.state.team.type = 'O';
                    }

                    this.props.state.team.name = name;
                    this.props.updateParent(this.props.state);
                }
                else {
                    this.state.name_error = "This URL is unavailable. Please try another.";
                    this.setState(this.state);
                }
            }.bind(this),
            function(err) {
                this.state.name_error = err.message;
                this.setState(this.state);
            }.bind(this)
        );
    },
    getInitialState: function() {
        return { };
    },
    handleFocus: function(e) {
        e.preventDefault();

        e.currentTarget.select();
    },
    render: function() {

        client.track('signup', 'signup_team_03_url');

        var name_error = this.state.name_error ? <label className="control-label">{ this.state.name_error }</label> : null;

        return (
            <div>
                <form>
                <img className="signup-team-logo" src="/static/images/logo.png" />
                <h2>{utils.toTitleCase(strings.Team) + " URL"}</h2>
                <div className={ name_error ? "form-group has-error" : "form-group" }>
               <div className="row">
                    <div className="col-sm-11">
                        <div className="input-group">
                            <span className="input-group-addon">{ utils.getWindowLocationOrigin() + "/" }</span>
                            <input type="text" ref="name" className="form-control" placeholder="" maxLength="128" defaultValue={this.props.state.team.name} autoFocus={true} onFocus={this.handleFocus}/>
                        </div>
                    </div>
                </div>
                { name_error }
                </div>
                <p>{"Choose the web address of your new " + strings.Team + ":"}</p>
                <ul className="color--light">
                    <li>Short and memorable is best</li>
                    <li>Use lower case letters, numbers and dashes</li>
                    <li>Must start with a letter and can't end in a dash</li>
                </ul>
                <button type="submit" className="btn btn-primary margin--extra" onClick={this.submitNext}>Next<i className="glyphicon glyphicon-chevron-right"></i></button>
                <div className="margin--extra">
                    <a href="#" onClick={this.submitBack}>Back to previous step</a>
                </div>
            </form>
            </div>
        );
    }
});

AllowedDomainsPage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();
        this.props.state.wizard = "team_url";
        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        if (this.refs.open_network.getDOMNode().checked) {
            this.props.state.wizard = "send_invites";
            this.props.state.team.type = 'O';
            this.props.updateParent(this.props.state);
            return;
        }

        if (this.refs.allow.getDOMNode().checked) {
            var name = this.refs.name.getDOMNode().value.trim();
            var domainRegex = /^\w+\.\w+$/
            if (!name) {
                this.setState({name_error: "This field is required"});
                return;
            }

            if(!name.trim().match(domainRegex)) {
                this.setState({name_error: "The domain doesn't appear valid"});
                return;
            }

            this.props.state.wizard = "send_invites";
            this.props.state.team.allowed_domains = name;
            this.props.state.team.type = 'I';
            this.props.updateParent(this.props.state);
        }
        else {
            this.props.state.wizard = "send_invites";
            this.props.state.team.type = 'I';
            this.props.updateParent(this.props.state);
        }
    },
    getInitialState: function() {
        return { };
    },
    render: function() {

        client.track('signup', 'signup_team_04_allow_domains');

        var name_error = this.state.name_error ? <label className="control-label">{ this.state.name_error }</label> : null;

        return (
            <div>
                <form>
                <img className="signup-team-logo" src="/static/images/logo.png" />
                <h2>Email Domain</h2>
                <p>
                <div className="checkbox"><label><input type="checkbox" ref="allow" defaultChecked />{" Allow sign up and " + strings.Team + " discovery with a " + strings.Company + " email address."}</label></div>
                </p>
                <p>{"Check this box to allow your " + strings.Team + " members to sign up using their " + strings.Company + " email addresses if you share the same domain--otherwise, you need to invite everyone yourself."}</p>
                <h4>{"Your " + strings.Team + "'s domain for emails"}</h4>
                <div className={ name_error ? "form-group has-error" : "form-group" }>
                <div className="row">
                    <div className="col-sm-9">
                        <div className="input-group">
                            <span className="input-group-addon">@</span>
                            <input type="text" ref="name" className="form-control" placeholder="" maxLength="128" defaultValue={this.props.state.team.allowed_domains} autoFocus={true} onFocus={this.handleFocus}/>
                        </div>
                    </div>
                </div>
                { name_error }
                </div>
                <p>To allow signups from multiple domains, separate each with a comma.</p>
                <p>
                <div className="checkbox"><label><input type="checkbox" ref="open_network" defaultChecked={this.props.state.team.type == 'O'} /> Allow anyone to signup to this domain without an invitation.</label></div>
                </p>
                <button type="button" className="btn btn-default" onClick={this.submitBack}><i className="glyphicon glyphicon-chevron-left"></i> Back</button>&nbsp;
                <button type="submit" className="btn-primary btn" onClick={this.submitNext}>Next<i className="glyphicon glyphicon-chevron-right"></i></button>
            </form>
            </div>
        );
    }
});

EmailItem = React.createClass({
    getInitialState: function() {
        return { };
    },
    getValue: function() {
        return this.refs.email.getDOMNode().value.trim()
    },
    validate: function(teamEmail) {
        var email = this.refs.email.getDOMNode().value.trim().toLowerCase();

        if (!email) {
            return true;
        }

        if (!utils.isEmail(email)) {
            this.state.email_error = "Please enter a valid email address";
            this.setState(this.state);
            return false;
        }
        else if (email === teamEmail) {
            this.state.email_error = "Please use a different email than the one used at signup";
            this.setState(this.state);
            return false;
        }
        else {
            this.state.email_error = "";
            this.setState(this.state);
            return true;
        }
    },
    render: function() {

        var email_error = this.state.email_error ? <label className="control-label">{ this.state.email_error }</label> : null;

        return (
            <div className={ email_error ? "form-group has-error" : "form-group" }>
                <input autoFocus={this.props.focus} type="email" ref="email" className="form-control" placeholder="Email Address" defaultValue={this.props.email} maxLength="128" />
                { email_error }
            </div>
        );
    }
});


SendInivtesPage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();

        if (config.AllowSignupDomainsWizard) {
            this.props.state.wizard = "allowed_domains";
        } else {
            this.props.state.wizard = "team_url";
        }

        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        var valid = true;
        var emails = [];

        for (var i = 0; i < this.props.state.invites.length; i++) {
            if (!this.refs['email_' + i].validate(this.props.state.team.email)) {
                valid = false;
            } else {
                emails.push(this.refs['email_' + i].getValue());
            }
        }

        if (!valid) {
            return;
        }

        this.props.state.wizard = "username";
        this.props.state.invites = emails;
        this.props.updateParent(this.props.state);
    },
    submitAddInvite: function (e) {
        e.preventDefault();
        this.props.state.wizard = "send_invites";
        if (this.props.state.invites == null || this.props.state.invites.length == 0) {
            this.props.state.invites = [];
        }
        this.props.state.invites.push("");
        this.props.updateParent(this.props.state);
    },
    submitSkip: function (e) {
        e.preventDefault();
        this.props.state.wizard = "username";
        this.props.updateParent(this.props.state);
    },
    getInitialState: function() {
        return { };
    },
    render: function() {

        client.track('signup', 'signup_team_05_send_invites');

        var name_error = this.state.name_error ? <label className="control-label">{ this.state.name_error }</label> : null;

        var emails = [];

        for (var i = 0; i < this.props.state.invites.length; i++) {
            if (i == 0) {
                emails.push(<EmailItem focus={true} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
            } else {
                emails.push(<EmailItem focus={false} key={i} ref={'email_' + i} email={this.props.state.invites[i]} />);
            }
        }

        return (
            <div>
                <form>
                    <img className="signup-team-logo" src="/static/images/logo.png" />
                    <h2>{"Invite " + utils.toTitleCase(strings.Team) + " Members"}</h2>
                    { emails }
                    <div className="form-group text-right"><a href="#" onClick={this.submitAddInvite}>Add Invitation</a></div>
                    <div className="form-group"><button type="submit" className="btn-primary btn" onClick={this.submitNext}>Next<i className="glyphicon glyphicon-chevron-right"></i></button></div>
                </form>
                <p className="color--light">{"if you prefer, you can invite " + strings.Team + " members later"}<br /> and <a href="#" onClick={this.submitSkip}>skip this step</a> for now.</p>
                <div className="margin--extra">
                    <a href="#" onClick={this.submitBack}>Back to previous step</a>
                </div>
            </div>
        );
    }
});

UsernamePage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();
        this.props.state.wizard = "send_invites";
        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        var name = this.refs.name.getDOMNode().value.trim();

        var username_error = utils.isValidUsername(name);
        if (username_error === "Cannot use a reserved word as a username.") {
            this.setState({name_error: "This username is reserved, please choose a new one." });
            return;
        } else if (username_error) {
            this.setState({name_error: "Username must begin with a letter, and contain between 3 to 15 lowercase characters made up of numbers, letters, and the symbols '.', '-' and '_'." });
            return;
        }


        this.props.state.wizard = "password";
        this.props.state.user.username = name;
        this.props.updateParent(this.props.state);
    },
    getInitialState: function() {
        return {  };
    },
    render: function() {

        client.track('signup', 'signup_team_06_username');

        var name_error = this.state.name_error ? <label className="control-label">{ this.state.name_error }</label> : null;

        return (
            <div>
                <form>
                <img className="signup-team-logo" src="/static/images/logo.png" />
                <h2 className="margin--less">Your username</h2>
                <h5 className="color--light">{"Select a memorable username that makes it easy for " + strings.Team + "mates to identify you:"}</h5>
                <div className="inner__content margin--extra">
                    <div className={ name_error ? "form-group has-error" : "form-group" }>
                    <div className="row">
                        <div className="col-sm-11">
                            <h5><strong>Choose your username</strong></h5>
                            <input autoFocus={true} type="text" ref="name" className="form-control" placeholder="" defaultValue={this.props.state.user.username} maxLength="128" />
                            <div className="color--light form__hint">Usernames must begin with a letter and contain 3 to 15 characters made up of lowercase letters, numbers, and the symbols '.', '-' and '_'</div>
                        </div>
                    </div>
                    { name_error }
                    </div>
                </div>
                <button type="submit" className="btn btn-primary margin--extra" onClick={this.submitNext}>Next<i className="glyphicon glyphicon-chevron-right"></i></button>
                <div className="margin--extra">
                    <a href="#" onClick={this.submitBack}>Back to previous step</a>
                </div>
            </form>
            </div>
        );
    }
});

PasswordPage = React.createClass({
    submitBack: function (e) {
        e.preventDefault();
        this.props.state.wizard = "username";
        this.props.updateParent(this.props.state);
    },
    submitNext: function (e) {
        e.preventDefault();

        var password = this.refs.password.getDOMNode().value.trim();
        if (!password || password.length < 5) {
            this.setState({password_error: "Please enter at least 5 characters"});
            return;
        }

        this.setState({password_error: null, server_error: null});
        $('#finish-button').button('loading');
        var teamSignup = JSON.parse(JSON.stringify(this.props.state));
        teamSignup.user.password = password;
        teamSignup.user.allow_marketing = true;
        delete teamSignup.wizard;
        var ctl = this;

        client.createTeamFromSignup(teamSignup,
            function(data) {

                client.track('signup', 'signup_team_08_complete');

                var props = this.props;

                $('#sign-up-button').button('reset');
                props.state.wizard = "finished";
                props.updateParent(props.state, true);

                window.location.href = utils.getWindowLocationOrigin() + '/' + props.state.team.name + '/login?email=' + encodeURIComponent(teamSignup.team.email);

                // client.loginByEmail(teamSignup.team.domain, teamSignup.team.email, teamSignup.user.password,
                //     function(data) {
                //         TeamStore.setLastName(teamSignup.team.domain);
                //         UserStore.setLastEmail(teamSignup.team.email);
                //         UserStore.setCurrentUser(data);
                //         window.location.href = '/channels/town-square';
                //     }.bind(ctl),
                //     function(err) {
                //         this.setState({name_error: err.message});
                //     }.bind(ctl)
                // );
            }.bind(this),
            function(err) {
                this.setState({server_error: err.message});
                $('#sign-up-button').button('reset');
            }.bind(this)
        );
    },
    getInitialState: function() {
        return {  };
    },
    render: function() {

        client.track('signup', 'signup_team_07_password');

        var password_error = this.state.password_error ? <div className="form-group has-error"><label className="control-label">{ this.state.password_error }</label></div> : null;
        var server_error = this.state.server_error ? <div className="form-group has-error"><label className="control-label">{ this.state.server_error }</label></div> : null;

        return (
            <div>
                <form>
                <img className="signup-team-logo" src="/static/images/logo.png" />
                <h2 className="margin--less">Your password</h2>
                <h5 className="color--light">Select a password that you'll use to login with your email address:</h5>
                <div className="inner__content margin--extra">
                    <h5><strong>Email</strong></h5>
                    <div className="block--gray form-group">{this.props.state.team.email}</div>
                    <div className={ password_error ? "form-group has-error" : "form-group" }>
                    <div className="row">
                        <div className="col-sm-11">
                            <h5><strong>Choose your password</strong></h5>
                            <input autoFocus={true} type="password" ref="password" className="form-control" placeholder="" maxLength="128" />
                            <div className="color--light form__hint">Passwords must contain 5 to 50 characters. Your password will be strongest if it contains a mix of symbols, numbers, and upper and lowercase characters.</div>
                        </div>
                    </div>
                        { password_error }
                        { server_error }
                    </div>
                </div>
                <div className="form-group">
                    <button type="submit" className="btn btn-primary margin--extra" id="finish-button" data-loading-text={"<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> Creating "+strings.Team+"..."} onClick={this.submitNext}>Finish</button>
                </div>
                <p>By proceeding to create your account and use { config.SiteName }, you agree to our <a href={ config.TermsLink }>Terms of Service</a> and <a href={ config.PrivacyLink }>Privacy Policy</a>. If you do not agree, you cannot use {config.SiteName}.</p>
                <div className="margin--extra">
                    <a href="#" onClick={this.submitBack}>Back to previous step</a>
                </div>
            </form>
            </div>
        );
    }
});

module.exports = React.createClass({
    updateParent: function(state, skipSet) {
        BrowserStore.setGlobalItem(this.props.hash, state);

        if (!skipSet) {
            this.setState(state);
        }
    },
    getInitialState: function() {
        var props = BrowserStore.getGlobalItem(this.props.hash);

        if (!props) {
            props = {};
            props.wizard = "welcome";
            props.team = {};
            props.team.email = this.props.email;
            props.team.allowed_domains = "";
            props.invites = [];
            props.invites.push("");
            props.invites.push("");
            props.invites.push("");
            props.user = {};
            props.hash = this.props.hash;
            props.data = this.props.data;
        }

        return props;
    },
    render: function() {
        if (this.state.wizard == "welcome") {
            return <WelcomePage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "team_display_name") {
            return <TeamDisplayNamePage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "team_url") {
            return <TeamURLPage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "allowed_domains") {
            return <AllowedDomainsPage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "send_invites") {
            return <SendInivtesPage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "username") {
            return <UsernamePage state={this.state} updateParent={this.updateParent} />
        }

        if (this.state.wizard == "password") {
            return <PasswordPage state={this.state} updateParent={this.updateParent} />
        }

        return (<div>You've already completed the signup process for this invitation or this invitation has expired.</div>);
    }
});