source: sources/client/src/hooks/useDeleteZone.js

Last change on this file was bc20307, checked in by Tasevski2 <39170279+Tasevski2@…>, 2 years ago

Push before video

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import { useState, useContext } from 'react';
2import axios from 'axios';
3import { AccessoriesContext } from '../context/AccessoriesContext';
4import { useHistory } from 'react-router-dom';
5
6const useDeleteZone = () => {
7 const [isLoading, setIsLoading] = useState(false);
8 const { setAlert } = useContext(AccessoriesContext);
9 const history = useHistory();
10 const deleteZone = async ({ id }) => {
11 setIsLoading(true);
12 await axios
13 .delete(`/parkingZone/${id}`) // TODO CHANGE OBJECT
14 .then((res) => {
15 setAlert({
16 type: 'success',
17 msg: `Зоната е успешно избришана!`, // TODO Change MSG - add the first and last name of the deleted emoloyee
18 });
19 history.push('/');
20 })
21 .catch((err) => {
22 // ALERT FOR ERROR WITH ERROR MSG
23 setAlert({
24 type: 'error',
25 msg: 'Проблеми со серверот!', // TODO change msg to err.message
26 });
27 console.log(err);
28 })
29 .finally(() => {
30 setIsLoading(false);
31 });
32 };
33
34 return {
35 deleteZone,
36 isLoading,
37 };
38};
39
40export default useDeleteZone;
Note: See TracBrowser for help on using the repository browser.