- added registartion page;
- implemented validation helper-functions; - fixed form fields datepicker and datepicker range; - updated routes logic; - fixed FAQ items editing/submission;
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { DndProvider } from 'react-dnd';
|
||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||
import { klona } from 'klona';
|
||||
import { isEmpty } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet, storeGet, useStore } from '../../store';
|
||||
@@ -13,17 +14,23 @@ import FormBuilder from './components/FormBuilder';
|
||||
import { Button } from 'primereact/button';
|
||||
import { ConfirmPopup, confirmPopup } from 'primereact/confirmpopup';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import { ConfirmDialog } from 'primereact/confirmdialog';
|
||||
|
||||
// api
|
||||
import FormsService from '../../service/forms-service';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import { elementItems } from '../../tempData';
|
||||
import { Messages } from 'primereact/messages';
|
||||
|
||||
const BandoFormsEdit = () => {
|
||||
const { id, formId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [formName, setFormName] = useState('');
|
||||
const [visibleConfirmation, setVisibleConfirmation] = useState(false);
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const formMsgs = useRef(null);
|
||||
const toast = useRef(null);
|
||||
|
||||
const getBandoId = () => {
|
||||
const parsed = parseInt(id)
|
||||
@@ -32,13 +39,46 @@ const BandoFormsEdit = () => {
|
||||
|
||||
const goBack = () => {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/tenders/${bandoId}/forms`);
|
||||
navigate(`/bandi/${bandoId}/forms`);
|
||||
}
|
||||
|
||||
const doSave = (shouldRedirect = false) => {
|
||||
if (formMsgs.current) {
|
||||
formMsgs.current.clear();
|
||||
}
|
||||
|
||||
const content = storeGet.main.formElements();
|
||||
|
||||
if (isEmpty(formName) || isEmpty(content)) {
|
||||
if (isEmpty(formName)) {
|
||||
if (formMsgs.current) {
|
||||
formMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: __('Nome di form è obligatorio.', 'gepafin'),
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isEmpty(content)) {
|
||||
if (formMsgs.current) {
|
||||
formMsgs.current.show([
|
||||
{
|
||||
id: '99',
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: __('Devi aggiungere almeno uno campo.', 'gepafin'),
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bandoId = getBandoId();
|
||||
const parsedFormId = parseInt(formId)
|
||||
const parsedFormId = parseInt(formId);
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
const formData = {
|
||||
label: formName,
|
||||
@@ -47,9 +87,20 @@ const BandoFormsEdit = () => {
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
if (bandoFormId === 0) {
|
||||
FormsService.createFormForCall(bandoId, formData, (data) => formCreateCallback(data, shouldRedirect), errFormCreateCallback);
|
||||
FormsService.createFormForCall(
|
||||
bandoId,
|
||||
formData,
|
||||
(data) => formCreateCallback(data, shouldRedirect),
|
||||
errFormCreateCallback
|
||||
);
|
||||
} else {
|
||||
FormsService.updateForm(bandoFormId, formData, (data) => formCreateCallback(data, shouldRedirect), errFormCreateCallback);
|
||||
FormsService.updateForm(
|
||||
bandoFormId,
|
||||
formData,
|
||||
(data) => formCreateCallback(data, shouldRedirect),
|
||||
errFormCreateCallback,
|
||||
[['forceDeleteFlow', false]]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,18 +109,59 @@ const BandoFormsEdit = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
const bandoId = getBandoId();
|
||||
if (shouldRedirect) {
|
||||
navigate(`/tenders/${bandoId}/forms/${data.data.id}/preview`);
|
||||
navigate(`/bandi/${bandoId}/forms/${data.data.id}/preview`);
|
||||
return;
|
||||
}
|
||||
if (data.data.id) {
|
||||
navigate(`/tenders/${bandoId}/forms/${data.data.id}`);
|
||||
navigate(`/bandi/${bandoId}/forms/${data.data.id}`);
|
||||
}
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
summary: '',
|
||||
detail: __('Il form è stato aggiornato corretamente!', 'gepafin')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const errFormCreateCallback = (data) => {
|
||||
console.log('errFormCreateCallback', data)
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
if (data.status === 'BAD_REQUEST') {
|
||||
setVisibleConfirmation(true);
|
||||
} else {
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'error',
|
||||
summary: '',
|
||||
detail: data.message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const acceptModification = () => {
|
||||
const content = storeGet.main.formElements();
|
||||
const parsedFormId = parseInt(formId);
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
const formData = {
|
||||
label: formName,
|
||||
content
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
|
||||
FormsService.updateForm(
|
||||
bandoFormId,
|
||||
formData,
|
||||
(data) => formCreateCallback(data, false),
|
||||
errFormCreateCallback,
|
||||
[['forceDeleteFlow', true]]
|
||||
);
|
||||
}
|
||||
|
||||
const rejectModification = () => {
|
||||
setVisibleConfirmation(false);
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
@@ -101,7 +193,7 @@ const BandoFormsEdit = () => {
|
||||
const formDeleteCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/tenders/${bandoId}/forms`);
|
||||
navigate(`/bandi/${bandoId}/forms`);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
@@ -170,6 +262,19 @@ const BandoFormsEdit = () => {
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<Messages ref={formMsgs}/>
|
||||
<ConfirmDialog
|
||||
group="declarative"
|
||||
visible={visibleConfirmation}
|
||||
onHide={() => setVisibleConfirmation(false)}
|
||||
message={__('Le modifiche al modulo influiscono sul flusso precedentemente creato, quindi deve essere ricreato. Confermi le modifiche?', 'gepafin')}
|
||||
header={__('Conferma le modifiche', 'gepafin')}
|
||||
icon="pi pi-exclamation-triangle"
|
||||
accept={acceptModification}
|
||||
acceptLabel={__('Si', 'gepafin')}
|
||||
reject={rejectModification}
|
||||
style={{ maxWidth: '500px' }} />
|
||||
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="label">{__('Assegna un nome a questo form', 'gepafin')}</label>
|
||||
<InputText
|
||||
@@ -190,6 +295,7 @@ const BandoFormsEdit = () => {
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
<Toast ref={toast} />
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
|
||||
Reference in New Issue
Block a user