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

var UserStore = require('../stores/user_store.jsx');
var TeamStore = require('../stores/team_store.jsx');
var SettingItemMin = require('./setting_item_min.jsx');
var SettingItemMax = require('./setting_item_max.jsx');
var SettingPicture = require('./setting_picture.jsx');
var SettingUpload = require('./setting_upload.jsx');
var utils = require('../utils/utils.jsx');

var client = require('../utils/client.jsx');
var AsyncClient = require('../utils/async_client.jsx');
var Constants = require('../utils/constants.jsx');

var FeatureTab = React.createClass({
    submitValetFeature: function() {
        data = {};
        data['allow_valet'] = this.state.allow_valet;

        client.updateValetFeature(data,
            function(data) {
                this.props.updateSection("");
                AsyncClient.getMyTeam();
            }.bind(this),
            function(err) {
                state = this.getInitialState();
                state.server_error = err;
                this.setState(state);
            }.bind(this)
        );
    },
    handleValetRadio: function(val) {
        this.setState({ allow_valet: val });
        this.refs.wrapper.getDOMNode().focus();
    },
    componentWillReceiveProps: function(newProps) {
        var team = newProps.team;

        var allow_valet = "false";
        if (team && team.allow_valet) {
            allow_valet = "true";
        }

        this.setState({ allow_valet: allow_valet });
    },
    getInitialState: function() {
        var team = this.props.team;

        var allow_valet = "false";
        if (team && team.allow_valet) {
            allow_valet = "true";
        }

        return { allow_valet: allow_valet };
    },
    render: function() {
        var team = this.props.team;

        var client_error = this.state.client_error ? this.state.client_error : null;
        var server_error = this.state.server_error ? this.state.server_error : null;

        var valetSection;
        var self = this;

        if (this.props.activeSection === 'valet') {
            var valetActive = ["",""];
            if (this.state.allow_valet === "false") {
                valetActive[1] = "active";
            } else {
                valetActive[0] = "active";
            }

            var inputs = [];

            inputs.push(
                <div>
                    <div className="btn-group" data-toggle="buttons-radio">
                        <button className={"btn btn-default "+valetActive[0]} onClick={function(){self.handleValetRadio("true")}}>On</button>
                        <button className={"btn btn-default "+valetActive[1]} onClick={function(){self.handleValetRadio("false")}}>Off</button>
                    </div>
                    <div><br/>Valet is a preview feature for enabling a non-user account limited to basic member permissions that can be manipulated by 3rd parties.<br/><br/>IMPORTANT: The preview version of Valet should not be used without a secure connection and a trusted 3rd party, since user credentials are used to connect. OAuth2 will be used in the final release.</div>
                </div>
            );

            valetSection = (
                <SettingItemMax
                    title="Valet (Preview - EXPERTS ONLY)"
                    inputs={inputs}
                    submit={this.submitValetFeature}
                    server_error={server_error}
                    client_error={client_error}
                    updateSection={function(e){self.props.updateSection("");e.preventDefault();}}
                />
            );
        } else {
            var describe = "";
            if (this.state.allow_valet === "false") {
                describe = "Off";
            } else {
                describe = "On";
            }

            valetSection = (
                <SettingItemMin
                    title="Valet (Preview - EXPERTS ONLY)"
                    describe={describe}
                    updateSection={function(){self.props.updateSection("valet");}}
                />
            );
        }

        return (
            <div>
                <div className="modal-header">
                    <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 className="modal-title" ref="title"><i className="modal-back"></i>Feature Settings</h4>
                </div>
                <div ref="wrapper" className="user-settings">
                    <h3 className="tab-header">Feature Settings</h3>
                    <div className="divider-dark first"/>
                    {valetSection}
                    <div className="divider-dark"/>
                </div>
            </div>
        );
    }
});

var ImportTab = React.createClass({
    getInitialState: function() {
        return {status: 'ready'};
    },
    onImportFailure: function() {
        this.setState({status: 'fail'});
    },
    onImportSuccess: function(data) {
        this.setState({status: 'done'});
    },
    doImportSlack: function(file) {
        this.setState({status: 'in-progress'});
        utils.importSlack(file, this.onImportSuccess, this.onImportFailure);
    },
    render: function() {

		uploadSection = (
			<SettingUpload
				title="Import from Slack"
                submit={this.doImportSlack}
                fileTypesAccepted='.zip'/>
		);

        var messageSection;
        switch (this.state.status) {
            case 'ready':
                messageSection = '';
                break;
            case 'in-progress':
                messageSection = (
                    <p>Importing...</p>
                );
                break;
            case 'done':
                messageSection = (
                    <p>Import sucessfull: <a href={this.state.link} download='MattermostImportSummery.txt'>View Summery</a></p>
                );
                break;
            case 'fail':
                messageSection = (
                    <p>Import failure: <a href={this.state.link} download='MattermostImportSummery.txt'>View Summery</a></p>
                );
                break;
        }

        return (
            <div>
                <div className="modal-header">
                    <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 className="modal-title" ref="title"><i className="modal-back"></i>Import</h4>
                </div>
                <div ref="wrapper" className="user-settings">
                    <h3 className="tab-header">Import</h3>
                    <div className="divider-dark first"/>
					{uploadSection}
                    {messageSection}
                    <div className="divider-dark"/>
                </div>
            </div>
        );
	}
});

module.exports = React.createClass({
    componentDidMount: function() {
        TeamStore.addChangeListener(this._onChange);
    },
    componentWillUnmount: function() {
        TeamStore.removeChangeListener(this._onChange);
    },
    _onChange: function () {
        var team = TeamStore.getCurrent();
        if (!utils.areStatesEqual(this.state.team, team)) {
            this.setState({ team: team });
        }
    },
    getInitialState: function() {
        return { team: TeamStore.getCurrent() };
    },
    render: function() {
        if (this.props.activeTab === 'general') {
            return (
                <div>
                </div>
            );
        } else if (this.props.activeTab === 'feature') {
            return (
                <div>
                    <FeatureTab team={this.state.team} activeSection={this.props.activeSection} updateSection={this.props.updateSection} />
                </div>
            );
		} else if (this.props.activeTab === 'import') {
			return (
                <div>
                    <ImportTab team={this.state.team} activeSection={this.props.activeSection} updateSection={this.props.updateSection} />
                </div>
			);
		} else {
            return <div/>;
        }
    }
});