- updated https url;
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, isNil, pathOr, head } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
import { wrap } from 'object-path-immutable';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore, storeGet } from '../../store';
|
||||
@@ -12,19 +13,24 @@ import FormField from '../../components/FormField';
|
||||
import { Button } from 'primereact/button';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import BlockingOverlay from '../../components/BlockingOverlay';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
|
||||
// api
|
||||
import CompanyService from '../../service/company-service';
|
||||
|
||||
// tools
|
||||
import { isPIVA, isCodiceFiscale } from '../../helpers/validators';
|
||||
import { isPIVA, isCodiceFiscale, isEmail, isEmailPEC } from '../../helpers/validators';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import FileuploadStandalone from '../../components/FileuploadStandalone';
|
||||
|
||||
const ProfileCompany = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const companies = useStore().main.companies();
|
||||
const infoMsgs = useRef(null);
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
const [delegaData, setDelegaData] = useState({});
|
||||
const [delega, setDelega] = useState({});
|
||||
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
||||
|
||||
const {
|
||||
control,
|
||||
@@ -137,6 +143,16 @@ const ProfileCompany = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const setDelegaFieldValue = (value, name) => {
|
||||
const newDelegaData = wrap(delegaData).set([name], value).value();
|
||||
setDelegaData(newDelegaData)
|
||||
}
|
||||
|
||||
const setDelegaFile = (data) => {
|
||||
console.log('setDelegaFile', data)
|
||||
setDelega(data);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const newFormData = klona(formInitialData);
|
||||
Object.keys(newFormData).map(v => setValue(v, newFormData[v]));
|
||||
@@ -204,7 +220,12 @@ const ProfileCompany = () => {
|
||||
label={__('Email PEC', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
config={{
|
||||
required: __('È obbligatorio', 'gepafin'),
|
||||
validate: {
|
||||
isEmailPEC
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
@@ -214,7 +235,12 @@ const ProfileCompany = () => {
|
||||
label={__('Email', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
config={{
|
||||
required: __('È obbligatorio', 'gepafin'),
|
||||
validate: {
|
||||
isEmail
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{/*<FormField
|
||||
@@ -258,6 +284,41 @@ const ProfileCompany = () => {
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
disabled={isNil(formInitialData.id)}
|
||||
fieldName="contactName"
|
||||
label={__('Nome di referente aziendale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="contactEmail"
|
||||
label={__('Email di referente aziendale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{
|
||||
required: __('È obbligatorio', 'gepafin'),
|
||||
validate: {
|
||||
isEmail
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
{/*<FormField
|
||||
type="textinput"
|
||||
fieldName="phoneNumber"
|
||||
label={__('Telefono', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>*/}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
@@ -273,101 +334,105 @@ const ProfileCompany = () => {
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{!isLegalRepresentant
|
||||
? <div className="appForm__delegaForm">
|
||||
<div className="appForm__delegaFormHeader">
|
||||
<legend>{__('Compilazione Delega', 'gepafin')}</legend>
|
||||
<p className="appForm__delegaFormText">{__('Per procedere come delegato, compila il form seguente, scarica il documento della delega, fallo firmare dal rappresentante legale e ricaricalo.', 'gepafin')}</p>
|
||||
{!isLegalRepresentant
|
||||
? <div className="appForm__delegaForm">
|
||||
<div className="appForm__delegaFormHeader">
|
||||
<legend>{__('Compilazione Delega', 'gepafin')}</legend>
|
||||
<p className="appForm__delegaFormText">{__('Per procedere come delegato, compila il form seguente, scarica il documento della delega, fallo firmare dal rappresentante legale e ricaricalo.', 'gepafin')}</p>
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="delegaFirstName">
|
||||
{__('Nome del rappresentante legale', 'gepafin')}
|
||||
<span className="appForm__field--required">*</span>
|
||||
</label>
|
||||
<InputText
|
||||
id="delegaFirstName"
|
||||
value={delegaFirstName}
|
||||
onChange={(e) => setDelegaFieldValue(e.target.value, 'delegaFirstName')}/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__cols">
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="delegaFirstName"
|
||||
label={__('Nome del rappresentante legale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="delegaLastName"
|
||||
label={__('Cognome del rappresentante legale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="textinput"
|
||||
fieldName="delegaCodiceFiscale"
|
||||
label={__('Codice fiscale del rappresentante legale', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{
|
||||
required: __('È obbligatorio', 'gepafin'),
|
||||
isCodiceFiscale
|
||||
}}
|
||||
/>
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="delegaLastName">
|
||||
{__('Cognome del rappresentante legale', 'gepafin')}
|
||||
<span className="appForm__field--required">*</span>
|
||||
</label>
|
||||
<InputText
|
||||
id="delegaLastName"
|
||||
value={delegaLastName}
|
||||
onChange={(e) => setDelegaFieldValue(e.target.value, 'delegaLastName')}/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
label={__('Genera documento Delega', 'gepafin')}
|
||||
icon="pi pi-check" iconPos="right"/>
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="delegaCodiceFiscale">
|
||||
{__('Codice fiscale del rappresentante legale', 'gepafin')}
|
||||
<span className="appForm__field--required">*</span>
|
||||
</label>
|
||||
<InputText
|
||||
id="delegaCodiceFiscale"
|
||||
value={delegaCodiceFiscale}
|
||||
onChange={(e) => setDelegaFieldValue(e.target.value, 'delegaCodiceFiscale')}/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FormField
|
||||
type="fileuploadasync"
|
||||
setDataFn={setValue}
|
||||
fieldName="docs"
|
||||
label={__('Carica documento Delega Firmato', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
defaultValue={values['docs']}
|
||||
config={{ required: __('È obbligatorio', 'gepafin') }}
|
||||
accept={['application/pkcs7-mime']}
|
||||
chooseLabel={__('Aggiungi documento', 'gepafin')}
|
||||
multiple={true}
|
||||
doctype="document"
|
||||
register={register}
|
||||
sourceId={values.id}
|
||||
source="call"
|
||||
/>
|
||||
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={true}
|
||||
outlined
|
||||
onClick={() => {
|
||||
}}
|
||||
label={__('Visualizza delega', 'gepafin')} icon="pi pi-eye" iconPos="right"/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={true}
|
||||
outlined
|
||||
onClick={() => {
|
||||
}}
|
||||
label={__('Sostituisci delega', 'gepafin')} icon="pi pi-sync" iconPos="right"/>
|
||||
</div>
|
||||
</div> : null}
|
||||
|
||||
<div className="appPageSection__hr">
|
||||
<span>{__('Azioni rapide', 'gepafin')}</span>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<div>
|
||||
<Button
|
||||
form="companyForm"
|
||||
/*disabled={isAsyncRequest || emptyValues || values.id}*/
|
||||
label={__('Salva modifiche', 'gepafin')}
|
||||
disabled={isEmpty(delegaCodiceFiscale) || isEmpty(delegaFirstName) || isEmpty(delegaLastName)}
|
||||
type="button"
|
||||
label={__('Genera documento Delega', 'gepafin')}
|
||||
icon="pi pi-check" iconPos="right"/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__field">
|
||||
<label htmlFor="delega">
|
||||
{__('Carica documento Delega Firmato', 'gepafin')}
|
||||
<span className="appForm__field--required">*</span>
|
||||
</label>
|
||||
<FileuploadStandalone
|
||||
setDataFn={setDelegaFile}
|
||||
fieldName="delega"
|
||||
defaultValue={[delega]}
|
||||
accept={['']}
|
||||
chooseLabel={__('Aggiungi documento', 'gepafin')}
|
||||
multiple={false}
|
||||
doctype="document"
|
||||
sourceId={formInitialData.id}
|
||||
source="call"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="appForm__delegaFormActions">
|
||||
<Button
|
||||
type="button"
|
||||
disabled={true}
|
||||
outlined
|
||||
onClick={() => {
|
||||
}}
|
||||
label={__('Visualizza delega', 'gepafin')} icon="pi pi-eye" iconPos="right"/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={true}
|
||||
outlined
|
||||
onClick={() => {
|
||||
}}
|
||||
label={__('Sostituisci delega', 'gepafin')} icon="pi pi-sync" iconPos="right"/>
|
||||
</div>
|
||||
</div> : <div className="appPage__spacer"></div>}
|
||||
|
||||
<div className="appPageSection__hr">
|
||||
<span>{__('Azioni rapide', 'gepafin')}</span>
|
||||
</div>
|
||||
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
<Button
|
||||
form="companyForm"
|
||||
/*disabled={isAsyncRequest || emptyValues || values.id}*/
|
||||
label={__('Salva modifiche', 'gepafin')}
|
||||
icon="pi pi-check" iconPos="right"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user