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

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