source: sources/client/src/hooks/useToggleAccountStatus.js

Last change on this file 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';
4
5const 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
39export default useToggleAccountStatus;
Note: See TracBrowser for help on using the repository browser.