updates
This commit is contained in:
@@ -3,6 +3,7 @@ import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { isEmpty, isNil, is } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// components
|
||||
import FormField from '../../../../components/FormField';
|
||||
@@ -12,6 +13,8 @@ import BandoEditFormActions from '../BandoEditFormActions';
|
||||
import UnsavedChangesDetector from '../../../../components/UnsavedChangesDetector';
|
||||
import BandoService from '../../../../service/bando-service';
|
||||
import LookupdataService from '../../../../service/lookupdata-service';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore } from '../../../../store';
|
||||
|
||||
const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors }, ref) {
|
||||
@@ -126,7 +129,11 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}, [initialData]);
|
||||
|
||||
useEffect(() => {
|
||||
reset(formInitialData);
|
||||
const newFormData = klona(formInitialData);
|
||||
if (!isNil(formInitialData.dates) && formInitialData.dates.length) {
|
||||
newFormData.dates = formInitialData.dates.map(v => is(String, v) ? new Date(v) : (v ? v : ''));
|
||||
}
|
||||
reset(newFormData);
|
||||
}, [formInitialData]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -259,7 +266,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors },
|
||||
</div>
|
||||
|
||||
<FormFieldRepeaterFaq
|
||||
data={values}
|
||||
data={values['faq']}
|
||||
setDataFn={setValue}
|
||||
fieldName="faq"
|
||||
options={faqOptions}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { is, isEmpty, isNil } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// components
|
||||
import FormField from '../../../../components/FormField';
|
||||
@@ -121,7 +122,11 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}, [initialData]);
|
||||
|
||||
useEffect(() => {
|
||||
reset(formInitialData);
|
||||
const newFormData = klona(formInitialData);
|
||||
if (!isNil(formInitialData.dates) && formInitialData.dates.length) {
|
||||
newFormData.dates = formInitialData.dates.map(v => is(String, v) ? new Date(v) : (v ? v : ''));
|
||||
}
|
||||
reset(newFormData);
|
||||
}, [formInitialData]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -308,7 +308,7 @@ const BandoEdit = () => {
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Publicca il Form', 'gepafin')}</h2>
|
||||
|
||||
<div className="appPageSection__actions">
|
||||
<div className="row">
|
||||
<Button
|
||||
type="button"
|
||||
outlined
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { isEmpty } from 'ramda';
|
||||
import { classNames } from 'primereact/utils';
|
||||
|
||||
// components
|
||||
import { Button } from 'primereact/button';
|
||||
@@ -114,7 +115,7 @@ const BandoForms = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection__withBorder">
|
||||
<div className={classNames(["appPageSection__withBorder", (isEmpty(forms) ? 'disabled' : '')])}>
|
||||
<h2>{__('Modifica form esistente', 'gepafin')}</h2>
|
||||
<div className="row">
|
||||
<p>{__('Continua a lavorare su un form precedentemente salvato', 'gepafin')}</p>
|
||||
|
||||
@@ -100,11 +100,13 @@ const BuilderElementSettings = ({ closeSettings }) => {
|
||||
? settings.map((o) => <div className="formElementSettings__field" key={o.name}>
|
||||
<label htmlFor={o.name}>{o.name}</label>
|
||||
{o.name === 'options'
|
||||
? <ElementSettingRepeater value={o.value} name={o.name} setDataFn={onUpdateOptions} />
|
||||
?
|
||||
<ElementSettingRepeater value={o.value} name={o.name} setDataFn={onUpdateOptions}/>
|
||||
: <InputText id={o.name} aria-describedby={`${o.name}-help`}
|
||||
value={o.value}
|
||||
onChange={(e) => onChange(e.target.value, o.name)}/>}
|
||||
</div>) : null}
|
||||
value={o.value}
|
||||
onChange={(e) => onChange(e.target.value, o.name)}/>}
|
||||
</div>)
|
||||
: null}
|
||||
</TabPanel>
|
||||
<TabPanel header={__('Validation', 'gepafin')}>
|
||||
{validators
|
||||
@@ -128,11 +130,11 @@ const BuilderElementSettings = ({ closeSettings }) => {
|
||||
: null}
|
||||
{textBasedValidatorFields.includes(k) && !isNil(validators[k])
|
||||
? <div className="formElementSettings__field">
|
||||
<label htmlFor={k}>{k}</label>
|
||||
<InputText id={k} aria-describedby={`${k}-help`}
|
||||
value={validators[k]}
|
||||
onChange={(e) => onChangeValidator(e.target.value, k)}/>
|
||||
</div> : null}
|
||||
<label htmlFor={k}>{k}</label>
|
||||
<InputText id={k} aria-describedby={`${k}-help`}
|
||||
value={validators[k]}
|
||||
onChange={(e) => onChangeValidator(e.target.value, k)}/>
|
||||
</div> : null}
|
||||
</div>) : null}
|
||||
</TabPanel>
|
||||
</TabView>
|
||||
|
||||
@@ -11,9 +11,10 @@ import { storeSet, storeGet, useStore } from '../../store';
|
||||
// components
|
||||
import FormBuilder from './components/FormBuilder';
|
||||
import { Button } from 'primereact/button';
|
||||
|
||||
// components
|
||||
import { ConfirmPopup, confirmPopup } from 'primereact/confirmpopup';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
|
||||
// api
|
||||
import FormsService from '../../service/forms-service';
|
||||
|
||||
const BandoFormsEdit = () => {
|
||||
@@ -46,7 +47,7 @@ const BandoFormsEdit = () => {
|
||||
if (bandoFormId === 0) {
|
||||
FormsService.createFormForCall(bandoId, formData, formCreateCallback, errFormCreateCallback);
|
||||
} else {
|
||||
FormsService.updateForm(bandoFormId, formData, formCreateCallback, errFormCreateCallback)
|
||||
FormsService.updateForm(bandoFormId, formData, formCreateCallback, errFormCreateCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +72,40 @@ const BandoFormsEdit = () => {
|
||||
navigate(`/bandi/${bandoId}/forms/${formId}/preview`);
|
||||
}
|
||||
|
||||
const confirmDelete = (event) => {
|
||||
confirmPopup({
|
||||
target: event.currentTarget,
|
||||
message: __('Sei sicuro di cancellare questo form?', 'gepafin'),
|
||||
icon: 'pi pi-info-circle',
|
||||
defaultFocus: 'reject',
|
||||
acceptClassName: 'p-button-danger',
|
||||
accept: doDelete,
|
||||
reject: () => {}
|
||||
});
|
||||
};
|
||||
|
||||
const doPublish = () => {
|
||||
console.log('doPublish');
|
||||
}
|
||||
|
||||
const doDelete = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
FormsService.deleteForm(formId, formDeleteCallback, errFormDeleteCallback)
|
||||
}
|
||||
|
||||
const formDeleteCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/bandi/${bandoId}/forms`);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errFormDeleteCallback = (data) => {
|
||||
console.log('errFormDeleteCallback', data)
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getElementItemsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.elementItems(data.data);
|
||||
@@ -172,6 +203,13 @@ const BandoFormsEdit = () => {
|
||||
onClick={doPublish}
|
||||
label={__('Pubblica', 'gepafin')}/>
|
||||
</div>
|
||||
<div className="appPageSection__actions">
|
||||
<ConfirmPopup />
|
||||
<Button
|
||||
onClick={confirmDelete}
|
||||
severity="danger"
|
||||
label={__('Cancella', 'gepafin')} icon="pi pi-trash" iconPos="right"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user