import React from 'react'; import { connect } from 'react-redux'; import { edit, save, init, update, remove } from 'Duck/integrations/teams'; import { Form, Input, Button, Message } from 'UI'; import { confirm } from 'UI'; interface Props { edit: (inst: any) => void; save: (inst: any) => void; init: (inst: any) => void; update: (inst: any) => void; remove: (id: string) => void; onClose: () => void; instance: any; saving: boolean; errors: any; } class TeamsAddForm 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: string) => { 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 } }: { target: { name: string; value: string } }) => this.props.edit({ [name]: value }); render() { const { instance, saving, errors, onClose } = this.props; return (
{errors && (
{errors.map((error: any) => ( {error} ))}
)}
); } } export default connect( (state: any) => ({ instance: state.getIn(['teams', 'instance']), saving: state.getIn(['teams', 'saveRequest', 'loading']) || state.getIn(['teams', 'updateRequest', 'loading']), errors: state.getIn(['teams', 'saveRequest', 'errors']), }), { edit, save, init, remove, update } )(TeamsAddForm);