diff --git a/Client/src/App.jsx b/Client/src/App.jsx index 88e1e7019..783f28330 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -39,6 +39,7 @@ function App() { const DetailsWithAdminProp = withAdminProp(Details); const PageSpeedWithAdminProp = withAdminProp(PageSpeed); const MaintenanceWithAdminProp = withAdminProp(Maintenance); + const SettingsWithAdminProp = withAdminProp(Settings); const mode = useSelector((state) => state.ui.mode); @@ -90,7 +91,7 @@ function App() { /> } + element={} /> { + try { + const { authToken, teamId } = data; + const res = await networkService.deleteChecksByTeamId(authToken, teamId); + return res.data; + } catch (error) { + if (error.response && error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + const payload = { + status: false, + msg: error.message ? error.message : "Unknown error", + }; + return thunkApi.rejectWithValue(payload); + } + } +); + const uptimeMonitorsSlice = createSlice({ name: "uptimeMonitors", initialState, @@ -256,6 +276,24 @@ const uptimeMonitorsSlice = createSlice({ : "Failed to delete uptime monitor"; }) // ***************************************************** + // Delete Monitor checks by Team ID + // ***************************************************** + .addCase(deleteMonitorChecksByTeamId.pending, (state) => { + state.isLoading = true; + }) + .addCase(deleteMonitorChecksByTeamId.fulfilled, (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; + }) + .addCase(deleteMonitorChecksByTeamId.rejected, (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to delete monitor checks"; + }) + // ***************************************************** // Pause Monitor // ***************************************************** .addCase(pauseUptimeMonitor.pending, (state) => { diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index d908e33c1..c0295b572 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -1,14 +1,38 @@ 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"; - -const Settings = () => { +import { useDispatch, useSelector } from "react-redux"; +import { createToast } from "../../Utils/toastUtils"; +import { deleteMonitorChecksByTeamId } from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; +import PropTypes from "prop-types"; +const Settings = ({ isAdmin }) => { 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", @@ -79,35 +103,39 @@ const Settings = () => { /> - - - History and monitoring - - Define here for how long you want to keep the data. You can also - remove all past data. - - - - logger.warn("Disabled")} - /> + {isAdmin && ( + - Clear all stats. This is irreversible. -