Добавлена возможность блокировки загрузки файла и вывод ошибки загрузки в консоль в режиме разработки

This commit is contained in:
Александр Сироткин 2022-02-22 15:28:55 +05:00
parent f268260df5
commit 168c2320ab

View File

@ -5,7 +5,7 @@ import { UploadOutlined } from '@ant-design/icons'
import { upload } from './factory'
import { ErrorFetch } from './ErrorFetch'
export const UploadForm = memo(({ url, accept, style, formData, onUploadStart, onUploadSuccess, onUploadComplete, onUploadError }) => {
export const UploadForm = memo(({ url, disabled, accept, style, formData, onUploadStart, onUploadSuccess, onUploadComplete, onUploadError }) => {
const [fileList, setfileList] = useState([])
const handleFileSend = async () => {
@ -27,6 +27,8 @@ export const UploadForm = memo(({ url, accept, style, formData, onUploadStart, o
onUploadSuccess?.()
}
} catch(error) {
if(process.env.NODE_ENV === 'development')
console.error(error)
onUploadError?.(error)
} finally {
setfileList([])
@ -40,10 +42,11 @@ export const UploadForm = memo(({ url, accept, style, formData, onUploadStart, o
<Upload
name={'file'}
accept={accept}
disabled={disabled}
fileList={fileList}
onChange={(props) => setfileList(props.fileList)}
>
<Button icon={<UploadOutlined/>}>Загрузить файл</Button>
<Button disabled={disabled} icon={<UploadOutlined/>}>Загрузить файл</Button>
</Upload>
<Button
type={'primary'}