- saving progress;
This commit is contained in:
@@ -1,121 +1,91 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, pluck } from 'ramda';
|
||||
|
||||
// components
|
||||
import { ListBox } from 'primereact/listbox';
|
||||
import { Button } from 'primereact/button';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import CompanyDocumentsService from '../../../../service/company-documents-service';
|
||||
|
||||
const FileSelect = ({
|
||||
fieldName,
|
||||
label,
|
||||
setDataFn,
|
||||
register,
|
||||
errors,
|
||||
defaultValue,
|
||||
config = {},
|
||||
infoText = null,
|
||||
disabled = false,
|
||||
options = []
|
||||
options = [],
|
||||
sourceId = 0,
|
||||
source = 'DOCUMENT',
|
||||
saveFormCallback
|
||||
}) => {
|
||||
const [stateFieldData, setStateFieldData] = useState([]);
|
||||
const [selectedUnconfirmed, setSelectedUnconfirmed] = useState(null);
|
||||
const cities = [
|
||||
{
|
||||
label: 'Company files',
|
||||
code: 'company-files',
|
||||
items: [
|
||||
{
|
||||
'id': 589,
|
||||
'name': 'pdf-3-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
},
|
||||
{
|
||||
'id': 569,
|
||||
'name': 'pdf-2-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
},
|
||||
{
|
||||
'id': 519,
|
||||
'name': 'pdf-1-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Personal files',
|
||||
code: 'personal-files',
|
||||
items: [
|
||||
{
|
||||
'id': 179,
|
||||
'name': 'pdf-13-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
},
|
||||
{
|
||||
'id': 169,
|
||||
'name': 'pdf-12-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
},
|
||||
{
|
||||
'id': 129,
|
||||
'name': 'pdf-11-test.pdf',
|
||||
'filePath': 'https://mementoresources.s3.eu-west-1.amazonaws.com/gepafin/staging/call/%2Fapplication/%2Fpdf-1-test_8432561.pdf',
|
||||
'type': 'DOCUMENT',
|
||||
'source': 'APPLICATION',
|
||||
'sourceId': 0,
|
||||
'createdDate': '2025-02-21T15:33:52.767089176',
|
||||
'updatedDate': '2025-02-21T15:33:52.767109885',
|
||||
'documentAttachmentId': null
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
//const [stateFieldData, setStateFieldData] = useState([]);
|
||||
const stateFieldData = useRef([]);
|
||||
const [selectedUnconfirmed, setSelectedUnconfirmed] = useState([]);
|
||||
const [optionsTransformed, setOptionsTransformed] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const attachSelectedFiles = useCallback(() => {
|
||||
setStateFieldData([...stateFieldData, ...selectedUnconfirmed]);
|
||||
const existingIds = pluck('id', stateFieldData.current);
|
||||
const selectedToBeAdded = selectedUnconfirmed.filter(o => !existingIds.includes(o.id));
|
||||
setSelectedUnconfirmed([]);
|
||||
}, [selectedUnconfirmed, stateFieldData])
|
||||
|
||||
setLoading(true);
|
||||
selectedToBeAdded.map(o => {
|
||||
CompanyDocumentsService.attachCompanyDocumentToAppl(o.id, callback, errCallback, [
|
||||
['applicationId', sourceId],
|
||||
['documentType', source]
|
||||
])
|
||||
});
|
||||
}, [selectedUnconfirmed]);
|
||||
|
||||
const callback = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
stateFieldData.current = [...stateFieldData.current, resp.data];
|
||||
setDataFn(fieldName, stateFieldData.current, { shouldValidate: true });
|
||||
saveFormCallback();
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
const errCallback = () => {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
console.log('selectedUnconfirmed', selectedUnconfirmed)
|
||||
}, [selectedUnconfirmed]);
|
||||
|
||||
useEffect(() => {
|
||||
setStateFieldData(defaultValue);
|
||||
stateFieldData.current = defaultValue;
|
||||
register(fieldName, config)
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setStateFieldData(defaultValue);
|
||||
if (!isEmpty(options)) {
|
||||
const optionsDefault = [
|
||||
{
|
||||
label: __('Documenti dell\'Azienda', 'gepafin'),
|
||||
code: 'COMPANY_DOCUMENT',
|
||||
items: options.filter(o => o.type === 'COMPANY_DOCUMENT')
|
||||
},
|
||||
{
|
||||
label: __('Documenti del Rappresentante Legale', 'gepafin'),
|
||||
code: 'PERSONAL_DOCUMENT',
|
||||
items: options.filter(o => o.type === 'PERSONAL_DOCUMENT')
|
||||
}
|
||||
];
|
||||
setOptionsTransformed(optionsDefault);
|
||||
}
|
||||
}, [options]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('defaultValue', defaultValue);
|
||||
stateFieldData.current = defaultValue;
|
||||
}, [defaultValue]);
|
||||
|
||||
return (
|
||||
@@ -129,7 +99,7 @@ const FileSelect = ({
|
||||
<ListBox multiple
|
||||
value={selectedUnconfirmed}
|
||||
onChange={(e) => setSelectedUnconfirmed(e.value)}
|
||||
options={cities}
|
||||
options={optionsTransformed}
|
||||
optionLabel="name"
|
||||
optionGroupLabel="label"
|
||||
optionGroupChildren="items"
|
||||
@@ -137,6 +107,7 @@ const FileSelect = ({
|
||||
listStyle={{ maxHeight: '130px' }}/>
|
||||
<Button
|
||||
severity="success"
|
||||
disabled={loading}
|
||||
onClick={attachSelectedFiles}
|
||||
label={__('Conferma i file scelti', 'gepafin')}
|
||||
icon="pi pi-arrow-right" size="small" iconPos="right"/>
|
||||
@@ -144,7 +115,7 @@ const FileSelect = ({
|
||||
<div className="fileselectInner__selectedFiles">
|
||||
<p>{__('Selezionati')}</p>
|
||||
<ul>
|
||||
{[...stateFieldData].map(o => <li key={o.id}>
|
||||
{[...stateFieldData.current].map(o => <li key={o.id}>
|
||||
{o.name}
|
||||
</li>)}
|
||||
</ul>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||
import React, { useState, useEffect, useRef, useMemo, useCallback } from 'react';
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { head, is, pluck, isEmpty, pathOr, isNil } from 'ramda';
|
||||
import { head, is, pluck, isEmpty, pathOr, isNil, uniq, uniqBy } from 'ramda';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import 'quill/dist/quill.core.css';
|
||||
import { wrap } from 'object-path-immutable';
|
||||
@@ -47,6 +47,7 @@ import FileuploadApplicationSignedPdf from '../../components/FileuploadApplicati
|
||||
|
||||
import { defaultMaxFileSize } from '../../configData';
|
||||
import parseCommaDecimal from '../../helpers/parseCommaDecimal';
|
||||
import CompanyDocumentsService from '../../service/company-documents-service';
|
||||
|
||||
const BandoApplication = () => {
|
||||
const chosenCompanyId = useStore().main.chosenCompanyId();
|
||||
@@ -62,6 +63,8 @@ const BandoApplication = () => {
|
||||
const [applicationStatus, setApplicationStatus] = useState('');
|
||||
const [activeStep, setActiveStep] = useState(1);
|
||||
const [signedPdfFile, setSignedPdfFile] = useState([]);
|
||||
const [companyDocs, setCompanyDocs] = useState([]);
|
||||
const [personalDocs, setPersonalDocs] = useState([]);
|
||||
const [isRequestForApplData, setIsRequestForApplData] = useState(false);
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const previousStatus = useRef('');
|
||||
@@ -217,7 +220,7 @@ const BandoApplication = () => {
|
||||
}
|
||||
|
||||
fieldVal = isEmpty(fieldVal) ? null : fieldVal;
|
||||
if (formField && formField.name === 'fileupload') {
|
||||
if (formField && ['fileupload', 'fileselect'].includes(formField.name)) {
|
||||
fieldVal = is(Array, fieldVal) ? fieldVal.map(o => o.id).join(',') : null;
|
||||
}
|
||||
acc.push({
|
||||
@@ -540,6 +543,27 @@ const BandoApplication = () => {
|
||||
? ['.p7m', '.pdf']
|
||||
: ['.p7m'];
|
||||
|
||||
const getDocsCallback = (resp, type) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
if (type === 'PERSONAL_DOCUMENT') {
|
||||
setPersonalDocs(uniqBy((o) => o.id, getFormattedDocsData(resp.data)));
|
||||
} else {
|
||||
setCompanyDocs(uniqBy((o) => o.id, getFormattedDocsData(resp.data)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const errDocsGetCallbacks = () => {
|
||||
}
|
||||
|
||||
const getFormattedDocsData = (data) => {
|
||||
return data.map((d) => {
|
||||
d.callEndDate = is(String, d.callEndDate) ? new Date(d.callEndDate) : (d.callEndDate ? d.callEndDate : '');
|
||||
return d;
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let updatedFormValues = klona(formValues);
|
||||
let context = {};
|
||||
@@ -628,6 +652,12 @@ const BandoApplication = () => {
|
||||
ApplicationService.getApplicationForm(applId, getApplFormCallback, errGetApplFormCallbacks, [
|
||||
['companyId', chosenCompanyId]
|
||||
]);
|
||||
CompanyDocumentsService.getCompanyDocuments(chosenCompanyId, (resp) => getDocsCallback(resp, 'COMPANY_DOCUMENT'), errDocsGetCallbacks, [
|
||||
['documentType', 'COMPANY_DOCUMENT']
|
||||
]);
|
||||
CompanyDocumentsService.getCompanyDocuments(chosenCompanyId, (resp) => getDocsCallback(resp, 'PERSONAL_DOCUMENT'), errDocsGetCallbacks, [
|
||||
['documentType', 'PERSONAL_DOCUMENT']
|
||||
]);
|
||||
}
|
||||
}, [id, chosenCompanyId]);
|
||||
|
||||
@@ -684,7 +714,9 @@ const BandoApplication = () => {
|
||||
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 options = ['fileselect'].includes(o.name)
|
||||
? {value: [...companyDocs, ...personalDocs]}
|
||||
: head(o.settings.filter(o => o.name === 'options'));
|
||||
let tableColumns = head(o.settings.filter(o => o.name === 'table_columns'));
|
||||
if (!tableColumns) {
|
||||
tableColumns = head(o.settings.filter(o => o.name === 'criteria_table_columns'));
|
||||
@@ -718,9 +750,9 @@ const BandoApplication = () => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
/*if (o.name === 'table') {
|
||||
console.log('value:', values[o.id] ? values[o.id] : '')
|
||||
}*/
|
||||
if (o.name === 'fileselect') {
|
||||
console.log('options::', options)
|
||||
}
|
||||
|
||||
return ['paragraph'].includes(o.name) && text
|
||||
? <div key={o.id}>
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { useDrag, useDrop } from 'react-dnd'
|
||||
import { ItemTypes } from '../ItemTypes';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { head, isEmpty } from 'ramda';
|
||||
import { head, isEmpty, pathOr } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// store
|
||||
@@ -22,6 +22,7 @@ const BuilderElement = ({ id, name, label, index, bandoStatus }) => {
|
||||
const ref = useRef(null);
|
||||
const elements = useStore().main.formElements();
|
||||
const element = head(elements.filter(o => o.id === id));
|
||||
const elementSettings = pathOr([], ['settings'], element);
|
||||
const [isVariable, setIsVariable] = useState('secondary');
|
||||
const [isFormula, setIsFormula] = useState('secondary');
|
||||
const [variableName, setVariableName] = useState('secondary');
|
||||
@@ -134,10 +135,10 @@ const BuilderElement = ({ id, name, label, index, bandoStatus }) => {
|
||||
drag(drop(ref));
|
||||
|
||||
useEffect(() => {
|
||||
const variable = head(element.settings.filter(o => o.name === 'variable'));
|
||||
const formula = head(element.settings.filter(o => o.name === 'formula'));
|
||||
const isRequestedAmount = head(element.settings.filter(o => o.name === 'isRequestedAmount'));
|
||||
const isDelegation = head(element.settings.filter(o => o.name === 'isDelegation'));
|
||||
const variable = head(elementSettings.filter(o => o.name === 'variable'));
|
||||
const formula = head(elementSettings.filter(o => o.name === 'formula'));
|
||||
const isRequestedAmount = head(elementSettings.filter(o => o.name === 'isRequestedAmount'));
|
||||
const isDelegation = head(elementSettings.filter(o => o.name === 'isDelegation'));
|
||||
|
||||
if (variable && !isEmpty(variable.value)) {
|
||||
setIsVariable('warning');
|
||||
@@ -151,12 +152,16 @@ const BuilderElement = ({ id, name, label, index, bandoStatus }) => {
|
||||
|
||||
if (isRequestedAmount && !isEmpty(isRequestedAmount.value) && isRequestedAmount.value) {
|
||||
setIsRequestedAmount('tertiary');
|
||||
} else {
|
||||
setIsRequestedAmount(false);
|
||||
}
|
||||
|
||||
if (isDelegation && !isEmpty(isDelegation.value) && isDelegation.value) {
|
||||
setIsDelegation('tertiary');
|
||||
} else {
|
||||
setIsDelegation(false);
|
||||
}
|
||||
}, [elements]);
|
||||
}, [elementSettings]);
|
||||
|
||||
return (
|
||||
draggingElementId === id
|
||||
|
||||
@@ -12,6 +12,10 @@ export default class CompanyDocumentsService {
|
||||
NetworkService.postMultiPart(`${API_BASE_URL}/companyDocument/company/${id}/upload`, body, callback, errCallback, queryParams);
|
||||
};
|
||||
|
||||
static attachCompanyDocumentToAppl = (id, callback, errCallback, queryParams) => {
|
||||
NetworkService.put(`${API_BASE_URL}/companyDocument/${id}/document/upload`, {}, callback, errCallback, queryParams);
|
||||
};
|
||||
|
||||
static deleteCompanyDocument = (id, callback, errCallback) => {
|
||||
NetworkService.delete(`${API_BASE_URL}/companyDocument`, {}, callback, errCallback, [
|
||||
['id', id]
|
||||
|
||||
Reference in New Issue
Block a user