From a3a25b2adddda0e8c18585634a2cb3f1849114a4 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 19 Feb 2026 17:28:00 +0000 Subject: [PATCH] clear-stats --- client/src/Pages/Settings/index.tsx | 38 ++++++++++++++++++++++++++++- client/src/locales/en.json | 26 +++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/Settings/index.tsx b/client/src/Pages/Settings/index.tsx index da3142cfb..270e0a26f 100644 --- a/client/src/Pages/Settings/index.tsx +++ b/client/src/Pages/Settings/index.tsx @@ -1,5 +1,5 @@ import { BasePage, ConfigBox } from "@/Components/v2/design-elements"; -import { Autocomplete, Select } from "@/Components/v2/inputs"; +import { Autocomplete, Select, Dialog } from "@/Components/v2/inputs"; import { Stack, useTheme, MenuItem, type SelectChangeEvent } from "@mui/material"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; @@ -15,6 +15,7 @@ import { useState } from "react"; import { Controller } from "react-hook-form"; import { TextField, Button, FieldLabel } from "@/Components/v2/inputs"; import { Box } from "@mui/material"; +import { useDelete } from "@/Hooks/UseApi"; import { setTimezone, @@ -54,6 +55,9 @@ export const SettingsPage = () => { fetchedSettings?.pagespeedKeySet ?? false ); const [apiKeyHasBeenReset, setApiKeyHasBeenReset] = useState(false); + // Local state for clear stats dialog + const [isStatsDialogOpen, setIsStatsDialogOpen] = useState(false); + const { deleteFn: deleteStats, loading: isDeletingStats } = useDelete(); // Initialize form with schema and defaults const { schema, defaults } = useSettingsForm({ data: fetchedSettings?.settings }); @@ -113,6 +117,11 @@ export const SettingsPage = () => { setApiKeyHasBeenReset(true); }; + const handleClearStats = async () => { + await deleteStats("/checks/team"); + setIsStatsDialogOpen(false); + }; + const onSubmit = async (data: SettingsFormData) => { // Don't send pagespeedApiKey if it's already set and user hasn't clicked reset const dataToSend = { ...data }; @@ -306,8 +315,35 @@ export const SettingsPage = () => { /> } /> + + {/* Clear All Stats */} + {isAdmin && ( + setIsStatsDialogOpen(true)} + > + {t("common.buttons.clear")} + + } + /> + )} + {/* Clear Stats Confirmation Dialog */} + setIsStatsDialogOpen(false)} + onConfirm={handleClearStats} + loading={isDeletingStats} + /> + {/* Sticky Save Button */}