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.3 KB
|
Rev | Line | |
---|
[bc20307] | 1 | import { useContext } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
| 4 | import { sessionStatus } from '../config/enums';
|
---|
| 5 |
|
---|
| 6 | const useUserStartSession = () => {
|
---|
| 7 | const { setAlert, setIsBackdropLoaderOpen } =
|
---|
| 8 | useContext(AccessoriesContext);
|
---|
| 9 | const userStartSession = async ({ sessionData, setSession }) => {
|
---|
| 10 | setIsBackdropLoaderOpen(true);
|
---|
| 11 | await axios
|
---|
| 12 | .post(
|
---|
| 13 | `/parkingSession/${sessionData.zone}?tablicka=${sessionData.plate}`
|
---|
| 14 | ) // TODO CHANGE OBJECT
|
---|
| 15 | .then((res) => {
|
---|
| 16 | setAlert({
|
---|
| 17 | type: 'success',
|
---|
| 18 | msg: `Успешно започната сесија!`,
|
---|
| 19 | });
|
---|
| 20 | setSession(res.data);
|
---|
| 21 |
|
---|
| 22 | })
|
---|
| 23 | .catch((err) => {
|
---|
| 24 | // ALERT FOR ERROR WITH ERROR MSG
|
---|
| 25 | setAlert({
|
---|
| 26 | type: 'error',
|
---|
| 27 | msg: 'Проблеми со серверот!', // TODO change msg to err.message
|
---|
| 28 | });
|
---|
| 29 | })
|
---|
| 30 | .finally(() => {
|
---|
| 31 | setIsBackdropLoaderOpen(false);
|
---|
| 32 | });
|
---|
| 33 | };
|
---|
| 34 |
|
---|
| 35 | return {
|
---|
| 36 | userStartSession,
|
---|
| 37 | };
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | export default useUserStartSession;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.