From 018b01f53c09130b8a3084e72e52163cfd955ae9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 27 Jun 2024 15:45:05 -0700 Subject: [PATCH] Redirected user to Monitors page after adding a new monitor --- Client/src/Pages/CreateNewMonitor/index.jsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Client/src/Pages/CreateNewMonitor/index.jsx b/Client/src/Pages/CreateNewMonitor/index.jsx index 127ec9766..19dd1386a 100644 --- a/Client/src/Pages/CreateNewMonitor/index.jsx +++ b/Client/src/Pages/CreateNewMonitor/index.jsx @@ -9,11 +9,13 @@ import { MenuItem, Select, Typography } from "@mui/material"; import { useSelector, useDispatch } from "react-redux"; import { createMonitorValidation } from "../../Validation/validation"; import { createMonitor } from "../../Features/Monitors/monitorsSlice"; +import { useNavigate } from "react-router-dom"; const CreateNewMonitor = () => { const MS_PER_MINUTE = 60000; const { user, authToken } = useSelector((state) => state.auth); const dispatch = useDispatch(); + const navigate = useNavigate(); const [errors, setErrors] = useState({}); @@ -76,7 +78,7 @@ const CreateNewMonitor = () => { // })); // }; - const handleCreateNewMonitor = (event) => { + const handleCreateNewMonitor = async (event) => { event.preventDefault(); //obj to submit let monitor = { @@ -102,7 +104,14 @@ const CreateNewMonitor = () => { // ...advancedSettings, // TODO frequency should be interval, then we can use spread interval: advancedSettings.frequency * MS_PER_MINUTE, }; - dispatch(createMonitor({ authToken, monitor })); + try { + const action = await dispatch(createMonitor({ authToken, monitor })); + if (action.meta.requestStatus === "fulfilled") { + navigate("/monitors"); + } + } catch (error) { + alert(error); + } } };