From b191cf36a73fae71221bd9acb29a089048096ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivana=20=C5=A0tef=C3=A1nikov=C3=A1=C3=A1=C5=A0=C3=A1?= Date: Sat, 12 Oct 2024 14:32:15 +0200 Subject: [PATCH] Changes based on review --- .../src/Pages/Monitors/Home/actionsMenu.jsx | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx index db57f44df..d2ccc0b88 100644 --- a/Client/src/Pages/Monitors/Home/actionsMenu.jsx +++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx @@ -3,6 +3,7 @@ import { useSelector, useDispatch } from "react-redux"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { createToast } from "../../../Utils/toastUtils"; +import { logger } from "../../../Utils/Logger"; import { Button, IconButton, @@ -47,24 +48,20 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => { } }; - const handlePause = async (event) => { + const handlePause = async () => { try { const action = await dispatch( pauseUptimeMonitor({ authToken, monitorId: monitor._id }) ); if (pauseUptimeMonitor.fulfilled.match(action)) { updateCallback(); - //window.location.reload(); - if (action.payload?.isActive === false){ - createToast({ body: "Monitor paused successfully." }); - }else{ - createToast({ body: "Monitor resumed successfully." }); - } + const state = action?.payload?.data.isActive === false ? "paused" : "resumed"; + createToast({ body: `Monitor ${state} successfully.` }); } else { - throw new Error(action.error.message); + throw new Error(action?.error?.message ?? "Failed to pause monitor."); } } catch (error) { - console.error("Error pausing monitor:", monitor._id, error); + logger.error("Error pausing monitor:", monitor._id, error); createToast({ body: "Failed to pause monitor." }); } }; @@ -187,11 +184,8 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => { handlePause(e); }} > - {monitor?.isActive ? ( - "Pause" - ) : ( - "Resume" - )} + {monitor?.isActive === true ? "Pause" : "Resume"} + )} {isAdmin && (