From d8e7f9fc0f6d31d25f756f466fda804dedd318ab Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 18 Feb 2026 20:20:45 +0000 Subject: [PATCH] add pagespeed config --- client/src/Pages/Settings/index.tsx | 91 ++++++++++++++++++++++++++++- client/src/locales/en.json | 13 ++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/client/src/Pages/Settings/index.tsx b/client/src/Pages/Settings/index.tsx index c389c6159..979c013ff 100644 --- a/client/src/Pages/Settings/index.tsx +++ b/client/src/Pages/Settings/index.tsx @@ -9,7 +9,12 @@ import { useSelector, useDispatch } from "react-redux"; import DummyChart from "@/Pages/Settings/DummyChart"; import { useGet } from "@/Hooks/UseApi"; import { useSettingsForm } from "@/Hooks/useSettingsForm"; +import { useIsAdmin } from "@/Hooks/useIsAdmin.js"; import type { SettingsFormData } from "@/Validation/settings"; +import { useState } from "react"; +import { Controller } from "react-hook-form"; +import { TextField, Button } from "@/Components/v2/inputs"; +import { Typography, Box } from "@mui/material"; import { setTimezone, @@ -27,13 +32,26 @@ interface Timezone { name: string; } +interface SettingsResponse { + settings: any; + pagespeedKeySet: boolean; + emailPasswordSet: boolean; +} + export const SettingsPage = () => { const theme = useTheme(); const { t, i18n } = useTranslation(); const dispatch = useDispatch(); + const isAdmin = useIsAdmin(); // Fetch settings data from API - const { data: fetchedSettings } = useGet("/settings"); + const { data: fetchedSettings } = useGet("/settings"); + + // Local state for API key reset + const [isApiKeySet, setIsApiKeySet] = useState( + fetchedSettings?.pagespeedKeySet ?? false + ); + const [apiKeyHasBeenReset, setApiKeyHasBeenReset] = useState(false); // Initialize form with schema and defaults const { schema, defaults } = useSettingsForm({ data: fetchedSettings?.settings }); @@ -48,6 +66,13 @@ export const SettingsPage = () => { form.reset(defaults); }, [defaults, form]); + // Update isApiKeySet when fetchedSettings changes + useEffect(() => { + if (fetchedSettings) { + setIsApiKeySet(fetchedSettings.pagespeedKeySet); + } + }, [fetchedSettings]); + const { timezone: selectedTimezoneId, mode, @@ -81,6 +106,11 @@ export const SettingsPage = () => { dispatch(setChartType(e.target.value)); }; + const handleResetApiKey = () => { + form.setValue("pagespeedApiKey", ""); + setApiKeyHasBeenReset(true); + }; + const languages = Object.keys(i18n.options.resources || {}); return ( @@ -151,6 +181,65 @@ export const SettingsPage = () => { } /> + {isAdmin && ( + + {(isApiKeySet === false || apiKeyHasBeenReset === true) && ( + ( + + )} + /> + )} + + {isApiKeySet === true && apiKeyHasBeenReset === false && ( + + + {t("pages.settings.pageSpeedSettings.labelApiKeySet")} + + + + )} + + } + /> + )} + + + ); diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 8d4e62a57..8bae5dcd0 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -38,7 +38,8 @@ "toggleTheme": "Toggles light & dark", "flushQueue": "Flush queue", "notFound": "Go to the main dashboard", - "resetPassword": "Reset password" + "resetPassword": "Reset password", + "reset": "Reset" }, "charts": { "labels": { @@ -936,6 +937,16 @@ "heatmap": "Heatmap" } } + }, + "pagespeed": { + "title": "Google PageSpeed API key", + "description": "Enter your Google PageSpeed API key to enable Google PageSpeed monitoring. Click Reset to update the key.", + "option": { + "apiKey": { + "label": "PageSpeed API key", + "placeholder": "Enter your Google PageSpeed API key" + } + } } } },