import React from 'react'; import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; import Column from '../ui/components/column'; import { SimpleForm, FieldsGroup, FileChooserCSV, } from 'soapbox/features/forms'; import { importFollows } from 'soapbox/actions/import_follows'; import { uploadMedia } from 'soapbox/actions/media'; const messages = defineMessages({ heading: { id: 'column.import_follows', defaultMessage: 'Import follows' }, }); const mapStateToProps = state => ({ follows: state.get('follows'), }); export default @connect(mapStateToProps) @injectIntl class ImportFollows extends ImmutablePureComponent { static propTypes = { follows: PropTypes.string, dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { isLoading: false, follows: this.props.follows, } setConfig = (value) => { this.setState({ follows: value }); }; handleSubmit = (event) => { const { dispatch } = this.props; dispatch(importFollows(this.state.follows)).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); }); this.setState({ isLoading: true }); event.preventDefault(); } handleChange = (getValue) => { return e => { this.setConfig(getValue(e)); }; }; handleFileChange = path => { return e => { const data = new FormData(); data.append('file', e.target.files[0]); this.props.dispatch(uploadMedia(data)).then(({ data }) => { this.handleChange(e => data.url)(e); }).catch(() => {}); }; }; render() { const { intl } = this.props; return (
} name='follows' hint={} onChange={this.handleFileChange('follows')} />
); } }