2016-03-21 15:08:26 -04:00
|
|
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2016-10-19 14:49:25 -04:00
|
|
|
import SpinnerButton from 'components/spinner_button.jsx';
|
2016-03-21 15:08:26 -04:00
|
|
|
|
2016-10-19 14:49:25 -04:00
|
|
|
import {addUserToChannel} from 'actions/channel_actions.jsx';
|
2016-03-21 15:08:26 -04:00
|
|
|
|
2016-10-19 14:49:25 -04:00
|
|
|
import React from 'react';
|
2016-03-21 15:08:26 -04:00
|
|
|
import {FormattedMessage} from 'react-intl';
|
|
|
|
|
|
|
|
|
|
export default class ChannelInviteButton extends React.Component {
|
|
|
|
|
static get propTypes() {
|
|
|
|
|
return {
|
|
|
|
|
user: React.PropTypes.object.isRequired,
|
|
|
|
|
channel: React.PropTypes.object.isRequired,
|
|
|
|
|
onInviteError: React.PropTypes.func.isRequired
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.handleClick = this.handleClick.bind(this);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
addingUser: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-22 10:03:17 -04:00
|
|
|
handleClick() {
|
2016-03-21 15:08:26 -04:00
|
|
|
if (this.state.addingUser) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
addingUser: true
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-19 14:49:25 -04:00
|
|
|
addUserToChannel(
|
2016-03-21 15:08:26 -04:00
|
|
|
this.props.channel.id,
|
2016-04-21 22:37:01 -07:00
|
|
|
this.props.user.id,
|
2016-03-21 15:08:26 -04:00
|
|
|
() => {
|
|
|
|
|
this.props.onInviteError(null);
|
|
|
|
|
},
|
|
|
|
|
(err) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
addingUser: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.props.onInviteError(err);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
2016-03-22 10:03:17 -04:00
|
|
|
<SpinnerButton
|
2016-03-28 09:41:03 -04:00
|
|
|
className='btn btn-sm btn-primary'
|
2016-03-21 15:08:26 -04:00
|
|
|
onClick={this.handleClick}
|
2016-03-22 10:03:17 -04:00
|
|
|
spinning={this.state.addingUser}
|
2016-03-21 15:08:26 -04:00
|
|
|
>
|
2016-07-06 00:46:36 +05:00
|
|
|
<i className='fa fa-envelope fa-margin--right'/>
|
2016-03-21 15:08:26 -04:00
|
|
|
<FormattedMessage
|
|
|
|
|
id='channel_invite.add'
|
|
|
|
|
defaultMessage=' Add'
|
|
|
|
|
/>
|
2016-03-22 10:03:17 -04:00
|
|
|
</SpinnerButton>
|
2016-03-21 15:08:26 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|