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.4 KB
|
Rev | Line | |
---|
[bc20307] | 1 | import { useContext } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 | import { AccessoriesContext } from '../context/AccessoriesContext';
|
---|
| 4 | import { UserContext } from '../context/UserContext';
|
---|
| 5 |
|
---|
| 6 | const useDeleteUserPlate = () => {
|
---|
| 7 | const { user } = useContext(UserContext);
|
---|
| 8 | const { setAlert } = useContext(AccessoriesContext);
|
---|
| 9 | const deleteUserPlate = async ({
|
---|
| 10 | deletePlate,
|
---|
| 11 | plate,
|
---|
| 12 | ind,
|
---|
| 13 | setIsLoadingDeletePlate,
|
---|
| 14 | }) => {
|
---|
| 15 | setIsLoadingDeletePlate({ state: true, itemInd: ind });
|
---|
| 16 | await axios
|
---|
| 17 | .delete(`/registriranParkirac/${user.id}/tablici/${plate}`) // TODO CHANGE OBJECT
|
---|
| 18 | .then((res) => {
|
---|
| 19 | setAlert({
|
---|
| 20 | type: 'success',
|
---|
| 21 | msg: `Таблицата е успешно избришана!`, // TODO Change MSG
|
---|
| 22 | });
|
---|
| 23 | deletePlate(plate); // or res.plate
|
---|
| 24 | })
|
---|
| 25 | .catch((err) => {
|
---|
| 26 | // ALERT FOR ERROR WITH ERROR MSG
|
---|
| 27 | setAlert({
|
---|
| 28 | type: 'error',
|
---|
| 29 | msg: 'Проблеми со серверот!', // TODO change msg to err.message
|
---|
| 30 | });
|
---|
| 31 | })
|
---|
| 32 | .finally(() => {
|
---|
| 33 | setIsLoadingDeletePlate({ state: false, itemInd: null });
|
---|
| 34 | });
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | return {
|
---|
| 38 | deleteUserPlate,
|
---|
| 39 | };
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | export default useDeleteUserPlate;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.