- fixed styles for fileupload;
- fixed funcionality of form fields; - added 'submit question' functionality;
This commit is contained in:
@@ -11,6 +11,9 @@ import { storeSet, useStore } from '../../store';
|
||||
// api
|
||||
import FormsService from '../../service/forms-service';
|
||||
|
||||
// tools
|
||||
import { isVAT } from '../../helpers/validators';
|
||||
|
||||
// components
|
||||
import { Skeleton } from 'primereact/skeleton';
|
||||
import { Button } from 'primereact/button';
|
||||
@@ -30,11 +33,32 @@ const BandoApplication = () => {
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
setValue,
|
||||
trigger,
|
||||
register,
|
||||
getValues,
|
||||
} = useForm({ defaultValues: {}, mode: 'onChange' });
|
||||
const values = getValues();
|
||||
|
||||
const validationFns = {
|
||||
isVAT
|
||||
}
|
||||
|
||||
const onSubmit = (formData) => {
|
||||
/*const newFormData = Object.keys(formData).reduce((acc, cur) => {
|
||||
acc.push({
|
||||
'fieldId': cur,
|
||||
'fieldValue': formData[cur] && formData[cur].getMonth ? formData[cur].toISOString() : formData[cur]
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
console.log('newFormData', newFormData);
|
||||
console.log('errors', errors);*/
|
||||
};
|
||||
|
||||
const saveDraft = () => {
|
||||
trigger();
|
||||
const formData = getValues();
|
||||
const newFormData = Object.keys(formData).reduce((acc, cur) => {
|
||||
acc.push({
|
||||
'fieldId': cur,
|
||||
@@ -42,7 +66,8 @@ const BandoApplication = () => {
|
||||
});
|
||||
return acc;
|
||||
}, []);
|
||||
console.log('newFormData', newFormData)
|
||||
console.log('newFormData', newFormData);
|
||||
console.log('errors', errors);
|
||||
};
|
||||
|
||||
const getBandoId = () => {
|
||||
@@ -98,7 +123,31 @@ const BandoApplication = () => {
|
||||
const placeholder = head(o.settings.filter(o => o.name === 'placeholder'));
|
||||
const options = head(o.settings.filter(o => o.name === 'options'));
|
||||
const step = head(o.settings.filter(o => o.name === 'step'));
|
||||
const mime = head(o.settings.filter(o => o.name === 'mime').join(','));
|
||||
const mime = head(o.settings.filter(o => o.name === 'mime'));
|
||||
let mimeValue = '';
|
||||
|
||||
if (mime) {
|
||||
mimeValue = mime.value.join(',');
|
||||
}
|
||||
|
||||
const validations = Object.keys(o.validators).reduce((acc, cur) => {
|
||||
if (o.validators[cur]) {
|
||||
if (['min', 'max', 'minLength', 'maxLength', 'maxSize'].includes(cur)) {
|
||||
acc[cur] = parseInt(o.validators[cur]);
|
||||
} else if ('pattern' === cur) {
|
||||
acc[cur] = new RegExp(o.validators[cur])
|
||||
} else if ('isRequired' === cur) {
|
||||
acc[cur] = o.validators[cur]
|
||||
} else if ('custom' === cur && validationFns[o.validators[cur]]) {
|
||||
if (!acc.validate) {
|
||||
acc.validate = {}
|
||||
}
|
||||
acc.validate[cur] = validationFns[o.validators[cur]]
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return <FormField
|
||||
key={o.id}
|
||||
@@ -107,12 +156,15 @@ const BandoApplication = () => {
|
||||
label={label ? label.value : ''}
|
||||
placeholder={placeholder ? placeholder.value : ''}
|
||||
control={control}
|
||||
register={register}
|
||||
errors={errors}
|
||||
defaultValue={values[o.id]}
|
||||
maxFractionDigits={step}
|
||||
accept={mime}
|
||||
config={o.validators}
|
||||
accept={mimeValue}
|
||||
config={validations}
|
||||
options={options ? options.value : []}
|
||||
setDataFn={setValue}
|
||||
sourceId={1}
|
||||
/>
|
||||
})}
|
||||
|
||||
@@ -125,6 +177,8 @@ const BandoApplication = () => {
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
type="button"
|
||||
onClick={saveDraft}
|
||||
outlined
|
||||
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
||||
<Button
|
||||
|
||||
@@ -109,11 +109,11 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
}
|
||||
|
||||
const openPreview = () => {
|
||||
navigate('/tenders/preview/11');
|
||||
navigate(`/tenders/${values.id}/preview`);
|
||||
}
|
||||
|
||||
const openPreviewEvaluation = () => {
|
||||
navigate('/tenders/preview-evaluation/11');
|
||||
navigate(`/tenders/${values.id}/preview-evaluation`);
|
||||
}
|
||||
|
||||
useImperativeHandle(
|
||||
@@ -231,6 +231,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors },
|
||||
|
||||
<Toast ref={toast} />
|
||||
<BandoEditFormActions
|
||||
id={values.id}
|
||||
openPreview={openPreview}
|
||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||
</form>
|
||||
|
||||
@@ -180,7 +180,9 @@ const BandoView = () => {
|
||||
<div className="appPageSection">
|
||||
<h2>{__('FAQ', 'gepafin')}</h2>
|
||||
<Accordion>
|
||||
{data.faq.map((o, i) => <AccordionTab key={i} header={o.value}>
|
||||
{data.faq
|
||||
.filter(o => o.isVisible)
|
||||
.map((o, i) => <AccordionTab key={i} header={o.value}>
|
||||
<p>
|
||||
{o.response}
|
||||
</p>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { Button } from 'primereact/button';
|
||||
import BandoService from '../../service/bando-service';
|
||||
import { Messages } from 'primereact/messages';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import FaqItemService from '../../service/faq-item-service';
|
||||
|
||||
const BandoViewBeneficiario = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
@@ -48,6 +49,57 @@ const BandoViewBeneficiario = () => {
|
||||
|
||||
}
|
||||
|
||||
const submitNewQuestion = () => {
|
||||
if (newQuestion) {
|
||||
if (bandoMsgs.current) {
|
||||
bandoMsgs.current.clear();
|
||||
}
|
||||
const obj = {
|
||||
"id": null,
|
||||
"lookUpDataId": null,
|
||||
"title": newQuestion,
|
||||
"value": newQuestion,
|
||||
"response": "",
|
||||
"isVisible": false
|
||||
}
|
||||
storeSet.main.setAsyncRequest();
|
||||
FaqItemService.addQuestion(id, obj, createCallBack, errCreateCallback)
|
||||
}
|
||||
}
|
||||
|
||||
const createCallBack = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setNewQuestion('');
|
||||
if (bandoMsgs.current && data.message) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'success', summary: '',
|
||||
detail: data.message,
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
|
||||
setTimeout(() => {
|
||||
bandoMsgs.current.clear();
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errCreateCallback = (data) => {
|
||||
if (bandoMsgs.current && data.message) {
|
||||
bandoMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: data.message,
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setData(getFormattedBandiData(data.data));
|
||||
@@ -77,7 +129,7 @@ const BandoViewBeneficiario = () => {
|
||||
useEffect(() => {
|
||||
const parsed = parseInt(id)
|
||||
const bandoId = !isNaN(parsed) ? parsed : 0;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
BandoService.getBando(bandoId, getCallback, errGetCallback);
|
||||
}, [id]);
|
||||
|
||||
@@ -187,7 +239,9 @@ const BandoViewBeneficiario = () => {
|
||||
<div className="appPageSection">
|
||||
<h2>{__('FAQ', 'gepafin')}</h2>
|
||||
<Accordion>
|
||||
{data.faq.map((o, i) => <AccordionTab key={i} header={o.value}>
|
||||
{data.faq
|
||||
.filter(o => o.isVisible)
|
||||
.map((o, i) => <AccordionTab key={i} header={o.value}>
|
||||
<p>
|
||||
{o.response}
|
||||
</p>
|
||||
@@ -210,6 +264,10 @@ const BandoViewBeneficiario = () => {
|
||||
{__('Riceverai una notifica quando ti risponderemo', 'gepafin')}
|
||||
</small>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={submitNewQuestion}
|
||||
label={__('Salva', 'gepafin')}/>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
|
||||
Reference in New Issue
Block a user