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) export default @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 }); }; // putConfig = config => { // this.setState({ soapbox: config, jsonValid: true }); // }; getParams = () => { const { follows } = this.state; return { follows: follows.toJS() }; } handleSubmit = (event) => { const { dispatch } = this.props; dispatch(importFollows(this.getParams())).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)); }; }; // handleUpload = (event) => { // const { dispatch } = this.props; // dispatch(importFollows(event.target.files[0])).then(() => { // this.setState({ isLoading: false }); // }).catch((error) => { // this.setState({ isLoading: false }); // }); // this.setState({ isLoading: true }); // event.preventDefault(); // } 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')} />
); } }