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