import React, { useState } from 'react'; import { MessageDescriptor, useIntl } from 'react-intl'; import { Button, FileInput, Form, FormActions, FormGroup, Text } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; import type { AppDispatch, RootState } from 'soapbox/store'; interface ICSVImporter { messages: { input_label: MessageDescriptor input_hint: MessageDescriptor submit: MessageDescriptor } action: (params: FormData) => (dispatch: AppDispatch, getState: () => RootState) => Promise } const CSVImporter: React.FC = ({ messages, action }) => { const dispatch = useAppDispatch(); const intl = useIntl(); const [isLoading, setIsLoading] = useState(false); const [file, setFile] = useState(null); const handleSubmit: React.FormEventHandler = (event) => { const params = new FormData(); params.append('list', file!); setIsLoading(true); dispatch(action(params)).then(() => { setIsLoading(false); }).catch(() => { setIsLoading(false); }); event.preventDefault(); }; const handleFileChange: React.ChangeEventHandler = e => { const file = e.target.files?.item(0); setFile(file); }; return (
{intl.formatMessage(messages.input_label)} {intl.formatMessage(messages.input_hint)}} >
); }; export default CSVImporter;