Merge pull request #12 from Kitzanos/feature/34-implement-delete-company-api
Delet company API (hidden in UI)
This commit is contained in:
@@ -5,6 +5,7 @@ import { klona } from 'klona';
|
|||||||
import { wrap } from 'object-path-immutable';
|
import { wrap } from 'object-path-immutable';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import emailjs from '@emailjs/browser';
|
import emailjs from '@emailjs/browser';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
// store
|
// store
|
||||||
import { storeSet, useStore, storeGet } from '../../store';
|
import { storeSet, useStore, storeGet } from '../../store';
|
||||||
@@ -40,6 +41,7 @@ const ProfileCompany = () => {
|
|||||||
const [isVisibleRemoveDialog, setIsVisibleRemoveDialog] = useState(false);
|
const [isVisibleRemoveDialog, setIsVisibleRemoveDialog] = useState(false);
|
||||||
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
const { delegaFirstName = '', delegaLastName = '', delegaCodiceFiscale = '' } = delegaData;
|
||||||
const toast = useRef(null);
|
const toast = useRef(null);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
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(() => {
|
useEffect(() => {
|
||||||
const newFormData = klona(formInitialData);
|
const newFormData = klona(formInitialData);
|
||||||
Object.keys(newFormData).map(v => setValue(v, newFormData[v]));
|
Object.keys(newFormData).map(v => setValue(v, newFormData[v]));
|
||||||
|
|||||||
@@ -35,4 +35,8 @@ export default class CompanyService {
|
|||||||
static deleteDelega = (id, callback, errCallback) => {
|
static deleteDelega = (id, callback, errCallback) => {
|
||||||
NetworkService.delete(`${API_BASE_URL}/company/${id}/delegation`, {}, 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