import { Form, Upload, Button} from 'antd' import { UploadOutlined} from '@ant-design/icons' import { useState } from 'react' import { upload } from './factory' export default function UploadForm({url, onUploadStart, onUploadComplete, onUploadError}) { const [isSubmitButtonEnabled, setSubmitButtonEnabled] = useState(false) const [form] = Form.useForm(); const handleFileSend = async (values) => { if(onUploadStart) onUploadStart() try { const values = await form.validateFields(); const formData = new FormData() values.file.fileList.forEach((val) => { formData.append("files", val.originFileObj); }); await upload(url, formData) } catch(error) { if(onUploadError) onUploadError(error) } finally { form.resetFields() if(onUploadComplete) onUploadComplete() } } return(
setSubmitButtonEnabled(props.fileList.length > 0)}>
) }