add hook for monitor contolrs
This commit is contained in:
1 parent
d48d3b9ff4
commit
04f75efa11
1 file changed
+30
@@ -0,0 +1,30 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { networkService } from "../main";
|
||||||
|
import { createToast } from "../Utils/toastUtils";
|
||||||
|
|
||||||
|
const usePauseMonitor = ({ monitorId, triggerUpdate }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(undefined);
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
const pauseMonitor = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(false);
|
||||||
|
const res = await networkService.pauseMonitorById({ monitorId });
|
||||||
|
setMonitor(res.data.data);
|
||||||
|
createToast({
|
||||||
|
body: res.data.data.isActive
|
||||||
|
? "Monitor resumed successfully"
|
||||||
|
: "Monitor paused successfully",
|
||||||
|
});
|
||||||
|
triggerUpdate();
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [pauseMonitor, isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
|
export { usePauseMonitor };
|
||||||
Reference in new issue
Block a user