- updated call form, new fields;
- updated preview pages for bando; - fixed bug with decimal number field;
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { useMemo, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, isNil } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore } from '../../store';
|
||||
@@ -12,12 +13,15 @@ import { Button } from 'primereact/button';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
// api
|
||||
import UserService from '../../service/user-service';
|
||||
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
||||
import CompanyService from '../../service/company-service';
|
||||
|
||||
// tools
|
||||
import { isPIVA } from '../../helpers/validators';
|
||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||
|
||||
const ProfileCompany = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const userData = useStore().main.userData();
|
||||
const companies = useStore().main.companies();
|
||||
const infoMsgs = useRef(null);
|
||||
|
||||
const {
|
||||
@@ -27,8 +31,8 @@ const ProfileCompany = () => {
|
||||
setValue
|
||||
} = useForm({
|
||||
defaultValues: useMemo(() => {
|
||||
return userData;
|
||||
}, [userData]),
|
||||
return companies[0];
|
||||
}, [companies]),
|
||||
mode: 'onChange'
|
||||
});
|
||||
|
||||
@@ -36,7 +40,11 @@ const ProfileCompany = () => {
|
||||
infoMsgs.current.clear();
|
||||
storeSet.main.setAsyncRequest();
|
||||
|
||||
UserService.updateUser(formData, updateCallback, updateError);
|
||||
if (isNil(formData.id)) {
|
||||
CompanyService.createCompany(formData, updateCallback, updateError);
|
||||
} else {
|
||||
CompanyService.updateCompany(formData.id, formData, updateCallback, updateError);
|
||||
}
|
||||
};
|
||||
|
||||
const updateCallback = (data) => {
|
||||
@@ -51,6 +59,47 @@ const ProfileCompany = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const checkVatNumber = (e) => {
|
||||
infoMsgs.current.clear();
|
||||
const isValid = isPIVA(e.target.value);
|
||||
|
||||
if (isValid) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
CompanyService.checkVat(checkVatCallback, errCheckVatCallback, [['vatNumber', e.target.value]])
|
||||
}
|
||||
}
|
||||
|
||||
const checkVatCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const resp = data.data.data;
|
||||
if (!isEmpty(resp)) {
|
||||
const {
|
||||
cap, cf, denominazione, piva, indirizzo, comune, dettaglio: { pec }
|
||||
} = resp;
|
||||
|
||||
const formData = {
|
||||
cap,
|
||||
pec,
|
||||
email: pec,
|
||||
city: comune,
|
||||
codiceFiscale: cf,
|
||||
address: indirizzo,
|
||||
vatNumber: piva,
|
||||
companyName: denominazione
|
||||
}
|
||||
console.log('formData', formData);
|
||||
Object.keys(formData).map(k => setValue(k, formData[k]));
|
||||
}
|
||||
//setData(getFormattedBandiData(data.data));
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errCheckVatCallback = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
@@ -61,25 +110,101 @@ const ProfileCompany = () => {
|
||||
<Messages ref={infoMsgs}/>
|
||||
|
||||
<form className="appForm" onSubmit={handleSubmit(onSubmit)}>
|
||||
|
||||
<BlockingOverlay shouldDisplay={isAsyncRequest}/>
|
||||
<div className="appPageSection">
|
||||
<h2>{__('Informazioni aziendali', 'gepafin')}</h2>
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="organization"
|
||||
disabled={true}
|
||||
fieldName="companyName"
|
||||
label={__('Ragione Sociale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
placeholder="Azienda"
|
||||
placeholder="Nome di azienda"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="vatNumber"
|
||||
label={__('P.IVA', 'gepafin')}
|
||||
onBlurFn={checkVatNumber}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="codiceFiscale"
|
||||
label={__('Codice fiscale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="pec"
|
||||
label={__('Email PEC', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="email"
|
||||
label={__('Email', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
{/*<FormField
|
||||
type="textinput"
|
||||
fieldName="phoneNumber"
|
||||
label={__('Telefono', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>*/}
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="address"
|
||||
label={__('Indirizzo Sede Legale', 'gepafin')}
|
||||
label={__('Indirizzo', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="city"
|
||||
label={__('Città', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="cap"
|
||||
label={__('CAP', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
|
||||
Reference in New Issue
Block a user