add isCreate flag to determine create/edit
This commit is contained in:
1 parent
f10b5b1e14
commit
55bd7d7973
1 file changed
+11
-3
@@ -1,12 +1,13 @@
|
|||||||
// React, Redux, Router
|
// React, Redux, Router
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
|
||||||
// Utility and Network
|
// Utility and Network
|
||||||
import { infrastructureMonitorValidation } from "../../../Validation/validation";
|
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 { capitalizeFirstLetter } from "../../../Utils/stringUtils";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -53,8 +54,15 @@ const CreateInfrastructureMonitor = () => {
|
|||||||
const monitorState = useSelector((state) => state.infrastructureMonitor);
|
const monitorState = useSelector((state) => state.infrastructureMonitor);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { monitorId } = useParams();
|
||||||
const { t } = useTranslation();
|
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
|
// State
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [https, setHttps] = useState(false);
|
const [https, setHttps] = useState(false);
|
||||||
|
|||||||
Reference in new issue
Block a user