import React from 'react'; import PureRenderMixin from 'react-addons-pure-render-mixin'; import Select from 'react-select'; import classNames from 'classnames'; import Flux from '../lib/flux'; import AnalyticsUtils from '../utils/AnalyticsUtils'; import InstantInviteUtils from '../utils/InstantInviteUtils'; import InstantInviteStore from '../stores/InstantInviteStore'; import StreamerModeStore from '../stores/StreamerModeStore'; import InstantInviteActionCreators from '../actions/InstantInviteActionCreators'; import InstantInvite from './InstantInvite'; import Spinner from './common/Spinner'; import Checkbox from './common/Checkbox'; import SaveButton from './common/SaveButton'; import HelpButton from './common/HelpButton'; import Countdown from './common/Countdown'; import i18n from '../i18n'; import '../styles/instant_invite_popout.styl'; import '../styles/popout.styl'; const LOCATION = 'Instant Invite Popout'; const MAX_AGE_REF = 'max_age'; const MAX_USES_REF = 'max_uses'; const TEMPORARY_REF = 'temporary'; const MAX_AGE_OPTIONS = InstantInviteUtils.getMaxAgeOptions; const MAX_USES_OPTIONS = InstantInviteUtils.getMaxUsesOptions; const InstantInvitePopout = React.createClass({ mixins: [Flux.StoreListenerMixin(InstantInviteStore, StreamerModeStore), PureRenderMixin], propTypes: { channel: React.PropTypes.object.isRequired, source: React.PropTypes.string, }, getDefaultProps() { return { source: null, }; }, getInitialState() { return { advanced: false, [MAX_AGE_REF]: MAX_AGE_OPTIONS[1].value, [MAX_USES_REF]: MAX_USES_OPTIONS[0].value, [TEMPORARY_REF]: false, }; }, getStateFromStores() { return { invite: InstantInviteStore.getInvite(this.props.channel.id), hide: StreamerModeStore.hideInstantInvites, }; }, componentDidMount() { const validate = this.state.invite ? this.state.invite.code : null; InstantInviteActionCreators.createInvite(this.props.channel.id, {validate}, 'InstantInvitePopout Mount'); let {source} = this.props; if (source != null) { if (window.inviteButtonSource) { source = window.inviteButtonSource; window.inviteButtonSource = undefined; } AnalyticsUtils.track('open_popout', { Type: 'Instant Invite', Source: source, }); } }, handleRegenerate() { const regenerate = this.state.invite ? this.state.invite.code : null; InstantInviteActionCreators.createInvite(this.props.channel.id, {regenerate}, 'InstantInvitePopout Regenerate'); }, handleShowAdvanced(e) { e.preventDefault(); e.stopPropagation(); this.setState({advanced: true}); }, handleHideAdvanced(e) { e.preventDefault(); e.stopPropagation(); this.setState({advanced: false}); }, handleSubmit(e) { e.preventDefault(); InstantInviteActionCreators.createInvite( this.props.channel.id, { [MAX_AGE_REF]: parseInt(this.state[MAX_AGE_REF], 10), [MAX_USES_REF]: parseInt(this.state[MAX_USES_REF], 10), [TEMPORARY_REF]: this.state[TEMPORARY_REF], }, 'InstantInvitePopout' ); this.setState({advanced: false}); }, handleMaxAgeChange(maxAge) { this.setState({[MAX_AGE_REF]: maxAge}); }, handleMaxUsesChange(maxUses) { this.setState({[MAX_USES_REF]: maxUses}); }, handleTemporaryChange(e) { this.setState({[TEMPORARY_REF]: e.currentTarget.checked}); }, renderBasic() { const {invite, hide} = this.state; let instantInvite; let countdown; if (invite == null) { instantInvite = ; } else { instantInvite =