From eedf2879ee52796aa4510cc40a8448d1769a60a4 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 30 Aug 2024 10:04:47 -0700 Subject: [PATCH] finish implementation --- Client/src/Pages/Settings/index.jsx | 29 ++++++++++++++++++++++++-- Server/controllers/checkController.js | 29 ++++++++++++++++---------- Server/db/mongo/MongoDB.js | 2 ++ Server/db/mongo/modules/checkModule.js | 4 ++-- Server/routes/checkRoute.js | 2 +- Server/validation/joi.js | 4 ++-- 6 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index d908e33c1..06bc00e1e 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -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 = () => { /> Clear all stats. This is irreversible. -