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