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_data'; const messages = defineMessages({ heading: { id: 'column.import_data', defaultMessage: 'Import data' }, }); export default @connect() @injectIntl class ImportData extends ImmutablePureComponent { static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { followsCSV: null, isLoading: false, } handleSubmit = (event) => { const { dispatch } = this.props; let params = new FormData(); params.append('list', this.state.followsCSV); this.setState({ isLoading: true }); dispatch(importFollows(params)).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); }); event.preventDefault(); } handleFileChange = e => { const [followsCSV] = e.target.files || []; this.setState({ followsCSV }); } render() { const { intl } = this.props; return (
} name='follows' hint={} onChange={this.handleFileChange} />
); } }