mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-04-25 10:28:29 -05:00
finish implementation
This commit is contained in:
@@ -1,14 +1,37 @@
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { Box, Stack, styled, Typography } from "@mui/material";
|
||||
import Button from "../../Components/Button";
|
||||
import ButtonSpinner from "../../Components/ButtonSpinner";
|
||||
import Field from "../../Components/Inputs/Field";
|
||||
import Link from "../../Components/Link";
|
||||
import Select from "../../Components/Inputs/Select";
|
||||
import { logger } from "../../Utils/Logger";
|
||||
import "./index.css";
|
||||
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { createToast } from "../../Utils/toastUtils";
|
||||
import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||
const Settings = () => {
|
||||
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")({
|
||||
display: "flex",
|
||||
@@ -100,9 +123,11 @@ const Settings = () => {
|
||||
/>
|
||||
<Box>
|
||||
<Typography>Clear all stats. This is irreversible.</Typography>
|
||||
<Button
|
||||
<ButtonSpinner
|
||||
isLoading={isLoading}
|
||||
level="error"
|
||||
label="Clear all stats"
|
||||
onClick={handleClearStats}
|
||||
sx={{ mt: theme.spacing(4) }}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
@@ -6,7 +6,7 @@ const {
|
||||
getTeamChecksParamValidation,
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
} = require("../validation/joi");
|
||||
const { successMessages } = require("../utils/messages");
|
||||
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 {
|
||||
const res = await deleteChecksByTeamParamValidation.validateAsync(
|
||||
req.params
|
||||
);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.CHECK_DELETE,
|
||||
data: { deletedCount: res },
|
||||
});
|
||||
await deleteChecksByTeamIdParamValidation.validateAsync(req.params);
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "deleteChecksByTeam";
|
||||
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,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeam,
|
||||
deleteChecksByTeamId,
|
||||
};
|
||||
|
||||
@@ -94,6 +94,7 @@ const {
|
||||
getChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeamId,
|
||||
} = require("./modules/checkModule");
|
||||
|
||||
//****************************************
|
||||
@@ -155,6 +156,7 @@ module.exports = {
|
||||
getChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeamId,
|
||||
createAlert,
|
||||
getAlertsByUserId,
|
||||
getAlertsByMonitorId,
|
||||
|
||||
@@ -194,7 +194,7 @@ const deleteChecks = async (monitorId) => {
|
||||
* @throws {Error}
|
||||
*/
|
||||
|
||||
const deleteChecksByTeam = async (teamId) => {
|
||||
const deleteChecksByTeamId = async (teamId) => {
|
||||
try {
|
||||
const teamMonitors = await Monitor.find({ teamId: teamId });
|
||||
teamMonitors.forEach(async (monitor) => {
|
||||
@@ -213,5 +213,5 @@ module.exports = {
|
||||
getChecks,
|
||||
getTeamChecks,
|
||||
deleteChecks,
|
||||
deleteChecksByTeam,
|
||||
deleteChecksByTeamId,
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ router.delete(
|
||||
router.delete(
|
||||
"/team/:teamId",
|
||||
isAllowed(["admin", "superadmin"]),
|
||||
checkController.deleteChecks
|
||||
checkController.deleteChecksByTeamId
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -292,7 +292,7 @@ const deleteChecksParamValidation = joi.object({
|
||||
monitorId: joi.string().required(),
|
||||
});
|
||||
|
||||
const deleteChecksByTeamParamValidation = joi.object({
|
||||
const deleteChecksByTeamIdParamValidation = joi.object({
|
||||
teamId: joi.string().required(),
|
||||
});
|
||||
|
||||
@@ -376,7 +376,7 @@ module.exports = {
|
||||
getTeamChecksParamValidation,
|
||||
getTeamChecksQueryValidation,
|
||||
deleteChecksParamValidation,
|
||||
deleteChecksByTeamParamValidation,
|
||||
deleteChecksByTeamIdParamValidation,
|
||||
deleteUserParamValidation,
|
||||
getPageSpeedCheckParamValidation,
|
||||
createPageSpeedCheckParamValidation,
|
||||
|
||||
Reference in New Issue
Block a user