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.1 KB
|
Rev | Line | |
---|
[bc20307] | 1 | import { useState,useContext } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
| 4 |
|
---|
| 5 | const 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 |
|
---|
| 36 | export default useGetZoneByName;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.