source: sources/client/src/hooks/useUserFinishedSession.js@ bc20307

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