summaryrefslogtreecommitdiffstats
path: root/webapp/components/admin_console/remove_file_setting.jsx
blob: ff453d9fccef0cd4b307e3f9e7e2915384fafba5 (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
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import $ from 'jquery';
import PropTypes from 'prop-types';
import React from 'react';

import Setting from './setting.jsx';

export default class RemoveFileSetting extends Setting {
    static get propTypes() {
        return {
            id: PropTypes.string.isRequired,
            label: PropTypes.node.isRequired,
            helpText: PropTypes.node,
            removeButtonText: PropTypes.node.isRequired,
            removingText: PropTypes.node,
            fileName: PropTypes.string.isRequired,
            onSubmit: PropTypes.func.isRequired,
            disabled: PropTypes.bool
        };
    }

    constructor(props) {
        super(props);
        this.handleRemove = this.handleRemove.bind(this);
    }

    handleRemove(e) {
        e.preventDefault();

        $(this.refs.remove_button).button('loading');
        this.props.onSubmit(this.props.id, () => {
            $(this.refs.remove_button).button('reset');
        });
    }

    render() {
        return (
            <Setting
                label={this.props.label}
                helpText={this.props.helpText}
                inputId={this.props.id}
            >
                <div>
                    <div className='help-text remove-filename'>
                        {this.props.fileName}
                    </div>
                    <button
                        className='btn btn-danger'
                        onClick={this.handleRemove}
                        ref='remove_button'
                        disabled={this.props.disabled}
                        data-loading-text={`<span class='glyphicon glyphicon-refresh glyphicon-refresh-animate'></span> ${this.props.removingText}`}
                    >
                        {this.props.removeButtonText}
                    </button>
                </div>
            </Setting>
        );
    }
}