diff --git a/src/components/FileuploadApplicationSignedPdf/index.js b/src/components/FileuploadApplicationSignedPdf/index.js index 3cbccec..ce13f37 100644 --- a/src/components/FileuploadApplicationSignedPdf/index.js +++ b/src/components/FileuploadApplicationSignedPdf/index.js @@ -94,7 +94,6 @@ const FileuploadApplicationSignedPdf = ({ setStateFieldData(prevState => { const newFiles = prevState.filter(o => o.id !== id); inputRef.current.setUploadedFiles(newFiles); - console.log('dCallback - newFiles', newFiles) return newFiles; }); } @@ -144,7 +143,8 @@ const FileuploadApplicationSignedPdf = ({ }, [defaultValue]); useEffect(() => { - const properMime = accept + const properMime = accept.map + ? accept .map(v => { const found = head(mimeTypes.filter(o => o.code.includes(v))); let res = v; @@ -154,7 +154,7 @@ const FileuploadApplicationSignedPdf = ({ } return res; - }) + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); setFormatsForInput(properMime.join(',')) @@ -162,7 +162,7 @@ const FileuploadApplicationSignedPdf = ({ useEffect(() => { if (inputRef.current) { - inputRef.current.setUploadedFiles(stateFieldData); + inputRef.current.setUploadedFiles(stateFieldData ? stateFieldData : []); } setDataFn(fieldName, stateFieldData, { shouldValidate: true }); }, [stateFieldData]) diff --git a/src/components/FileuploadDelega/index.js b/src/components/FileuploadDelega/index.js index e53be51..ae1ce5b 100644 --- a/src/components/FileuploadDelega/index.js +++ b/src/components/FileuploadDelega/index.js @@ -143,7 +143,8 @@ const FileuploadDelega = ({ }, [defaultValue]); useEffect(() => { - const properMime = accept + const properMime = accept.map + ? accept .map(v => { const found = head(mimeTypes.filter(o => o.code.includes(v))); let res = v; @@ -153,7 +154,7 @@ const FileuploadDelega = ({ } return res; - }) + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); setFormatsForInput(properMime.join(',')) diff --git a/src/components/FormField/components/Fileupload/index.js b/src/components/FormField/components/Fileupload/index.js index 49a035e..fdd1f03 100644 --- a/src/components/FormField/components/Fileupload/index.js +++ b/src/components/FormField/components/Fileupload/index.js @@ -19,7 +19,6 @@ import { mimeTypes } from '../../../../configData'; const Fileupload = ({ fieldName, setDataFn, - control, label, errors, register, @@ -161,7 +160,8 @@ const Fileupload = ({ }, [defaultValue]); useEffect(() => { - const properMime = accept + const properMime = accept.map + ? accept .map(v => { const found = head(mimeTypes.filter(o => o.code.includes(v))); let res = v; @@ -171,7 +171,7 @@ const Fileupload = ({ } return res; - }) + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); setFormatsForInput(properMime.join(',')) diff --git a/src/components/FormField/components/FileuploadAsync/index.js b/src/components/FormField/components/FileuploadAsync/index.js index a9ad614..71164ba 100644 --- a/src/components/FormField/components/FileuploadAsync/index.js +++ b/src/components/FormField/components/FileuploadAsync/index.js @@ -161,7 +161,8 @@ const FileuploadAsync = ({ }, [defaultValue]); useEffect(() => { - const properMime = accept + const properMime = accept.map + ? accept .map(v => { const found = head(mimeTypes.filter(o => o.code.includes(v))); let res = v; @@ -171,7 +172,7 @@ const FileuploadAsync = ({ } return res; - }) + }) : []; // eslint-disable-next-line no-useless-escape setAcceptFormats(properMime.join(',').replace(/\*/g, '.\*').replace(/,/g, '|')); setFormatsForInput(properMime.join(',')) diff --git a/src/components/FormField/components/Table/index.js b/src/components/FormField/components/Table/index.js index db95ab6..d02badb 100644 --- a/src/components/FormField/components/Table/index.js +++ b/src/components/FormField/components/Table/index.js @@ -1,12 +1,15 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useCallback } from 'react'; import { classNames } from 'primereact/utils'; import { __ } from '@wordpress/i18n'; import { pathOr, isEmpty, isNil } from 'ramda'; import { wrap } from 'object-path-immutable'; +import equal from 'fast-deep-equal'; //components import { Button } from 'primereact/button'; import RenderTable from './RenderTable'; +import { klona } from 'klona'; +import { nonEmptyTables } from '../../../../helpers/validators'; const Table = ({ fieldName, @@ -21,7 +24,7 @@ const Table = ({ const [columnsCfg, setColumnsCfg] = useState([]); const [rowsCfg, setRowsCfg] = useState([]); const [columns, setColumns] = useState([]); - const [rows, setRows] = useState([]); + const [rows, setRows] = useState(null); const [shouldDisableNewRows, setShouldDisableNewRows] = useState(false); const [rowIndexToDelete, rowRowIndexToDelete] = useState(null); @@ -32,24 +35,33 @@ const Table = ({ return acc; }, {}); const newRowsData = [...rows, obj]; - setRows(newRowsData); - setDataFn(fieldName, newRowsData, { shouldValidate: true }); + updateRows(newRowsData); } const removeRow = (index) => { rowRowIndexToDelete(index); } - const updateRows = (data) => { + const updateRows = useCallback((data) => { setRows(data); setDataFn(fieldName, data, { shouldValidate: true }); + }, [rows, defaultValue]); + + const properConfig = (config) => { + let newConfig = klona(config); + if (config.validate && config.validate.nonEmptyTables) { + newConfig = wrap(newConfig) + .set(['validate', 'nonEmptyTables'], (v) => nonEmptyTables(v, tableColumns)) + .value(); + } + + return newConfig; } useEffect(() => { if (!isNil(rowIndexToDelete)) { const newRowsData = wrap(rows).del([rowIndexToDelete]).value(); - setRows(newRowsData); - setDataFn(fieldName, [...newRowsData], { shouldValidate: true }); + updateRows(newRowsData); } rowRowIndexToDelete(null); }, [rowIndexToDelete]); @@ -111,11 +123,14 @@ const Table = ({ }, [tableColumns]); useEffect(() => { - setRows(defaultValue) + if (!equal(rows, defaultValue)) { + setRows(defaultValue); + } }, [defaultValue]); useEffect(() => { - register(fieldName, config); + setRows(defaultValue); + register(fieldName, properConfig(config)); }, []); return ( @@ -123,7 +138,7 @@ const Table = ({ - + {rows ? : null} {!isEmpty(columns) && !shouldDisableNewRows ?
{__('Aggiungi una riga', 'gepafin')}
: null} diff --git a/src/helpers/validators.js b/src/helpers/validators.js index 5764928..3ccc929 100644 --- a/src/helpers/validators.js +++ b/src/helpers/validators.js @@ -65,4 +65,14 @@ export const minChecks = (v, num) => { export const maxChecks = (v, num) => { return is(Array, v) ? v.length <= parseInt(num) : false; +} + +export const nonEmptyTables = (v = [], colsCfg = []) => { + //console.log('nonEmptyTables',v) + /*const cellValues = v.map(row => { + + return isEmpty(row) + }); + console.log('cellValues', cellValues, colsCfg)*/ + return is(Array, v) ? v.length >= 1 : false; } \ No newline at end of file diff --git a/src/pages/AddCompany/index.js b/src/pages/AddCompany/index.js index 82af8ac..fe17fc5 100644 --- a/src/pages/AddCompany/index.js +++ b/src/pages/AddCompany/index.js @@ -147,7 +147,7 @@ const AddCompany = () => { return (
-

{__('Profilo aziendale', 'gepafin')}

+

{__('Agguingi azienda', 'gepafin')}

diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js index 1a0a631..80b58cc 100644 --- a/src/pages/BandoApplication/index.js +++ b/src/pages/BandoApplication/index.js @@ -20,7 +20,7 @@ import { isEmail, isEmailPEC, isUrl, - isMarcaDaBollo + isMarcaDaBollo, minChecks, maxChecks, nonEmptyTables } from '../../helpers/validators'; import renderHtmlContent from '../../helpers/renderHtmlContent'; import set404FromErrorResponse from '../../helpers/set404FromErrorResponse'; @@ -34,7 +34,7 @@ import { Messages } from 'primereact/messages'; import ApplicationSteps from './ApplicationSteps'; import BlockingOverlay from '../../components/BlockingOverlay'; import { Dialog } from 'primereact/dialog'; -//import FileuploadApplicationSignedPdf from '../../components/FileuploadApplicationSignedPdf'; +import FileuploadApplicationSignedPdf from '../../components/FileuploadApplicationSignedPdf'; const BandoApplication = () => { const { id } = useParams(); @@ -47,8 +47,7 @@ const BandoApplication = () => { const [visibleConfirmation, setVisibleConfirmation] = useState(false); const [applicationStatus, setApplicationStatus] = useState(''); const [activeStep, setActiveStep] = useState(1); - // TODO - //const [signedPdfFile, setSignedPdfFile] = useState([]); + const [signedPdfFile, setSignedPdfFile] = useState([]); const isAsyncRequest = useStore().main.isAsyncRequest(); const toast = useRef(null); const formMsgs = useRef(null); @@ -75,7 +74,10 @@ const BandoApplication = () => { isEmail, isEmailPEC, isUrl, - isMarcaDaBollo + isMarcaDaBollo, + minChecks, + maxChecks, + nonEmptyTables } const activeStepIndex = activeStep - 1; const values = getValues(); @@ -362,8 +364,32 @@ const BandoApplication = () => { const errPdfCallback = (data) => { set404FromErrorResponse(data); + storeSet.main.unsetAsyncRequest(); } + const getSignedPdfCallback = (data) => { + if (data.status === 'SUCCESS') { + setSignedPdfFile([data.data]); + } + storeSet.main.unsetAsyncRequest(); + } + + const errSignedPdfCallbacks = (data) => { + //set404FromErrorResponse(data); + storeSet.main.unsetAsyncRequest(); + } + + useEffect(() => { + if ('SUBMIT' === applicationStatus) { + const applId = getApplicationId(); + + if (applId) { + storeSet.main.setAsyncRequest(); + ApplicationService.getApplicationSignedPdf(applId, getSignedPdfCallback, errSignedPdfCallbacks); + } + } + }, [applicationStatus]) + useEffect(() => { if (formInitialData) { reset(); @@ -455,6 +481,13 @@ 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 @@ -498,18 +531,17 @@ const BandoApplication = () => { iconPos="right"/>
: null} - {/*{'SUBMIT' === applicationStatus + {'SUBMIT' === applicationStatus ?
{ />
- : null}*/} + : null}
diff --git a/src/pages/BandoEdit/components/BandoEditFormStep2/index.js b/src/pages/BandoEdit/components/BandoEditFormStep2/index.js index b4c1eaa..3727a14 100644 --- a/src/pages/BandoEdit/components/BandoEditFormStep2/index.js +++ b/src/pages/BandoEdit/components/BandoEditFormStep2/index.js @@ -213,7 +213,6 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, st } const acceptAllFormats = () => { - console.log(mimeTypes.map(o => o.code)) return mimeTypes.map(o => o.code); } diff --git a/src/pages/BandoFormsEdit/components/BuilderElementSettings/index.js b/src/pages/BandoFormsEdit/components/BuilderElementSettings/index.js index ec16fa0..7be02dc 100644 --- a/src/pages/BandoFormsEdit/components/BuilderElementSettings/index.js +++ b/src/pages/BandoFormsEdit/components/BuilderElementSettings/index.js @@ -14,6 +14,7 @@ import { TabView, TabPanel } from 'primereact/tabview'; import { InputSwitch } from 'primereact/inputswitch'; import ElementSetting from './components/ElementSetting'; import { Dropdown } from 'primereact/dropdown'; +import { maxChecks, minChecks } from '../../../../helpers/validators'; const BuilderElementSettings = ({ closeSettings }) => { const elements = useStore().main.formElements(); @@ -30,7 +31,10 @@ const BuilderElementSettings = ({ closeSettings }) => { { value: 'isEmail', label: 'isEmail' }, { value: 'isEmailPEC', label: 'isEmailPEC' }, { value: 'isUrl', label: 'isUrl' }, - { value: 'isMarcaDaBollo', label: 'isMarcaDaBollo' } + { value: 'isMarcaDaBollo', label: 'isMarcaDaBollo' }, + { value: 'minChecks', label: 'minChecks' }, + { value: 'maxChecks', label: 'maxChecks' }, + { value: 'nonEmptyTables', label: 'nonEmptyTables' } ] const onChange = (value, name) => { diff --git a/src/pages/BandoFormsEdit/index.js b/src/pages/BandoFormsEdit/index.js index 1233076..fdbaf3f 100644 --- a/src/pages/BandoFormsEdit/index.js +++ b/src/pages/BandoFormsEdit/index.js @@ -23,7 +23,7 @@ import FormsService from '../../service/forms-service'; import set404FromErrorResponse from '../../helpers/set404FromErrorResponse'; // TODO temp data -//import { elementItems } from '../../tempData'; +import { elementItems } from '../../tempData'; const BandoFormsEdit = () => { const { id, formId } = useParams(); @@ -215,8 +215,8 @@ const BandoFormsEdit = () => { const getElementItemsCallback = (data) => { if (data.status === 'SUCCESS') { - //storeSet.main.elementItems(elementItems.sort((a, b) => a.sortOrder - b.sortOrder)); - storeSet.main.elementItems(data.data.sort((a, b) => a.sortOrder - b.sortOrder)); + storeSet.main.elementItems(elementItems.sort((a, b) => a.sortOrder - b.sortOrder)); + //storeSet.main.elementItems(data.data.sort((a, b) => a.sortOrder - b.sortOrder)); } storeSet.main.unsetAsyncRequest(); } diff --git a/src/pages/BandoFormsPreview/index.js b/src/pages/BandoFormsPreview/index.js index be57da4..f722435 100644 --- a/src/pages/BandoFormsPreview/index.js +++ b/src/pages/BandoFormsPreview/index.js @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { __ } from '@wordpress/i18n'; import { useNavigate, useParams } from 'react-router-dom'; import { klona } from 'klona'; -import { head } from 'ramda'; +import { head, isNil } from 'ramda'; import { useForm } from 'react-hook-form'; // store @@ -26,7 +26,7 @@ import { isIBAN, isMarcaDaBollo, isPIVA, - isUrl + isUrl, minChecks, maxChecks, nonEmptyTables } from '../../helpers/validators'; import renderHtmlContent from '../../helpers/renderHtmlContent'; @@ -53,7 +53,10 @@ const BandoFormsPreview = () => { isEmail, isEmailPEC, isUrl, - isMarcaDaBollo + isMarcaDaBollo, + minChecks, + maxChecks, + nonEmptyTables } const onSubmit = () => { @@ -93,7 +96,7 @@ const BandoFormsPreview = () => { return (
- {!isAsyncRequest + {!isAsyncRequest && !isNil(formName) ?

{formName}

@@ -116,7 +119,8 @@ const BandoFormsPreview = () => {
- {formData.map(o => { + {!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')); @@ -149,6 +153,8 @@ const BandoFormsPreview = () => { return acc; }, {}); + //console.log('validations', validations, o.name) + return ['paragraph'].includes(o.name) && text ?
{renderHtmlContent(text.value)}
: { control={control} register={register} errors={errors} - defaultValue={values[o.id]} + defaultValue={values[o.id] ? values[o.id] : ''} maxFractionDigits={step ? step.value : 0} accept={mimeValue} config={validations} @@ -170,7 +176,7 @@ const BandoFormsPreview = () => { useGrouping={false} tableColumns={tableColumns ? tableColumns.value : {}} /> - })} + }) : null}
diff --git a/src/pages/BandoViewBeneficiario/index.js b/src/pages/BandoViewBeneficiario/index.js index 0526cce..a832190 100644 --- a/src/pages/BandoViewBeneficiario/index.js +++ b/src/pages/BandoViewBeneficiario/index.js @@ -12,6 +12,11 @@ import getDateFromISOstring from '../../helpers/getDateFromISOstring'; import set404FromErrorResponse from '../../helpers/set404FromErrorResponse'; import renderHtmlContent from '../../helpers/renderHtmlContent'; +// api +import BandoService from '../../service/bando-service'; +import FaqItemService from '../../service/faq-item-service'; +import ApplicationService from '../../service/application-service'; + // components import { Skeleton } from 'primereact/skeleton'; import { Accordion } from 'primereact/accordion'; @@ -20,11 +25,6 @@ import { Button } from 'primereact/button'; import { Messages } from 'primereact/messages'; import { Message } from 'primereact/message'; import { Toast } from 'primereact/toast'; - -// api -import BandoService from '../../service/bando-service'; -import FaqItemService from '../../service/faq-item-service'; -import ApplicationService from '../../service/application-service'; import { Editor } from 'primereact/editor'; const BandoViewBeneficiario = () => { @@ -38,12 +38,37 @@ const BandoViewBeneficiario = () => { const bandoMsgs = useRef(null); const toast = useRef(null); - const scaricaBando = () => { + /*const scaricaBando = () => { - } + }*/ const scaricaModulistica = () => { + const bandoId = getBandoId(); + BandoService.getBandoPdf(bandoId, getCallPdfCallback, errCallPdfCallback); + } + const getCallPdfCallback = (data) => { + const bandoId = getBandoId(); + const pdfFile = new Blob([data], { type: 'application/zip' }) + const url = window.URL.createObjectURL(pdfFile); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', `modulistica-bando-${bandoId}.zip`); + document.body.appendChild(link); + link.click(); + link.remove(); + storeSet.main.unsetAsyncRequest(); + } + + const errCallPdfCallback = (data) => { + if (toast.current) { + toast.current.show({ + severity: 'error', + summary: '', + detail: data.message + }); + } + storeSet.main.unsetAsyncRequest(); } const getBandoId = () => { @@ -56,7 +81,7 @@ const BandoViewBeneficiario = () => { navigate(`/imieibandi/${applicationObj.id}`); } else { const bandoId = getBandoId(); - ApplicationService.createApplication(bandoId, {}, createApplCallback, errCreateApplCallback, [['companyId', chosenCompanyId]]) + ApplicationService.createApplication(bandoId, {}, createApplCallback, errCreateApplCallback, [['companyId', chosenCompanyId]]); } } @@ -352,19 +377,18 @@ const BandoViewBeneficiario = () => {

{__('Download Documenti', 'gepafin')}

-