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

import SpinnerButton from 'components/spinner_button.jsx';

import {addUserToChannel} from 'actions/channel_actions.jsx';

import PropTypes from 'prop-types';

import React from 'react';
import {FormattedMessage} from 'react-intl';

export default class ChannelInviteButton extends React.Component {
    static get propTypes() {
        return {
            user: PropTypes.object.isRequired,
            channel: PropTypes.object.isRequired,
            onInviteError: PropTypes.func.isRequired
        };
    }

    constructor(props) {
        super(props);

        this.handleClick = this.handleClick.bind(this);

        this.state = {
            addingUser: false
        };
    }

    handleClick() {
        if (this.state.addingUser) {
            return;
        }

        this.setState({
            addingUser: true
        });

        addUserToChannel(
            this.props.channel.id,
            this.props.user.id,
            () => {
                this.props.onInviteError(null);
            },
            (err) => {
                this.setState({
                    addingUser: false
                });

                this.props.onInviteError(err);
            }
        );
    }

    render() {
        return (
            <SpinnerButton
                id='addMembers'
                className='btn btn-sm btn-primary'
                onClick={this.handleClick}
                spinning={this.state.addingUser}
            >
                <i className='fa fa-envelope fa-margin--right'/>
                <FormattedMessage
                    id='channel_invite.add'
                    defaultMessage=' Add'
                />
            </SpinnerButton>
        );
    }
}