diff --git a/src/assets/scss/components/fieldsRepeater.scss b/src/assets/scss/components/fieldsRepeater.scss index 2a28eda..dd4b4ba 100644 --- a/src/assets/scss/components/fieldsRepeater.scss +++ b/src/assets/scss/components/fieldsRepeater.scss @@ -2,12 +2,13 @@ display: flex; flex-direction: column; align-items: flex-start; - gap: 30px; + gap: 10px; width: 100%; } .fieldsRepeater form { display: contents; + } .fieldsRepeater__panel { @@ -18,6 +19,16 @@ align-items: center; display: flex; justify-content: space-between; + + > span { + width: 100%; + height: 100%; + + &:hover { + cursor: pointer; + color: var(--menuitem-active-background); + } + } } .fieldsRepeater__fields { diff --git a/src/pages/DomandaEditPreInstructor/components/RepeaterFields/index.js b/src/pages/DomandaEditPreInstructor/components/RepeaterFields/index.js index 384e4dc..a28d452 100644 --- a/src/pages/DomandaEditPreInstructor/components/RepeaterFields/index.js +++ b/src/pages/DomandaEditPreInstructor/components/RepeaterFields/index.js @@ -1,7 +1,6 @@ -import React, { useMemo, useState, useEffect } from 'react'; -import { klona } from 'klona'; +import React, { useMemo, useState, useEffect, useCallback } from 'react'; import { useForm } from 'react-hook-form'; -import { isEmpty } from 'ramda'; +import { isEmpty, head } from 'ramda'; import { __ } from '@wordpress/i18n'; // tools @@ -11,7 +10,12 @@ import uniqid from '../../../../helpers/uniqid'; import FormField from '../../../../components/FormField'; import { Button } from 'primereact/button'; -const RepeaterFields = ({ sourceId, sourceName }) => { +const RepeaterFields = ({ + sourceId, + sourceName, + updateFn = () => {}, + defaultValue = [] +}) => { const [items, setItems] = useState([]); const [chosen, setChosen] = useState(''); const [formInitialData, setFormInitialData] = useState({}); @@ -22,7 +26,7 @@ const RepeaterFields = ({ sourceId, sourceName }) => { setValue, register, trigger, - getValues, + reset, watch } = useForm({ defaultValues: useMemo(() => { @@ -35,32 +39,49 @@ const RepeaterFields = ({ sourceId, sourceName }) => { const onSubmit = () => { }; - const doUpdateAmendment = () => { + const doUpdateAfterFileUploaded = () => { trigger(); - let formValues = klona(getValues()); - console.log('formValues', formValues); } - const addNew = () => { + const addNew = useCallback(() => { setValue('nameValue', ''); - setValue('fileValue', {}); + setValue('fileValue', []); trigger(); const uid = uniqid('f'); const newItem = { fieldId: uid, - name: '', - file: {}, + nameValue: '', + fileValue: [], + valid: true } setItems([...items, newItem]); setChosen(uid); trigger(); - } + }, [items]); + + const setNewChosen = useCallback((id) => { + const chosenObj = head(items.filter(o => id === o.fieldId)); + setChosen(chosen === id ? '' : id); + reset(); + if (chosenObj) { + setValue('nameValue', chosenObj.nameValue); + setValue('fileValue', chosenObj.fileValue); + } + }, [items]); + + const removeItem = useCallback((id) => { + setItems([...items.filter(o => id !== o.fieldId)]); + if (chosen === id) { + setChosen(''); + reset(); + } + }, [items, chosen]); useEffect(() => { const updatedItems = items.map((o) => { return o.fieldId === chosen ? { ...o, - name: watchName + nameValue: watchName } : o; }) setItems([...updatedItems]); @@ -70,29 +91,35 @@ const RepeaterFields = ({ sourceId, sourceName }) => { const updatedItems = items.map((o) => { return o.fieldId === chosen ? { ...o, - file: watchFile + fileValue: watchFile } : o; }) setItems([...updatedItems]); }, [watchFile]); useEffect(() => { - console.log('items', items); + updateFn(items); }, [items]); - //console.log('items', items, chosen); + useEffect(() => { + setItems(defaultValue); + }, []) + + console.log('items', items, chosen); return (
{items ? items.map(o =>
- {o.name} -
{chosen === o.fieldId ?
@@ -102,23 +129,25 @@ const RepeaterFields = ({ sourceId, sourceName }) => { label={__('Titolo del file', 'gepafin')} control={control} errors={errors} - defaultValue={formInitialData['nameValue']} + defaultValue={o.nameValue} config={{ required: __('È obbligatorio', 'gepafin') }} />
: null}
@@ -126,10 +155,11 @@ const RepeaterFields = ({ sourceId, sourceName }) => {
) diff --git a/src/pages/DomandaEditPreInstructor/index.js b/src/pages/DomandaEditPreInstructor/index.js index c76469a..a2e444d 100644 --- a/src/pages/DomandaEditPreInstructor/index.js +++ b/src/pages/DomandaEditPreInstructor/index.js @@ -158,6 +158,12 @@ const DomandaEditPreInstructor = () => { criteria: klona(data.criteria), checklist: klona(data.checklist), files: klona(data.files), + evaluationDocument: klona(data.evaluationDocument.map(o => ({ + ...o, + fileValue: o.fileValue[0] ? o.fileValue[0].id : '' + }) + )), + amendmentDetails: klona(data.amendmentDetails), note: data.note } @@ -540,7 +546,14 @@ const DomandaEditPreInstructor = () => {

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

- + updateEvaluationValue( + data, + ['evaluationDocument'] + )} + sourceId={data.assignedApplicationId} + sourceName="evaluation"/>
diff --git a/src/pages/SoccorsoAddPreInstructor/index.js b/src/pages/SoccorsoAddPreInstructor/index.js index 754f643..bfb4745 100644 --- a/src/pages/SoccorsoAddPreInstructor/index.js +++ b/src/pages/SoccorsoAddPreInstructor/index.js @@ -193,7 +193,7 @@ const SoccorsoAddPreInstructor = () => {
-

{__('Note', 'gepafin')}

+

{__('Pec/Email', 'gepafin')}

{ const header = renderHeader(); const updateNewAmendmentData = (value, path) => { - const newData = wrap(data).set(path.split('.'), value).value(); + const newData = wrap(data).set(path, value).value(); setData(newData); } @@ -136,10 +136,22 @@ const SoccorsoEditPreInstructor = () => { }); return acc; }, []); + const newAmendDocs = data.amendmentDocuments + .reduce((acc, cur) => { + const newObj = { + ...klona(cur), + fileValue: cur.fileValue[0] ? cur.fileValue[0].id : '' + } + + acc.push(newObj); + return acc; + }, []); const submitData = { - applicationFormFields: newFormValues + applicationFormFields: newFormValues, + amendmentDocuments: newAmendDocs } + storeSet.main.setAsyncRequest(); AmendmentsService.updateSoccorso(amendmentId, submitData, updateAmendmentCallback, errUpdateAmendmentCallback); } @@ -177,6 +189,7 @@ const SoccorsoEditPreInstructor = () => { } const doCloseAmendment = () => { + doUpdateAmendment(); const submitData = { internalNote: data.internalNote } @@ -194,7 +207,7 @@ const SoccorsoEditPreInstructor = () => { }); } if (data.data.status) { - updateNewAmendmentData(data.data.status, 'status') + updateNewAmendmentData(data.data.status, ['status']) } } storeSet.main.unsetAsyncRequest(); @@ -311,6 +324,10 @@ const SoccorsoEditPreInstructor = () => { AmendmentsService.getSoccorsoById(getCallback, errGetCallback, [['id', soccorsoEntityId]]); }, [amendmentId]); + useEffect(() => { + console.log(data); + }, [data]); + return (
@@ -389,17 +406,12 @@ const SoccorsoEditPreInstructor = () => {
-
-

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

- -
+ {data.formFields && !isEmpty(data.formFields) + ?
+

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

-
-

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

- -
- {data.formFields - ? data.formFields.map((o, i) => { + + {data.formFields.map((o, i) => { return { sourceId={data.applicationId} multiple={true} /> - }) : null} - + })} + +
: null} + +
+

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

+ updateNewAmendmentData( + data, + ['amendmentDocuments'] + )} + sourceId={amendmentId} + sourceName="AMENDMENT"/>
@@ -432,7 +456,7 @@ const SoccorsoEditPreInstructor = () => { headerTemplate={header} onTextChange={(e) => updateNewAmendmentData( e.htmlValue, - 'internalNote' + ['internalNote'] )} style={{ height: 80 * 3, width: '100%' }} />