113 lines
3.7 KiB
JavaScript
Executable file
113 lines
3.7 KiB
JavaScript
Executable file
import React from 'react';
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
import classNames from 'classnames';
|
|
import Flux from '../lib/flux';
|
|
import Spinner from './common/Spinner';
|
|
import InstantInviteActionCreators from '../actions/InstantInviteActionCreators';
|
|
import InviteStore from '../stores/InviteStore';
|
|
import GuildStore from '../stores/GuildStore';
|
|
import {InviteStates} from '../Constants';
|
|
import i18n from '../i18n';
|
|
import '../styles/invite_button.styl';
|
|
|
|
const InviteButton = React.createClass({
|
|
mixins: [PureRenderMixin, Flux.StoreListenerMixin(InviteStore, GuildStore)],
|
|
|
|
propTypes: {
|
|
code: React.PropTypes.string.isRequired,
|
|
},
|
|
|
|
getStateFromStores() {
|
|
const invite = InviteStore.getInvite(this.props.code);
|
|
return {
|
|
invite,
|
|
isMember: invite && invite.guild && GuildStore.getGuild(invite.guild.id),
|
|
};
|
|
},
|
|
|
|
handleAcceptInstantInvite() {
|
|
InstantInviteActionCreators.acceptInvite(this.props.code, 'Invite Button Embed', () => {
|
|
this.handleTransitionToInviteChannel();
|
|
});
|
|
},
|
|
|
|
handleTransitionToInviteChannel() {
|
|
InstantInviteActionCreators.transitionToInviteChannelSync(this.state.invite.channel.id);
|
|
},
|
|
|
|
render() {
|
|
const invite = this.state.invite || {state: InviteStates.RESOLVING};
|
|
|
|
const channelType = invite.channel != null ? invite.channel.type : null;
|
|
const channelName = invite.channel != null ? invite.channel.name : '';
|
|
const guildName = invite.guild != null ? invite.guild.name : '';
|
|
|
|
let className;
|
|
let body;
|
|
let spinner;
|
|
let onClick;
|
|
switch (invite.state) {
|
|
case InviteStates.RESOLVING:
|
|
className = 'resolving';
|
|
spinner = <Spinner type="chasing-dots" />;
|
|
body = (
|
|
<div className="invite-button-inner">
|
|
<div className="invite-button-header">{i18n.Messages.INVITE_BUTTON_RESOLVING}</div>
|
|
</div>
|
|
);
|
|
break;
|
|
case InviteStates.EXPIRED:
|
|
className = 'expired';
|
|
body = (
|
|
<div className="invite-button-inner">
|
|
<div className="invite-button-header">{i18n.Messages.INVITE_BUTTON_EXPIRED}</div>
|
|
</div>
|
|
);
|
|
break;
|
|
case InviteStates.ACCEPTING:
|
|
className = 'accepting';
|
|
spinner = <Spinner type="chasing-dots" />;
|
|
body = (
|
|
<div className="invite-button-inner">
|
|
<div className="invite-button-header">{i18n.Messages.INVITE_BUTTON_ACCEPTING.format({channelName})}</div>
|
|
<div className="invite-button-body">{guildName}</div>
|
|
</div>
|
|
);
|
|
break;
|
|
default:
|
|
if (this.state.isMember) {
|
|
className = 'accepted';
|
|
onClick = this.handleTransitionToInviteChannel;
|
|
body = (
|
|
<div className="invite-button-inner">
|
|
<div className="invite-button-header">{i18n.Messages.INVITE_BUTTON_ACCEPTED.format({channelName})}</div>
|
|
<div className="invite-button-body">{guildName}</div>
|
|
</div>
|
|
);
|
|
} else {
|
|
className = 'join';
|
|
onClick = this.handleAcceptInstantInvite;
|
|
body = (
|
|
<div className="invite-button-inner">
|
|
<div className="invite-button-header">{i18n.Messages.INVITE_BUTTON_JOIN.format({channelName})}</div>
|
|
<div className="invite-button-body">{guildName}</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className={classNames('invite-button', className, channelType, {'can-click': !!onClick})} onClick={onClick}>
|
|
<div className={classNames('invite-button-icon', className)}>{spinner}</div>
|
|
{body}
|
|
</div>
|
|
);
|
|
},
|
|
});
|
|
|
|
export default InviteButton;
|
|
|
|
|
|
|
|
// WEBPACK FOOTER //
|
|
// ./discord_app/components/InviteButton.js
|