- implemented API way of deletin company, hid by now, but ready to be shipped;
This commit is contained in:
@@ -5,6 +5,7 @@ import { klona } from 'klona';
|
||||
import { wrap } from 'object-path-immutable';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import emailjs from '@emailjs/browser';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore, storeGet } from '../../store';
|
||||
@@ -40,6 +41,7 @@ const ProfileCompany = () => {
|
||||
const [isVisibleRemoveDialog, setIsVisibleRemoveDialog] = useState(false);
|
||||
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
||||
const toast = useRef(null);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {
|
||||
control,
|
||||
@@ -268,9 +270,35 @@ const ProfileCompany = () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// TODO delete company functionality by API, ready to be shipped
|
||||
/*const doRemoveCompanyAPI = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
CompanyService.deleteCompany(formInitialData.id, deleteCompanyCallback, errDeleteCompanyCallback)
|
||||
}
|
||||
|
||||
const deleteCompanyCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const userData = storeGet.main.userData();
|
||||
const newCompanies = companies.filter(o => o.id !== chosenCompanyId);
|
||||
const newUserData = wrap(userData).set('company', newCompanies).value();
|
||||
storeSet.main.companies(newUserData.companies);
|
||||
storeSet.main.userData(newUserData);
|
||||
|
||||
if (!isEmpty(newCompanies)) {
|
||||
const newChosenCompanyId = newCompanies[0].id;
|
||||
storeSet.main.chosenCompanyId(newChosenCompanyId);
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errDeleteCompanyCallback = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}*/
|
||||
|
||||
useEffect(() => {
|
||||
const newFormData = klona(formInitialData);
|
||||
Object.keys(newFormData).map(v => setValue(v, newFormData[v]));
|
||||
|
||||
@@ -35,4 +35,8 @@ export default class CompanyService {
|
||||
static deleteDelega = (id, callback, errCallback) => {
|
||||
NetworkService.delete(`${API_BASE_URL}/company/${id}/delegation`, {}, callback, errCallback);
|
||||
};
|
||||
|
||||
static deleteCompany = (id, callback, errCallback) => {
|
||||
NetworkService.delete(`${API_BASE_URL}/company/${id}`, {}, callback, errCallback);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user