- updated zustand and react libraries;
- added 'put in draft' btn;
This commit is contained in:
@@ -8,7 +8,7 @@ import { useForm } from 'react-hook-form';
|
||||
//import { useNavigate } from 'react-router-dom';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore, storeGet } from '../../store';
|
||||
import { storeSet, useStoreValue, storeGet } from '../../store';
|
||||
|
||||
// api
|
||||
import CompanyService from '../../service/company-service';
|
||||
@@ -34,9 +34,9 @@ import { useNavigate } from 'react-router-dom';
|
||||
const APP_HUB_ID = process.env.REACT_APP_HUB_ID;
|
||||
|
||||
const ProfileCompany = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const chosenCompanyId = useStore().main.chosenCompanyId();
|
||||
const companies = useStore().main.companies();
|
||||
const isAsyncRequest = useStoreValue('isAsyncRequest');
|
||||
const chosenCompanyId = useStoreValue('chosenCompanyId');
|
||||
const companies = useStoreValue('companies');
|
||||
const infoMsgs = useRef(null);
|
||||
const [formInitialData, setFormInitialData] = useState({});
|
||||
const [delegaData, setDelegaData] = useState({});
|
||||
@@ -77,7 +77,7 @@ const ProfileCompany = () => {
|
||||
|
||||
const onSubmit = (formData) => {
|
||||
infoMsgs.current.clear();
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
|
||||
CompanyService.updateCompany(formData.id, formData, updateCallback, updateError);
|
||||
};
|
||||
@@ -85,7 +85,7 @@ const ProfileCompany = () => {
|
||||
const updateCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const company = klona(data.data);
|
||||
const companies = storeGet.main.companies();
|
||||
const companies = storeGet('companies');
|
||||
const existingCompany = head(companies.filter(o => o.id === company.id));
|
||||
let newCompanies = [];
|
||||
|
||||
@@ -93,10 +93,10 @@ const ProfileCompany = () => {
|
||||
newCompanies = companies.map(o => o.id === company.id ? company : o)
|
||||
} else {
|
||||
newCompanies = [...companies, company];
|
||||
storeSet.main.chosenCompanyId(company.id);
|
||||
storeSet('chosenCompanyId', company.id);
|
||||
}
|
||||
|
||||
storeSet.main.companies(newCompanies);
|
||||
storeSet('companies', newCompanies);
|
||||
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
@@ -106,12 +106,12 @@ const ProfileCompany = () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const updateError = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const checkVatNumber = (e) => {
|
||||
@@ -119,7 +119,7 @@ const ProfileCompany = () => {
|
||||
const isValid = isPIVA(e.target.value);
|
||||
|
||||
if (isValid) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
CompanyService.checkVat(checkVatCallback, errCheckVatCallback, [['vatNumber', e.target.value]])
|
||||
} else {
|
||||
setEmptyValues();
|
||||
@@ -150,13 +150,13 @@ const ProfileCompany = () => {
|
||||
} else {
|
||||
setEmptyValues();
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errCheckVatCallback = (data) => {
|
||||
setEmptyValues();
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const setDelegaFieldValue = (value, name) => {
|
||||
@@ -172,16 +172,16 @@ const ProfileCompany = () => {
|
||||
if (data.data) {
|
||||
setDelega([data.data]);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errDellegaCallback = () => {
|
||||
setDelega([]);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const downloadDelega = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
const data = {
|
||||
codiceFiscale: delegaCodiceFiscale,
|
||||
firstName: delegaFirstName,
|
||||
@@ -199,11 +199,11 @@ const ProfileCompany = () => {
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errDellegaDownloadCallback = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const confirmDelete = (event) => {
|
||||
@@ -231,7 +231,7 @@ const ProfileCompany = () => {
|
||||
}*/
|
||||
|
||||
/*const doRemoveCompany = () => {
|
||||
const userData = storeGet.main.userData();
|
||||
const userData = storeGet('userData');
|
||||
let chosenCompany = {};
|
||||
|
||||
if (chosenCompanyId) {
|
||||
@@ -276,32 +276,32 @@ const ProfileCompany = () => {
|
||||
}*/
|
||||
|
||||
const doRemoveCompanyAPI = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
CompanyService.deleteCompany(formInitialData.id, deleteCompanyCallback, errDeleteCompanyCallback)
|
||||
}
|
||||
|
||||
const deleteCompanyCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const userData = storeGet.main.userData();
|
||||
const userData = storeGet('userData');
|
||||
const newCompanies = companies.filter(o => o.id !== chosenCompanyId);
|
||||
storeSet.main.companies(newCompanies);
|
||||
storeSet('companies', newCompanies);
|
||||
const newUserData = wrap(userData).set('companies', newCompanies).value();
|
||||
storeSet.main.userData(newUserData);
|
||||
storeSet('userData', newUserData);
|
||||
|
||||
if (!isEmpty(newCompanies)) {
|
||||
const newChosenCompanyId = newCompanies[0].id;
|
||||
storeSet.main.chosenCompanyId(newChosenCompanyId);
|
||||
storeSet('chosenCompanyId', newChosenCompanyId);
|
||||
} else {
|
||||
storeSet.main.chosenCompanyId(0);
|
||||
storeSet('chosenCompanyId', 0);
|
||||
navigate(`/`);
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errDeleteCompanyCallback = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
@@ -345,7 +345,7 @@ const ProfileCompany = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (formInitialData.id) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
CompanyService.getCompanyDelega(getDellegaCallback, errDellegaCallback, [
|
||||
['companyId', formInitialData.id]
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user