source: sources/client/src/hooks/useGetZoneByName.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';
4
5const useGetZoneByName = (defaultZoneInfo) => {
6 const [zone, setZone] = useState(defaultZoneInfo);
7 const [isLoading, setIsLoading] = useState(false);
8 const { setAlert } = useContext(AccessoriesContext);
9 const fetchZone = async (pzName) => {
10 setIsLoading(true);
11 return await axios
12 .get(`/parkingZone/name/${pzName}`)
13 .then((res) => {
14 setZone(res.data);
15 return res.data;
16 })
17 .catch((err) => {
18 // ALERT FOR ERROR WITH ERROR MSG
19 setAlert({
20 type: 'error',
21 msg: 'Проблеми со серверот!', // TODO change msg to err.message
22 });
23 })
24 .finally(() => {
25 setIsLoading(false);
26 });
27 };
28 return {
29 zone,
30 isLoading,
31 fetchZone,
32 setZone
33 };
34};
35
36export default useGetZoneByName;
Note: See TracBrowser for help on using the repository browser.