Redirected user to Monitors page after adding a new monitor
This commit is contained in:
1 parent
1d720a20c2
commit
018b01f53c
1 file changed
+11
-2
@@ -9,11 +9,13 @@ import { MenuItem, Select, Typography } from "@mui/material";
|
|||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { createMonitorValidation } from "../../Validation/validation";
|
import { createMonitorValidation } from "../../Validation/validation";
|
||||||
import { createMonitor } from "../../Features/Monitors/monitorsSlice";
|
import { createMonitor } from "../../Features/Monitors/monitorsSlice";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
const CreateNewMonitor = () => {
|
const CreateNewMonitor = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ const CreateNewMonitor = () => {
|
|||||||
// }));
|
// }));
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const handleCreateNewMonitor = (event) => {
|
const handleCreateNewMonitor = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
//obj to submit
|
//obj to submit
|
||||||
let monitor = {
|
let monitor = {
|
||||||
@@ -102,7 +104,14 @@ const CreateNewMonitor = () => {
|
|||||||
// ...advancedSettings, // TODO frequency should be interval, then we can use spread
|
// ...advancedSettings, // TODO frequency should be interval, then we can use spread
|
||||||
interval: advancedSettings.frequency * MS_PER_MINUTE,
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user