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
+28 -17

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,23 +44,33 @@ const CreateMonitor = () => {
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
useEffect(() => { useEffect(() => {
if (monitorId) { const fetchMonitor = async () => {
const data = monitors.find((monitor) => monitor._id === monitorId); if (monitorId) {
if (!data) { const action = await dispatch(
console.error("Error fetching monitor of id: " + monitorId); getUptimeMonitorById({ authToken, monitorId })
navigate("/not-found", { replace: true }); );
if (action.payload.success) {
const data = action.payload.data;
const { name, ...rest } = data; //data.name is read-only
if (rest.type === "http") {
const url = new URL(rest.url);
rest.url = url.host;
}
rest.name = `${name} (Clone)`;
rest.interval /= MS_PER_MINUTE;
setMonitor({
...rest,
});
} else {
navigate("/not-found", { replace: true });
createToast({
body: "There was an error cloning the monitor.",
});
}
} }
const { name, ...rest } = data; //data.name is read-only };
if (rest.type === "http") { fetchMonitor();
const url = new URL(rest.url);
rest.url = url.host;
}
rest.name = `${name} (Clone)`;
rest.interval /= MS_PER_MINUTE;
setMonitor({
...rest,
});
}
}, [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