From 55bd7d797309224bbfd4fa22f739a4bade35214c Mon Sep 17 00:00:00 2001 From: Vishnu Sreekumaran Nair <200557136@student.georgianc.on.ca> Date: Fri, 14 Mar 2025 22:12:52 -0400 Subject: [PATCH] add isCreate flag to determine create/edit --- src/Pages/Infrastructure/Create/index.jsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Pages/Infrastructure/Create/index.jsx b/src/Pages/Infrastructure/Create/index.jsx index 2c2a5505f..69e8e480a 100644 --- a/src/Pages/Infrastructure/Create/index.jsx +++ b/src/Pages/Infrastructure/Create/index.jsx @@ -1,12 +1,13 @@ // React, Redux, Router import { useTheme } from "@emotion/react"; -import { useNavigate } from "react-router-dom"; -import { useState } from "react"; +import { useNavigate, useParams } from "react-router-dom"; +import { useState, useEffect } from "react"; import { useSelector, useDispatch } from "react-redux"; // Utility and Network import { infrastructureMonitorValidation } from "../../../Validation/validation"; -import { createInfrastructureMonitor } from "../../../Features/InfrastructureMonitors/infrastructureMonitorsSlice"; +import { createInfrastructureMonitor, updateInfrastructureMonitor } from "../../../Features/InfrastructureMonitors/infrastructureMonitorsSlice"; +import { useHardwareMonitorsFetch } from "../Details/Hooks/useHardwareMonitorsFetch"; import { capitalizeFirstLetter } from "../../../Utils/stringUtils"; import { useTranslation } from "react-i18next"; @@ -53,7 +54,14 @@ const CreateInfrastructureMonitor = () => { const monitorState = useSelector((state) => state.infrastructureMonitor); const dispatch = useDispatch(); const navigate = useNavigate(); - const { t } = useTranslation(); + const { monitorId } = useParams(); + const { t } = useTranslation(); + + // Determine if we are creating or editing + const isCreate = typeof monitorId === "undefined"; + + // Fetch monitor details if editing + const { monitor, isLoading, networkError } = useHardwareMonitorsFetch({ monitorId }); // State const [errors, setErrors] = useState({});