- updated code related to files validation;
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty } from 'ramda';
|
||||
import { head, isEmpty } from 'ramda';
|
||||
|
||||
import { FileUpload } from 'primereact/fileupload';
|
||||
import { Tag } from 'primereact/tag';
|
||||
@@ -8,6 +8,7 @@ import { Button } from 'primereact/button';
|
||||
|
||||
// api
|
||||
import CompanyService from '../../service/company-service';
|
||||
import { mimeTypes } from '../../configData';
|
||||
|
||||
const FileuploadDelega = ({
|
||||
fieldName,
|
||||
@@ -25,6 +26,7 @@ const FileuploadDelega = ({
|
||||
}) => {
|
||||
const [stateFieldData, setStateFieldData] = useState([]);
|
||||
const [acceptFormats, setAcceptFormats] = useState('');
|
||||
const [formatsForInput, setFormatsForInput] = useState('');
|
||||
const inputRef = useRef();
|
||||
|
||||
const customBase64Uploader = (event) => {
|
||||
@@ -141,8 +143,20 @@ const FileuploadDelega = ({
|
||||
}, [defaultValue]);
|
||||
|
||||
useEffect(() => {
|
||||
const properMime = accept
|
||||
.map(v => {
|
||||
const found = head(mimeTypes.filter(o => o.code.includes(v)));
|
||||
let res = v;
|
||||
|
||||
if (found) {
|
||||
res = found.code;
|
||||
}
|
||||
|
||||
return res;
|
||||
})
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
setAcceptFormats(accept.join(',').replace(/\*/g, '.\*').replace(/,/g, '|'));
|
||||
setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|'));
|
||||
setFormatsForInput(properMime.join(','))
|
||||
}, [accept]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -161,7 +175,7 @@ const FileuploadDelega = ({
|
||||
name={fieldName}
|
||||
url={'/document/uploadFile'}
|
||||
multiple={multiple}
|
||||
accept={accept}
|
||||
accept={formatsForInput}
|
||||
maxFileSize={maxSize}
|
||||
emptyTemplate={<p>{emptyText}</p>}
|
||||
chooseLabel={chooseLabel}
|
||||
|
||||
Reference in New Issue
Block a user