import React from 'react'; import { connect } from 'react-redux'; import { edit, save, init, update } from 'Duck/integrations/slack'; import { Form, Input, Button, Message } from 'UI'; import { confirm } from 'UI'; import { remove } from 'Duck/integrations/slack'; class SlackAddForm extends React.PureComponent { componentWillUnmount() { this.props.init({}); } save = () => { const instance = this.props.instance; if (instance.exists()) { this.props.update(this.props.instance); } else { this.props.save(this.props.instance); } }; remove = async (id) => { if ( await confirm({ header: 'Confirm', confirmButton: 'Yes, delete', confirmation: `Are you sure you want to permanently delete this channel?`, }) ) { this.props.remove(id); } }; write = ({ target: { name, value } }) => this.props.edit({ [name]: value }); render() { const { instance, saving, errors, onClose } = this.props; return (
{errors && (
{errors.map((error) => ( {error} ))}
)}
); } } export default connect( (state) => ({ instance: state.getIn(['slack', 'instance']), saving: state.getIn(['slack', 'saveRequest', 'loading']) || state.getIn(['slack', 'updateRequest', 'loading']), errors: state.getIn(['slack', 'saveRequest', 'errors']), }), { edit, save, init, remove, update } )(SlackAddForm);