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

var SettingItemMin = require('./setting_item_min.jsx');
var SettingItemMax = require('./setting_item_max.jsx');

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

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

        this.submitValetFeature = this.submitValetFeature.bind(this);
        this.handleValetRadio = this.handleValetRadio.bind(this);
        this.onUpdateSection = this.onUpdateSection.bind(this);
        this.setupInitialState = this.setupInitialState.bind(this);

        this.state = this.setupInitialState();
    }
    componentWillReceiveProps(newProps) {
        var team = newProps.team;

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

        this.setState({allowValet: allowValet});
    }
    submitValetFeature() {
        var data = {};
        data.allow_valet = this.state.allowValet;

        Client.updateValetFeature(data,
            function success() {
                this.props.updateSection('');
                AsyncClient.getMyTeam();
            }.bind(this),
            function fail(err) {
                var state = this.setupInitialState();
                state.serverError = err;
                this.setState(state);
            }.bind(this)
        );
    }
    handleValetRadio(val) {
        this.setState({allowValet: val});
        React.findDOMNode(this.refs.wrapper).focus();
    }
    onUpdateSection(e) {
        e.preventDefault();
        if (this.props.activeSection === 'valet') {
            this.props.updateSection('');
        } else {
            this.props.updateSection('valet');
        }
    }
    setupInitialState() {
        var allowValet;
        var team = this.props.team;

        if (team && team.allow_valet) {
            allowValet = 'true';
        } else {
            allowValet = 'false';
        }

        return {allowValet: allowValet};
    }
    render() {
        var clientError = null;
        var serverError = null;
        if (this.state.clientError) {
            clientError = this.state.clientError;
        }
        if (this.state.serverError) {
            serverError = this.state.serverError;
        }

        var valetSection;

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

            let inputs = [];

            inputs.push(
                <div key='teamValetSetting'>
                    <div className='radio'>
                        <label>
                            <input
                                type='radio'
                                checked={valetActive[0]}
                                onChange={this.handleValetRadio.bind(this, 'true')}
                            >
                                On
                            </input>
                        </label>
                        <br/>
                    </div>
                    <div className='radio'>
                        <label>
                            <input
                                type='radio'
                                checked={valetActive[1]}
                                onChange={this.handleValetRadio.bind(this, 'false')}
                            >
                                Off
                            </input>
                        </label>
                        <br/>
                     </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={serverError}
                    client_error={clientError}
                    updateSection={this.onUpdateSection}
                />
            );
        } else {
            var describe = '';
            if (this.state.allowValet === 'false') {
                describe = 'Off';
            } else {
                describe = 'On';
            }

            valetSection = (
                <SettingItemMin
                    title='Valet (Preview - EXPERTS ONLY)'
                    describe={describe}
                    updateSection={this.onUpdateSection}
                />
            );
        }

        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>Advanced Features
                    </h4>
                </div>
                <div
                    ref='wrapper'
                    className='user-settings'
                >
                    <h3 className='tab-header'>Advanced Features</h3>
                    <div className='divider-dark first'/>
                    {valetSection}
                    <div className='divider-dark'/>
                </div>
            </div>
        );
    }
}

FeatureTab.defaultProps = {
    team: {},
    activeSection: ''
};
FeatureTab.propTypes = {
    updateSection: React.PropTypes.func.isRequired,
    team: React.PropTypes.object.isRequired,
    activeSection: React.PropTypes.string.isRequired
};