Last change
on this file since 747e0ab was bc20307, checked in by Tasevski2 <39170279+Tasevski2@…>, 3 years ago |
Push before video
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | import { useState, useContext } from 'react';
|
---|
2 | import axios from 'axios';
|
---|
3 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
4 |
|
---|
5 | const useCreateZone = () => {
|
---|
6 | const [isLoading, setIsLoading] = useState(false);
|
---|
7 | const { setAlert } = useContext(AccessoriesContext);
|
---|
8 |
|
---|
9 | const createZone = async ({
|
---|
10 | zoneName,
|
---|
11 | setModalInput,
|
---|
12 | setModalOpen,
|
---|
13 | addNewZoneToData,
|
---|
14 | }) => {
|
---|
15 | setIsLoading(true);
|
---|
16 | await axios
|
---|
17 | .post(`/parkingZoneName`, zoneName)
|
---|
18 | .then((res) => {
|
---|
19 | setAlert({
|
---|
20 | type: 'success',
|
---|
21 | msg: `Зоната ${zoneName} е успешно креирана!`,
|
---|
22 | });
|
---|
23 | setModalOpen(false);
|
---|
24 | setModalInput('');
|
---|
25 | console.log(res.data);
|
---|
26 | addNewZoneToData({ ...res.data });
|
---|
27 | })
|
---|
28 | .catch((err) => {
|
---|
29 | // ALERT FOR ERROR WITH ERROR MSG
|
---|
30 | console.log(err);
|
---|
31 | setAlert({
|
---|
32 | type: 'error',
|
---|
33 | msg: 'Проблеми со серверот!', // TODO change msg to err.message
|
---|
34 | });
|
---|
35 | })
|
---|
36 | .finally(() => {
|
---|
37 | setIsLoading(false);
|
---|
38 | });
|
---|
39 | };
|
---|
40 |
|
---|
41 | return {
|
---|
42 | createZone,
|
---|
43 | isLoading,
|
---|
44 | };
|
---|
45 | };
|
---|
46 |
|
---|
47 | export default useCreateZone;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.