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

const Client = require('../utils/client.jsx');
const AsyncClient = require('../utils/async_client.jsx');
const ChannelStore = require('../stores/channel_store.jsx');
var TeamStore = require('../stores/team_store.jsx');

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

        this.handleDelete = this.handleDelete.bind(this);

        this.state = {
            title: '',
            channelId: ''
        };
    }
    handleDelete() {
        if (this.state.channelId.length !== 26) {
            return;
        }

        Client.deleteChannel(this.state.channelId,
            function handleDeleteSuccess() {
                AsyncClient.getChannels(true);
                window.location.href = TeamStore.getCurrentTeamUrl() + '/channels/town-square';
            },
            function handleDeleteError(err) {
                AsyncClient.dispatchError(err, 'handleDelete');
            }
        );
    }
    componentDidMount() {
        $(React.findDOMNode(this.refs.modal)).on('show.bs.modal', function handleShow(e) {
            var button = $(e.relatedTarget);
            this.setState({
                title: button.attr('data-title'),
                channelId: button.attr('data-channelid')
            });
        }.bind(this));
    }
    render() {
        const channel = ChannelStore.getCurrent();
        let channelType = 'channel';
        if (channel && channel.type === 'P') {
            channelType = 'private group';
        }

        return (
            <div
                className='modal fade'
                ref='modal'
                id='delete_channel'
                role='dialog'
                tabIndex='-1'
                aria-hidden='true'
            >
                <div className='modal-dialog'>
                    <div className='modal-content'>
                        <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'>Confirm DELETE Channel</h4>
                        </div>
                        <div className='modal-body'>
                            <p>
                                Are you sure you wish to delete the {this.state.title} {channelType}?
                            </p>
                        </div>
                        <div className='modal-footer'>
                            <button
                                type='button'
                                className='btn btn-default'
                                data-dismiss='modal'
                            >
                                Cancel
                            </button>
                            <button
                                type='button'
                                className='btn btn-danger'
                                data-dismiss='modal'
                                onClick={this.handleDelete}
                            >
                                Delete
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}