diff --git a/src/components/FileuploadApplicationSignedPdf/index.js b/src/components/FileuploadApplicationSignedPdf/index.js index ce13f37..54d362a 100644 --- a/src/components/FileuploadApplicationSignedPdf/index.js +++ b/src/components/FileuploadApplicationSignedPdf/index.js @@ -9,22 +9,22 @@ import { Button } from 'primereact/button'; // api import ApplicationService from '../../service/application-service'; -import { mimeTypes } from '../../configData'; +import { defaultMaxFileSize, mimeTypes } from '../../configData'; const FileuploadApplicationSignedPdf = ({ - fieldName, - setDataFn, - defaultValue = [], - accept = [], - maxSize = 100000000, - emptyText = __('Trascina qui il tuo file', 'gepafin'), - chooseLabel = __('Aggiungi documento', 'gepafin'), - uploadLabel = __('Salva documento', 'gepafin'), - cancelLabel = __('Cancella documento', 'gepafin'), - multiple = false, - applicationId = 0, - disabled = false - }) => { + fieldName, + setDataFn, + defaultValue = [], + accept = [], + maxSize = defaultMaxFileSize, + emptyText = __('Trascina qui il tuo file', 'gepafin'), + chooseLabel = __('Aggiungi documento', 'gepafin'), + uploadLabel = __('Salva documento', 'gepafin'), + cancelLabel = __('Cancella documento', 'gepafin'), + multiple = false, + applicationId = 0, + disabled = false + }) => { const [stateFieldData, setStateFieldData] = useState([]); const [acceptFormats, setAcceptFormats] = useState(''); const [formatsForInput, setFormatsForInput] = useState(''); @@ -145,19 +145,19 @@ const FileuploadApplicationSignedPdf = ({ useEffect(() => { const properMime = accept.map ? accept - .map(v => { - const found = head(mimeTypes.filter(o => o.code.includes(v))); - let res = v; + .map(v => { + const found = head(mimeTypes.filter(o => o.code.includes(v))); + let res = v; - if (found) { - res = found.code; - } + if (found) { + res = found.code; + } - return res; - }) : []; + return res; + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); - setFormatsForInput(properMime.join(',')) + setFormatsForInput(properMime.join(',')); }, [accept]); useEffect(() => { diff --git a/src/components/FileuploadDelega/index.js b/src/components/FileuploadDelega/index.js index ae1ce5b..b53f387 100644 --- a/src/components/FileuploadDelega/index.js +++ b/src/components/FileuploadDelega/index.js @@ -8,14 +8,14 @@ import { Button } from 'primereact/button'; // api import CompanyService from '../../service/company-service'; -import { mimeTypes } from '../../configData'; +import { defaultMaxFileSize, mimeTypes } from '../../configData'; const FileuploadDelega = ({ fieldName, setDataFn, defaultValue = [], accept = [], - maxSize = 100000000, + maxSize = defaultMaxFileSize, emptyText = __('Trascina qui il tuo file', 'gepafin'), chooseLabel = __('Aggiungi delega', 'gepafin'), uploadLabel = __('Salva documento', 'gepafin'), diff --git a/src/components/FormField/components/Fileupload/index.js b/src/components/FormField/components/Fileupload/index.js index fdd1f03..fe06a2e 100644 --- a/src/components/FormField/components/Fileupload/index.js +++ b/src/components/FormField/components/Fileupload/index.js @@ -14,7 +14,8 @@ import { FileUpload } from 'primereact/fileupload'; import { Tag } from 'primereact/tag'; import { Button } from 'primereact/button'; -import { mimeTypes } from '../../../../configData'; +import { defaultMaxFileSize, mimeTypes } from '../../../../configData'; +import getFormatedFileSizeText from '../../../../helpers/getFormatedFileSizeText'; const Fileupload = ({ fieldName, @@ -27,7 +28,7 @@ const Fileupload = ({ infoText = null, accept = ['image/*'], doctype = 'document', - maxSize = 100000000, + maxSize = defaultMaxFileSize, emptyText = __('Trascina qui il tuo file', 'gepafin'), chooseLabel = __('Aggiungi file', 'gepafin'), uploadLabel = __('Salva documento', 'gepafin'), @@ -162,19 +163,19 @@ const Fileupload = ({ useEffect(() => { const properMime = accept.map ? accept - .map(v => { - const found = head(mimeTypes.filter(o => o.code.includes(v))); - let res = v; + .map(v => { + const found = head(mimeTypes.filter(o => o.code.includes(v))); + let res = v; - if (found) { - res = found.code; - } + if (found) { + res = found.code; + } - return res; - }) : []; + return res; + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); - setFormatsForInput(properMime.join(',')) + setFormatsForInput(properMime.join(',')); }, [accept]); return ( @@ -184,6 +185,7 @@ const Fileupload = ({ {label}{config.required || config.isRequired ? * : null} {acceptFormats ? ' (' + getPropeMimeLabels(accept) + ')' : null} + {` (max ${getFormatedFileSizeText(maxSize)})`} {label}{config.required ? '*' : null} {acceptFormats ? ' (' + getPropeMimeLabels(accept) + ')' : null} + {` (max ${getFormatedFileSizeText(maxSize)})`} { + if (!+bytes) return '0 B' + + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + + const i = Math.floor(Math.log(bytes) / Math.log(k)) + + return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` +} + +export default getFormatedFileSizeText; \ No newline at end of file diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js index 922a509..9272991 100644 --- a/src/pages/BandoApplication/index.js +++ b/src/pages/BandoApplication/index.js @@ -35,6 +35,8 @@ import ApplicationSteps from './ApplicationSteps'; import BlockingOverlay from '../../components/BlockingOverlay'; import { Dialog } from 'primereact/dialog'; import FileuploadApplicationSignedPdf from '../../components/FileuploadApplicationSignedPdf'; +import getFormatedFileSizeText from '../../helpers/getFormatedFileSizeText'; +import { defaultMaxFileSize } from '../../configData'; const BandoApplication = () => { const { id } = useParams(); @@ -94,17 +96,9 @@ const BandoApplication = () => { const submitApplicationCallback = (data) => { if (data.status === 'SUCCESS') { - /*if (toast.current) { - toast.current.show({ - severity: 'success', - summary: '', - detail: __('La domanda รจ stata presentata!', 'gepafin') - }); - }*/ if (data.data.applicationStatus) { - setApplicationStatus(data.data.status); + setApplicationStatus(data.data.status); // ask why not 'applicationStatus'? } - setVisibleConfirmation(true); } storeSet.main.unsetAsyncRequest(); } @@ -380,6 +374,13 @@ const BandoApplication = () => { storeSet.main.unsetAsyncRequest(); } + const handleSetSignedDocumentFromFileupload = (fieldName, stateFieldData) => { + setSignedPdfFile(stateFieldData); + if (!isEmpty(stateFieldData)) { + setVisibleConfirmation(true); + } + } + useEffect(() => { if ('SUBMIT' === applicationStatus) { const applId = getApplicationId(); @@ -389,7 +390,7 @@ const BandoApplication = () => { ApplicationService.getApplicationSignedPdf(applId, getSignedPdfCallback, errSignedPdfCallbacks); } } - }, [applicationStatus]) + }, [applicationStatus]); useEffect(() => { if (formInitialData) { @@ -483,14 +484,6 @@ const BandoApplication = () => { return acc; }, {}); - /*if (o.name === 'table') { - validations.required = true; - validations.validate = { - nonEmptyTables: (v) => nonEmptyTables(v) - }; - }*/ - //console.log('validations', validations, o.name) - return ['paragraph'].includes(o.name) && text ?
{renderHtmlContent(text.value)}
: {
{
{!isNil(formName) ? formData.map(o => { - const label = head(o.settings.filter(o => o.name === 'label')); - const text = head(o.settings.filter(o => o.name === 'text')); - const placeholder = head(o.settings.filter(o => o.name === 'placeholder')); - const options = head(o.settings.filter(o => o.name === 'options')); - const tableColumns = head(o.settings.filter(o => o.name === 'table_columns')); - const step = head(o.settings.filter(o => o.name === 'step')); - const mime = head(o.settings.filter(o => o.name === 'mime')); - let mimeValue = ''; + const label = head(o.settings.filter(o => o.name === 'label')); + const text = head(o.settings.filter(o => o.name === 'text')); + const placeholder = head(o.settings.filter(o => o.name === 'placeholder')); + const options = head(o.settings.filter(o => o.name === 'options')); + const tableColumns = head(o.settings.filter(o => o.name === 'table_columns')); + const step = head(o.settings.filter(o => o.name === 'step')); + const mime = head(o.settings.filter(o => o.name === 'mime')); + let mimeValue = ''; - if (mime) { - mimeValue = mime.value.map(o => o.code).join(','); - } - - const validations = Object.keys(o.validators).reduce((acc, cur) => { - if (o.validators[cur]) { - if (['min', 'max', 'minLength', 'maxLength', 'maxSize'].includes(cur)) { - acc[cur] = parseInt(o.validators[cur]); - } else if ('pattern' === cur) { - acc[cur] = new RegExp(o.validators[cur]) - } else if ('isRequired' === cur) { - acc[cur] = o.validators[cur] - } else if ('custom' === cur && validationFns[o.validators[cur]]) { - if (!acc.validate) { - acc.validate = {} - } - acc.validate[cur] = validationFns[o.validators[cur]] - } + if (mime) { + mimeValue = mime.value.map(o => o.code ? o.code : o.ext); } - return acc; - }, {}); + const validations = Object.keys(o.validators).reduce((acc, cur) => { + if (o.validators[cur]) { + if (['min', 'max', 'minLength', 'maxLength', 'maxSize'].includes(cur)) { + acc[cur] = parseInt(o.validators[cur]); + } else if ('pattern' === cur) { + acc[cur] = new RegExp(o.validators[cur]) + } else if ('isRequired' === cur) { + acc[cur] = o.validators[cur] + } else if ('custom' === cur && validationFns[o.validators[cur]]) { + if (!acc.validate) { + acc.validate = {} + } + acc.validate[cur] = validationFns[o.validators[cur]] + } + } - //console.log('mime', mime) + return acc; + }, {}); - return ['paragraph'].includes(o.name) && text - ?
{renderHtmlContent(text.value)}
- : - }) : null} + return ['paragraph'].includes(o.name) && text + ?
{renderHtmlContent(text.value)}
+ : + }) : null}
diff --git a/src/pages/ProfileCompany/index.js b/src/pages/ProfileCompany/index.js index 3fdd8c9..56e3f41 100644 --- a/src/pages/ProfileCompany/index.js +++ b/src/pages/ProfileCompany/index.js @@ -23,6 +23,8 @@ import BlockingOverlay from '../../components/BlockingOverlay'; import { InputText } from 'primereact/inputtext'; import FileuploadDelega from '../../components/FileuploadDelega'; import { Toast } from 'primereact/toast'; +import getFormatedFileSizeText from '../../helpers/getFormatedFileSizeText'; +import { defaultMaxFileSize } from '../../configData'; const ProfileCompany = () => { const isAsyncRequest = useStore().main.isAsyncRequest(); @@ -461,7 +463,8 @@ const ProfileCompany = () => {