- fixed displaying tables;
- fixed uploading signed pdf for application; - added downloading modullistica archive; - added basic table related validator;
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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(','))
|
||||
|
||||
@@ -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(','))
|
||||
|
||||
@@ -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(','))
|
||||
|
||||
@@ -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 = ({
|
||||
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
|
||||
{label}{config.required || config.isRequired ? <span className="appForm__field--required">*</span> : null}
|
||||
</label>
|
||||
<RenderTable columns={columns} data={rows} setRowsFn={updateRows}/>
|
||||
{rows ? <RenderTable columns={columns} data={rows} setRowsFn={updateRows}/> : null}
|
||||
{!isEmpty(columns) && !shouldDisableNewRows
|
||||
? <div className="addNewTableRow" onClick={addNewRow}>{__('Aggiungi una riga', 'gepafin')}</div>
|
||||
: null}
|
||||
|
||||
Reference in New Issue
Block a user