summaryrefslogtreecommitdiffstats
path: root/webapp/components/signup_team_complete/components/team_signup_send_invites_page.jsx
blob: db060b6b9dfc1620263431afe12fc3213488a9e1 (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
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import $ from 'jquery';
import EmailItem from './team_signup_email_item.jsx';
import * as Client from 'utils/client.jsx';

import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';

import logoImage from 'images/logo.png';

import React from 'react';

export default class TeamSignupSendInvitesPage extends React.Component {
    constructor(props) {
        super(props);
        this.submitBack = this.submitBack.bind(this);
        this.submitNext = this.submitNext.bind(this);
        this.submitAddInvite = this.submitAddInvite.bind(this);
        this.submitSkip = this.submitSkip.bind(this);
        this.keySubmit = this.keySubmit.bind(this);
        this.state = {
            emailEnabled: global.window.mm_config.SendEmailNotifications === 'true'
        };
    }
    submitBack(e) {
        e.preventDefault();
        this.props.state.wizard = 'team_url';

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

        var valid = true;

        if (this.state.emailEnabled) {
            var emails = [];

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

            if (valid) {
                this.props.state.invites = emails;
            }
        }

        if (valid) {
            this.props.state.wizard = 'username';
            this.props.updateParent(this.props.state);
        }
    }
    submitAddInvite(e) {
        e.preventDefault();
        this.props.state.wizard = 'send_invites';
        if (!this.props.state.invites) {
            this.props.state.invites = [];
        }
        this.props.state.invites.push('');
        this.props.updateParent(this.props.state);
    }
    submitSkip(e) {
        e.preventDefault();
        this.props.state.wizard = 'username';
        this.props.updateParent(this.props.state);
    }
    keySubmit(e) {
        if (e && e.keyCode === 13) {
            this.submitNext(e);
        }
    }
    componentDidMount() {
        if (!this.state.emailEnabled) {
            // Must use keypress not keyup due to event chain of pressing enter
            $('body').keypress(this.keySubmit);
        }
    }
    componentWillUnmount() {
        if (!this.state.emailEnabled) {
            $('body').off('keypress', this.keySubmit);
        }
    }
    render() {
        Client.track('signup', 'signup_team_05_send_invites');

        var content = null;
        var bottomContent = null;

        if (this.state.emailEnabled) {
            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]}
                        />
                    );
                }
            }

            content = (
                <div>
                    {emails}
                    <div className='form-group text-right'>
                        <a
                            href='#'
                            onClick={this.submitAddInvite}
                        >
                            <FormattedMessage
                                id='team_signup_send_invites.addInvitation'
                                defaultMessage='Add Invitation'
                            />
                        </a>
                    </div>
                </div>
            );

            bottomContent = (
                <p className='color--light'>
                    <FormattedHTMLMessage
                        id='team_signup_send_invites.prefer'
                        defaultMessage='if you prefer, you can invite team members later<br /> and '
                    />
                    <a
                        href='#'
                        onClick={this.submitSkip}
                    >
                        <FormattedMessage
                            id='team_signup_send_invites.skip'
                            defaultMessage='skip this step '
                        />
                    </a>
                    <FormattedMessage
                        id='team_signup_send_invites.forNow'
                        defaultMessage='for now.'
                    />
                </p>
            );
        } else {
            content = (
                <div className='form-group color--light'>
                    <FormattedMessage
                        id='team_signup_send_invites.disabled'
                        defaultMessage='Email is currently disabled for your team, and emails cannot be sent. Contact your system administrator to enable email and email invitations.'
                    />
                </div>
            );
        }

        return (
            <div>
                <form>
                    <img
                        className='signup-team-logo'
                        src={logoImage}
                    />
                    <h2>
                        <FormattedMessage
                            id='team_signup_send_invites.title'
                            defaultMessage='Invite Team Members'
                        />
                    </h2>
                    {content}
                    <div className='form-group'>
                        <button
                            type='submit'
                            className='btn-primary btn'
                            onClick={this.submitNext}
                        >
                            <FormattedMessage
                                id='team_signup_send_invites.next'
                                defaultMessage='Next'
                            /><i className='glyphicon glyphicon-chevron-right'/>
                        </button>
                    </div>
                </form>
                {bottomContent}
                <div className='margin--extra'>
                    <a
                        href='#'
                        onClick={this.submitBack}
                    >
                        <FormattedMessage
                            id='team_signup_send_invites.back'
                            defaultMessage='Back to previous step'
                        />
                    </a>
                </div>
            </div>
        );
    }
}

TeamSignupSendInvitesPage.propTypes = {
    state: React.PropTypes.object.isRequired,
    updateParent: React.PropTypes.func.isRequired
};