finish implementation
This commit is contained in:
1 parent
13039ed2ff
commit
eedf2879ee
6 files changed
+52
-18
No files matched your search
@@ -1,14 +1,37 @@
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Box, Stack, styled, Typography } from "@mui/material";
|
import { Box, Stack, styled, Typography } from "@mui/material";
|
||||||
import Button from "../../Components/Button";
|
import Button from "../../Components/Button";
|
||||||
|
import ButtonSpinner from "../../Components/ButtonSpinner";
|
||||||
import Field from "../../Components/Inputs/Field";
|
import Field from "../../Components/Inputs/Field";
|
||||||
import Link from "../../Components/Link";
|
import Link from "../../Components/Link";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import Select from "../../Components/Inputs/Select";
|
||||||
import { logger } from "../../Utils/Logger";
|
import { logger } from "../../Utils/Logger";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { createToast } from "../../Utils/toastUtils";
|
||||||
|
import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
const Settings = () => {
|
const Settings = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
|
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
|
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const handleClearStats = async () => {
|
||||||
|
try {
|
||||||
|
const action = await dispatch(
|
||||||
|
deleteMonitorChecksByTeamId({ teamId: user.teamId, authToken })
|
||||||
|
);
|
||||||
|
|
||||||
|
if (deleteMonitorChecksByTeamId.fulfilled.match(action)) {
|
||||||
|
createToast({ body: "Stats cleared successfully" });
|
||||||
|
} else {
|
||||||
|
createToast({ body: "Failed to clear stats" });
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
createToast({ body: "Failed to clear stats" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const ConfigBox = styled("div")({
|
const ConfigBox = styled("div")({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@@ -100,9 +123,11 @@ const Settings = () => {
|
|||||||
/>
|
/>
|
||||||
<Box>
|
<Box>
|
||||||
<Typography>Clear all stats. This is irreversible.</Typography>
|
<Typography>Clear all stats. This is irreversible.</Typography>
|
||||||
<Button
|
<ButtonSpinner
|
||||||
|
isLoading={isLoading}
|
||||||
level="error"
|
level="error"
|
||||||
label="Clear all stats"
|
label="Clear all stats"
|
||||||
|
onClick={handleClearStats}
|
||||||
sx={{ mt: theme.spacing(4) }}
|
sx={{ mt: theme.spacing(4) }}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const {
|
|||||||
getTeamChecksParamValidation,
|
getTeamChecksParamValidation,
|
||||||
getTeamChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const { successMessages } = require("../utils/messages");
|
const { successMessages } = require("../utils/messages");
|
||||||
const SERVICE_NAME = "check";
|
const SERVICE_NAME = "check";
|
||||||
@@ -113,20 +113,27 @@ const deleteChecks = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteChecksByTeam = async (req, res, next) => {
|
const deleteChecksByTeamId = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const res = await deleteChecksByTeamParamValidation.validateAsync(
|
await deleteChecksByTeamIdParamValidation.validateAsync(req.params);
|
||||||
req.params
|
|
||||||
);
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
msg: successMessages.CHECK_DELETE,
|
|
||||||
data: { deletedCount: res },
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = "deleteChecksByTeam";
|
error.method = "deleteChecksByTeam";
|
||||||
error.status = 422;
|
error.status = 422;
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deletedCount = await req.db.deleteChecksByTeamId(req.params.teamId);
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: successMessages.CHECK_DELETE,
|
||||||
|
data: { deletedCount },
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
error.method = "deleteChecksByTeamId";
|
||||||
|
next(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -135,5 +142,5 @@ module.exports = {
|
|||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
deleteChecksByTeam,
|
deleteChecksByTeamId,
|
||||||
};
|
};
|
||||||
@@ -94,6 +94,7 @@ const {
|
|||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
|
deleteChecksByTeamId,
|
||||||
} = require("./modules/checkModule");
|
} = require("./modules/checkModule");
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -155,6 +156,7 @@ module.exports = {
|
|||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
|
deleteChecksByTeamId,
|
||||||
createAlert,
|
createAlert,
|
||||||
getAlertsByUserId,
|
getAlertsByUserId,
|
||||||
getAlertsByMonitorId,
|
getAlertsByMonitorId,
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ const deleteChecks = async (monitorId) => {
|
|||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const deleteChecksByTeam = async (teamId) => {
|
const deleteChecksByTeamId = async (teamId) => {
|
||||||
try {
|
try {
|
||||||
const teamMonitors = await Monitor.find({ teamId: teamId });
|
const teamMonitors = await Monitor.find({ teamId: teamId });
|
||||||
teamMonitors.forEach(async (monitor) => {
|
teamMonitors.forEach(async (monitor) => {
|
||||||
@@ -213,5 +213,5 @@ module.exports = {
|
|||||||
getChecks,
|
getChecks,
|
||||||
getTeamChecks,
|
getTeamChecks,
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
deleteChecksByTeam,
|
deleteChecksByTeamId,
|
||||||
};
|
};
|
||||||
@@ -23,7 +23,7 @@ router.delete(
|
|||||||
router.delete(
|
router.delete(
|
||||||
"/team/:teamId",
|
"/team/:teamId",
|
||||||
isAllowed(["admin", "superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
checkController.deleteChecks
|
checkController.deleteChecksByTeamId
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -292,7 +292,7 @@ const deleteChecksParamValidation = joi.object({
|
|||||||
monitorId: joi.string().required(),
|
monitorId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const deleteChecksByTeamParamValidation = joi.object({
|
const deleteChecksByTeamIdParamValidation = joi.object({
|
||||||
teamId: joi.string().required(),
|
teamId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ module.exports = {
|
|||||||
getTeamChecksParamValidation,
|
getTeamChecksParamValidation,
|
||||||
getTeamChecksQueryValidation,
|
getTeamChecksQueryValidation,
|
||||||
deleteChecksParamValidation,
|
deleteChecksParamValidation,
|
||||||
deleteChecksByTeamParamValidation,
|
deleteChecksByTeamIdParamValidation,
|
||||||
deleteUserParamValidation,
|
deleteUserParamValidation,
|
||||||
getPageSpeedCheckParamValidation,
|
getPageSpeedCheckParamValidation,
|
||||||
createPageSpeedCheckParamValidation,
|
createPageSpeedCheckParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user