source: sources/client/src/hooks/useUpdateZone.js@ bc20307

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

Push before video

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