summaryrefslogtreecommitdiffstats
path: root/web/react/components/signup_team.jsx
blob: 5e8ae117d01c2c1a45f77eed10bd8f69b2d87202 (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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import ChoosePage from './team_signup_choose_auth.jsx';
import EmailSignUpPage from './team_signup_with_email.jsx';
import SSOSignupPage from './team_signup_with_sso.jsx';
import Constants from '../utils/constants.jsx';

import {FormattedMessage} from 'mm-intl';

export default class TeamSignUp extends React.Component {
    constructor(props) {
        super(props);

        this.updatePage = this.updatePage.bind(this);

        var count = 0;

        if (global.window.mm_config.EnableSignUpWithEmail === 'true') {
            count = count + 1;
        }

        if (global.window.mm_config.EnableSignUpWithGitLab === 'true') {
            count = count + 1;
        }

        if (count > 1) {
            this.state = {page: 'choose'};
        } else if (global.window.mm_config.EnableSignUpWithEmail === 'true') {
            this.state = {page: 'email'};
        } else if (global.window.mm_config.EnableSignUpWithGitLab === 'true') {
            this.state = {page: 'gitlab'};
        } else {
            this.state = {page: 'none'};
        }
    }

    updatePage(page) {
        this.setState({page});
    }

    render() {
        var teamListing = null;

        if (global.window.mm_config.EnableTeamListing === 'true') {
            if (this.props.teams.length === 0) {
                if (global.window.mm_config.EnableTeamCreation !== 'true') {
                    teamListing = (
                        <div>
                            <FormattedMessage
                                id='signup_team.noTeams'
                                defaultMessage='There are no teams include in the Team Directory and team creation has been disabled.'
                            />
                        </div>
                    );
                }
            } else {
                teamListing = (
                    <div>
                        <h4>
                            <FormattedMessage
                                id='signup_team.choose'
                                defaultMessage='Choose a Team'
                            />
                        </h4>
                        <div className='signup-team-all'>
                            {
                                this.props.teams.map((team) => {
                                    return (
                                        <div
                                            key={'team_' + team.name}
                                            className='signup-team-dir'
                                        >
                                            <a
                                                href={'/' + team.name}
                                            >
                                                <span className='signup-team-dir__name'>{team.display_name}</span>
                                                <span
                                                    className='glyphicon glyphicon-menu-right right signup-team-dir__arrow'
                                                    aria-hidden='true'
                                                />
                                            </a>
                                        </div>
                                    );
                                })
                            }
                        </div>
                        <h4>
                            <FormattedMessage
                                id='signup_team.createTeam'
                                defaultMessage='Or Create a Team'
                            />
                        </h4>
                    </div>
                );
            }
        }

        if (global.window.mm_config.EnableTeamCreation !== 'true') {
            if (teamListing == null) {
                return (
                    <div>
                        <FormattedMessage
                            id='signup_team.disabled'
                            defaultMessage='Team creation has been disabled.  Please contact an administrator for access.'
                        />
                    </div>
                );
            }

            return (
                <div>
                    {teamListing}
                </div>
            );
        }

        if (this.state.page === 'choose') {
            return (
                <div>
                    {teamListing}
                    <ChoosePage
                        updatePage={this.updatePage}
                    />
                </div>
            );
        }

        if (this.state.page === 'email') {
            return (
                <div>
                    {teamListing}
                    <EmailSignUpPage/>
                </div>
            );
        } else if (this.state.page === 'gitlab') {
            return (
                <div>
                    {teamListing}
                    <SSOSignupPage service={Constants.GITLAB_SERVICE}/>
                </div>
            );
        } else if (this.state.page === 'google') {
            return (
                <div>
                    {teamListing}
                    <SSOSignupPage service={Constants.GOOGLE_SERVICE}/>
                </div>
            );
        } else if (this.state.page === 'none') {
            return (
                <div>
                    <FormattedMessage
                        id='signup_team.none'
                        defaultMessage='No team creation method has been enabled.  Please contact an administrator for access.'
                    />
                </div>
            );
        }

        return null;
    }
}

TeamSignUp.propTypes = {
    teams: React.PropTypes.array
};