import { connect } from 'react-redux'; import { toast } from 'react-toastify'; import withRequest from 'HOCs/withRequest'; import { Popup, Dropdown, Icon, IconButton } from 'UI'; import { pause } from 'Player'; import styles from './sharePopup.css'; @connect(state => ({ channels: state.getIn([ 'slack', 'list' ]), tenantId: state.getIn([ 'user', 'client', 'tenantId' ]), })) @withRequest({ endpoint: ({ id, entity }, integrationId) => `/integrations/slack/notify/${ integrationId }/${entity}/${ id }`, method: "POST", }) export default class SharePopup extends React.PureComponent { state = { comment: '', isOpen: false, channelId: this.props.channels.getIn([ 0, 'id' ]), } editMessage = e => this.setState({ comment: e.target.value }) share = () => this.props.request({ comment: this.state.comment }, this.state.channelId) .then(this.handleSuccess) handleOpen = () => { this.setState({ isOpen: true }); pause(); setTimeout(function() { document.getElementById('message').focus(); }, 100) } handleClose = () => { this.setState({ isOpen: false, comment: '' }); } handleSuccess = () => { toast.success('Your comment is shared.'); this.handleClose(); } changeChannel = (e, { value }) => this.setState({ channelId: value }) render() { const { trigger, loading, channels, tenantId } = this.props; const { comment, isOpen, channelId } = this.state; const options = channels.map(({ id, name }) => ({ value: id, text: name })).toJS(); return (
{ 'Comment' }
{ options.length === 0 ?
: