Made the code more readable by separation of tasks.

This commit is contained in:
Owaise Imdad committed 2025-05-21 22:55:34 +05:30
1 parent dab2bb466f
commit deec5a096e
1 file changed
+14 -3
+14 -3
View File
@@ -101,7 +101,6 @@ const Configure = () => {
const action = await dispatch(getUptimeMonitorById({ monitorId })); const action = await dispatch(getUptimeMonitorById({ monitorId }));
if (getUptimeMonitorById.fulfilled.match(action)) { if (getUptimeMonitorById.fulfilled.match(action)) {
const monitor = action.payload.data; const monitor = action.payload.data;
console.log("Monitor fetched: ", monitor);
setMonitor(monitor); setMonitor(monitor);
} else if (getUptimeMonitorById.rejected.match(action)) { } else if (getUptimeMonitorById.rejected.match(action)) {
throw new Error(action.error.message); throw new Error(action.error.message);
@@ -221,11 +220,23 @@ const Configure = () => {
}; };
const statusMsg = { const statusMsg = {
pause: "Monitoring is paused.",
true: "Your site is up.", true: "Your site is up.",
false: "Your site is down.", false: "Your site is down.",
undefined: "Pending...", undefined: "Pending...",
}; };
const getStatusColor = (monitor) => {
if (monitor?.isActive === false || monitor?.status == false) return "false";
return monitor?.isActive || String(monitor?.status);
};
const getStatusMsg = (monitor) => {
if (monitor?.isActive === false) return "pause";
if (monitor?.status === false) return "false";
return monitor?.isActive || String(monitor?.status);
};
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
@@ -269,7 +280,7 @@ const Configure = () => {
gap={theme.spacing(2)} gap={theme.spacing(2)}
> >
<Tooltip <Tooltip
title={statusMsg[monitor?.isActive ?? undefined]} title={statusMsg[getStatusMsg(monitor)]}
disableInteractive disableInteractive
slotProps={{ slotProps={{
popper: { popper: {
@@ -285,7 +296,7 @@ const Configure = () => {
}} }}
> >
<Box> <Box>
<PulseDot color={statusColor[monitor?.isActive ?? undefined]} /> <PulseDot color={statusColor[getStatusColor(monitor)]} />
</Box> </Box>
</Tooltip> </Tooltip>
<Typography <Typography