forked from ddrilling/asb_cloud_front
Добавлен проп multiple в UploadForm
This commit is contained in:
parent
ea4dd1dfe0
commit
e610ab2768
@ -10,6 +10,7 @@ import { notify, upload } from './factory'
|
||||
import { ErrorFetch } from './ErrorFetch'
|
||||
|
||||
export type UploadFormProps = {
|
||||
multiple?: boolean
|
||||
url: string
|
||||
disabled?: boolean
|
||||
accept?: string
|
||||
@ -22,7 +23,7 @@ export type UploadFormProps = {
|
||||
onUploadError?: (error: unknown) => void
|
||||
}
|
||||
|
||||
export const UploadForm = memo<UploadFormProps>(({ url, disabled, style, formData, mimeTypes, onUploadStart, onUploadSuccess, onUploadComplete, onUploadError }) => {
|
||||
export const UploadForm = memo<UploadFormProps>(({ url, multiple, disabled, style, formData, mimeTypes, onUploadStart, onUploadSuccess, onUploadComplete, onUploadError }) => {
|
||||
const [fileList, setfileList] = useState<UploadFile<any>[]>([])
|
||||
|
||||
const checkMimeTypes = useCallback((file: RcFile) => {
|
||||
@ -38,7 +39,7 @@ export const UploadForm = memo<UploadFormProps>(({ url, disabled, style, formDat
|
||||
onUploadStart?.()
|
||||
try {
|
||||
const formDataLocal = new FormData()
|
||||
fileList.forEach((val) => formDataLocal.append('files', val.originFileObj as Blob))
|
||||
fileList.forEach((val) => formDataLocal.append(multiple ? 'files' : 'file', val.originFileObj as Blob))
|
||||
|
||||
if(formData)
|
||||
for(const propName in formData)
|
||||
@ -60,7 +61,7 @@ export const UploadForm = memo<UploadFormProps>(({ url, disabled, style, formDat
|
||||
setfileList([])
|
||||
onUploadComplete?.()
|
||||
}
|
||||
}, [fileList, formData, onUploadComplete, onUploadError, onUploadStart, onUploadSuccess, url])
|
||||
}, [fileList, formData, onUploadComplete, onUploadError, onUploadStart, onUploadSuccess, url, multiple])
|
||||
|
||||
const isSendButtonEnabled = fileList.length > 0
|
||||
return(
|
||||
@ -72,6 +73,7 @@ export const UploadForm = memo<UploadFormProps>(({ url, disabled, style, formDat
|
||||
fileList={fileList}
|
||||
onChange={(props) => setfileList(props.fileList)}
|
||||
beforeUpload={checkMimeTypes}
|
||||
maxCount={multiple ? undefined : 1}
|
||||
>
|
||||
<Button disabled={disabled} icon={<UploadOutlined/>}>Загрузить файл</Button>
|
||||
</Upload>
|
||||
|
@ -137,6 +137,7 @@ export const DocumentsTemplate = ({ idCategory, well: givenWell, mimeTypes, head
|
||||
<div>
|
||||
<span>Загрузка</span>
|
||||
<UploadForm
|
||||
multiple
|
||||
url={uploadUrl}
|
||||
mimeTypes={mimeTypes}
|
||||
onUploadStart={() => setShowLoader(true)}
|
||||
|
@ -123,6 +123,7 @@ export const CategoryRender = memo(({ partData, onUpdate, onEdit, onHistory, set
|
||||
<div className={'file_actions'}>
|
||||
{permissionToUpload && (
|
||||
<UploadForm
|
||||
multiple
|
||||
url={uploadUrl}
|
||||
mimeTypes={MimeTypes.XLSX}
|
||||
style={{ margin: '5px 0 10px 0' }}
|
||||
|
@ -34,6 +34,7 @@ export const ImportOperations = memo(({ well: givenWell, onDone }) => {
|
||||
<span>Очистить список операций перед импортом </span>
|
||||
<Switch onChange={setDeleteBeforeImport} checked={deleteBeforeImport} />
|
||||
<UploadForm
|
||||
multiple
|
||||
url={url}
|
||||
style={uploadFormStyle}
|
||||
onUploadSuccess={onUploadSuccess}
|
||||
|
Loading…
Reference in New Issue
Block a user