use new utils hook
This commit is contained in:
1 parent
4122849723
commit
d4164417da
1 file changed
+2
-29
@@ -2,34 +2,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { networkService } from "../../../../main";
|
import { networkService } from "../../../../main";
|
||||||
import { createToast } from "../../../../Utils/toastUtils";
|
import { createToast } from "../../../../Utils/toastUtils";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
const getMonitorWithPercentage = (monitor, theme) => {
|
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
|
||||||
let uptimePercentage = "";
|
|
||||||
let percentageColor = "";
|
|
||||||
|
|
||||||
if (monitor.uptimePercentage !== undefined) {
|
|
||||||
uptimePercentage =
|
|
||||||
monitor.uptimePercentage === 0 ? "0" : (monitor.uptimePercentage * 100).toFixed(2);
|
|
||||||
|
|
||||||
percentageColor =
|
|
||||||
monitor.uptimePercentage < 0.25
|
|
||||||
? theme.palette.error.main
|
|
||||||
: monitor.uptimePercentage < 0.5
|
|
||||||
? theme.palette.warning.main
|
|
||||||
: monitor.uptimePercentage < 0.75
|
|
||||||
? theme.palette.success.main
|
|
||||||
: theme.palette.success.main;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: monitor._id,
|
|
||||||
name: monitor.name,
|
|
||||||
url: monitor.url,
|
|
||||||
title: monitor.name,
|
|
||||||
percentage: uptimePercentage,
|
|
||||||
percentageColor,
|
|
||||||
monitor: monitor,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMonitorFetch = ({
|
export const useMonitorFetch = ({
|
||||||
authToken,
|
authToken,
|
||||||
@@ -49,7 +22,7 @@ export const useMonitorFetch = ({
|
|||||||
const [networkError, setNetworkError] = useState(false);
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user