Resolve conflicts, update create monitor

This commit is contained in:
Alex Holliday committed 2024-09-06 10:09:13 -07:00
1 parent f80f531de7
commit f85c2d001a
2 files changed
+17 -6

No files matched your search

@@ -13,6 +13,7 @@ import Field from "../../../Components/Inputs/Field";
import Select from "../../../Components/Inputs/Select"; import Select from "../../../Components/Inputs/Select";
import Checkbox from "../../../Components/Inputs/Checkbox"; import Checkbox from "../../../Components/Inputs/Checkbox";
import Breadcrumbs from "../../../Components/Breadcrumbs"; import Breadcrumbs from "../../../Components/Breadcrumbs";
import { getUptimeMonitorById } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
import "./index.css"; import "./index.css";
const CreateMonitor = () => { const CreateMonitor = () => {
@@ -43,12 +44,14 @@ const CreateMonitor = () => {
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
useEffect(() => { useEffect(() => {
const fetchMonitor = async () => {
if (monitorId) { if (monitorId) {
const data = monitors.find((monitor) => monitor._id === monitorId); const action = await dispatch(
if (!data) { getUptimeMonitorById({ authToken, monitorId })
console.error("Error fetching monitor of id: " + monitorId); );
navigate("/not-found", { replace: true });
} if (action.payload.success) {
const data = action.payload.data;
const { name, ...rest } = data; //data.name is read-only const { name, ...rest } = data; //data.name is read-only
if (rest.type === "http") { if (rest.type === "http") {
const url = new URL(rest.url); const url = new URL(rest.url);
@@ -59,7 +62,15 @@ const CreateMonitor = () => {
setMonitor({ setMonitor({
...rest, ...rest,
}); });
} else {
navigate("/not-found", { replace: true });
createToast({
body: "There was an error cloning the monitor.",
});
} }
}
};
fetchMonitor();
}, [monitorId, authToken, monitors]); }, [monitorId, authToken, monitors]);
const handleChange = (event, name) => { const handleChange = (event, name) => {
@@ -140,7 +140,7 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
<MenuItem <MenuItem
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
navigate(`/monitors/clone/${actions.id}`); navigate(`/monitors/create/${actions.id}`);
}} }}
> >
Clone Clone