Last change
on this file since bc20307 was bc20307, checked in by Tasevski2 <39170279+Tasevski2@…>, 3 years ago |
Push before video
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[bc20307] | 1 | import { useState, useContext } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
| 4 |
|
---|
| 5 | const useActivateSession = () => {
|
---|
| 6 | const [isLoading, setIsLoading] = useState(false);
|
---|
| 7 | const { setAlert } = useContext(AccessoriesContext);
|
---|
| 8 |
|
---|
| 9 | const activateSession = async ({
|
---|
| 10 | pssId,
|
---|
| 11 | parkingSpaceName,
|
---|
| 12 | onActivateSession,
|
---|
| 13 | }) => {
|
---|
| 14 | setIsLoading(true);
|
---|
| 15 | axios
|
---|
| 16 | .put(
|
---|
| 17 | `/parkingSession/verify/${pssId}?parkingSpaceName=${parkingSpaceName}`)
|
---|
| 18 | .then((res) => {
|
---|
| 19 | // res.data is the new updated active zone
|
---|
| 20 | setAlert({
|
---|
| 21 | type: 'success',
|
---|
| 22 | msg: 'Сесијата е успешно активирана!',
|
---|
| 23 | });
|
---|
| 24 | onActivateSession({ updatedSession:res.data });
|
---|
| 25 | })
|
---|
| 26 | .catch((err) => {
|
---|
| 27 | console.log(err);
|
---|
| 28 | setAlert({
|
---|
| 29 | type: 'error',
|
---|
| 30 | msg: 'Проблеми со серверот!',
|
---|
| 31 | });
|
---|
| 32 | })
|
---|
| 33 | .finally(() => {
|
---|
| 34 | setIsLoading(false);
|
---|
| 35 | });
|
---|
| 36 | };
|
---|
| 37 | return {
|
---|
| 38 | activateSession,
|
---|
| 39 | isLoading,
|
---|
| 40 | };
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | export default useActivateSession;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.