use utils hook
This commit is contained in:
1 parent
d4164417da
commit
68202dc88b
1 file changed
+2
-25
@@ -3,30 +3,7 @@ import { networkService } from "../../../../main";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
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 {
|
|
||||||
...monitor,
|
|
||||||
percentage: uptimePercentage,
|
|
||||||
percentageColor,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const useStatusPageFetch = (isCreate = false) => {
|
const useStatusPageFetch = (isCreate = false) => {
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
@@ -35,7 +12,7 @@ const useStatusPageFetch = (isCreate = false) => {
|
|||||||
const [monitors, setMonitors] = useState(undefined);
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
const fetchStatusPage = useCallback(async () => {
|
const fetchStatusPage = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await networkService.getStatusPage({ authToken });
|
const response = await networkService.getStatusPage({ authToken });
|
||||||
|
|||||||
Reference in new issue
Block a user