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 useDeleteSession = () => {
|
---|
| 6 | const [isLoading, setIsLoading] = useState(false);
|
---|
| 7 | const { setAlert } = useContext(AccessoriesContext);
|
---|
| 8 |
|
---|
| 9 | const deleteSession = async ({ pssId, onDeleteSession }) => {
|
---|
| 10 | setIsLoading(true);
|
---|
| 11 | await axios
|
---|
| 12 | .delete(`/parkingSession/${pssId}`)
|
---|
| 13 | .then((res) => {
|
---|
| 14 | setAlert({
|
---|
| 15 | type: 'success',
|
---|
| 16 | msg: `Сесијата е успешно избришана!`, //
|
---|
| 17 | });
|
---|
| 18 |
|
---|
| 19 | onDeleteSession({ pssId });
|
---|
| 20 | })
|
---|
| 21 | .catch((err) => {
|
---|
| 22 | // ALERT FOR ERROR WITH ERROR MSG
|
---|
| 23 | setAlert({
|
---|
| 24 | type: 'error',
|
---|
| 25 | msg: 'Проблеми со серверот!', // TODO change msg to err.message
|
---|
| 26 | });
|
---|
| 27 | console.log(err);
|
---|
| 28 | })
|
---|
| 29 | .finally(() => {
|
---|
| 30 | setIsLoading(false);
|
---|
| 31 | });
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | return {
|
---|
| 35 | deleteSession,
|
---|
| 36 | isLoading,
|
---|
| 37 | };
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | export default useDeleteSession;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.