Files
Checkmate/Client/src/Pages/Uptime/utils.jsx
T

100 lines
2.9 KiB
React
Raw Normal View History

import { useTheme } from "@mui/material";
const useUtils = () => {
const determineState = (monitor) => {
if (monitor.isActive === false) return "paused";
if (monitor?.status === undefined) return "pending";
return monitor?.status == true ? "up" : "down";
};
2024-11-27 17:38:39 -05:00
/* TODO Refactor: from here on shouldn't live in a custom hook, but on theme, or constants */
const theme = useTheme();
const statusColor = {
2025-01-12 09:39:31 -05:00
up: theme.palette.success.lowContrast,
down: theme.palette.error.lowContrast,
paused: theme.palette.warning.lowContrast,
pending: theme.palette.warning.lowContrast,
};
const statusMsg = {
up: "Your site is up.",
down: "Your site is down.",
paused: "Pending...",
};
const pagespeedStatusMsg = {
up: "Live (collecting data)",
down: "Inactive",
paused: "Paused",
};
2025-01-11 11:49:02 -05:00
/* This is used on
1) Details > Gradient card */
2025-01-12 09:39:31 -05:00
/* These are rediections. We should do something that maps up to success, down to error, and get the theme by that
*/
const statusStyles = {
up: {
2025-01-12 09:39:31 -05:00
backgroundColor: theme.palette.success.lowContrast,
background: `linear-gradient(340deg, ${theme.palette.success.lowContrast} -60%, ${theme.palette.success.contrastText} 35%)`,
2025-01-11 11:49:02 -05:00
borderColor: theme.palette.success.contrastText,
"& h2": { color: theme.palette.success.main },
},
down: {
2025-01-12 09:39:31 -05:00
backgroundColor: theme.palette.error.lowContrast,
background: `linear-gradient(340deg, ${theme.palette.error.lowContrast} -60%, ${theme.palette.error.contrastText} 35%)`,
2025-01-11 11:49:02 -05:00
borderColor: theme.palette.error.contrastText,
"& h2": { color: theme.palette.error.main },
2025-01-11 11:49:02 -05:00
},
paused: {
2025-01-12 09:39:31 -05:00
backgroundColor: theme.palette.warning.lowContrast,
background: `linear-gradient(340deg, ${theme.palette.warning.lowContrast} -60%, ${theme.palette.warning.contrastText} 35%)`,
2025-01-11 11:49:02 -05:00
borderColor: theme.palette.warning.contrastText,
"& h2": { color: theme.palette.warning.main },
2025-01-11 11:49:02 -05:00
},
pending: {
2025-01-12 09:39:31 -05:00
backgroundColor: theme.palette.warning.lowContrast,
background: `linear-gradient(340deg, ${theme.palette.warning.lowContrast} -60%, ${theme.palette.warning.contrastText} 35%)`,
2025-01-11 11:49:02 -05:00
borderColor: theme.palette.warning.contrastText,
"& h2": { color: theme.palette.warning.main },
2025-01-11 11:49:02 -05:00
},
};
2025-01-12 09:39:31 -05:00
/* These are rediections. We should do something that maps up to success, down to error, and get the theme by that
*/
const pagespeedStyles = {
up: {
2024-11-10 17:00:13 -05:00
bg: theme.palette.success.dark,
light: theme.palette.success.light,
stroke: theme.palette.success.main,
},
down: {
2024-11-10 17:00:13 -05:00
bg: theme.palette.error.dark,
light: theme.palette.error.light,
stroke: theme.palette.error.main,
},
paused: {
2024-11-10 17:00:13 -05:00
bg: theme.palette.warning.dark,
light: theme.palette.warning.light,
stroke: theme.palette.warning.main,
},
pending: {
2024-11-10 17:00:13 -05:00
bg: theme.palette.warning.dark,
light: theme.palette.warning.light,
stroke: theme.palette.warning.main,
},
};
return {
determineState,
statusColor,
statusMsg,
pagespeedStatusMsg,
pagespeedStyles,
statusStyles,
};
};
export default useUtils;