remove settings hooks

This commit is contained in:
Alex Holliday committed 2026-02-09 23:28:46 +00:00
1 parent 2091d8dcd7
commit b817a16459
3 files changed
+36 -96

No files matched your search

+28 -15
View File
@@ -13,7 +13,7 @@ import SettingsExport from "./SettingsExport.jsx";
import Button from "@mui/material/Button";
// Utils
import { settingsValidation } from "@/Validation/validation.js";
import { useState } from "react";
import { useState, useEffect } from "react";
import { useTheme } from "@emotion/react";
import { useTranslation } from "react-i18next";
import { useSelector, useDispatch } from "react-redux";
@@ -26,9 +26,8 @@ import {
} from "@/Features/UI/uiSlice.js";
import SettingsStats from "./SettingsStats.jsx";
import { useFetchSettings, useSaveSettings } from "@/Hooks/settingsHooks";
import { useIsAdmin } from "@/Hooks/useIsAdmin.js";
import { usePost, useDelete, useLazyGet } from "@/Hooks/UseApi";
import { useGet, usePost, useDelete, useLazyGet, usePut } from "@/Hooks/UseApi";
// Constants
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
@@ -53,19 +52,33 @@ const Settings = () => {
const [emailPasswordHasBeenReset, setEmailPasswordHasBeenReset] = useState(false);
// Network
const [isSettingsLoading, settingsError] = useFetchSettings({
setSettingsData,
setIsApiKeySet,
setIsEmailPasswordSet,
});
const { data: fetchedSettings, isLoading: isSettingsLoading } = useGet("/settings");
const [isSaving, saveError, saveSettings] = useSaveSettings({
setSettingsData,
setIsApiKeySet,
setApiKeyHasBeenReset,
setIsEmailPasswordSet,
setEmailPasswordHasBeenReset,
});
useEffect(() => {
if (fetchedSettings) {
setSettingsData(fetchedSettings);
setIsApiKeySet(fetchedSettings?.pagespeedKeySet);
setIsEmailPasswordSet(fetchedSettings?.emailPasswordSet);
}
}, [fetchedSettings]);
const { put: saveSettingsFn, loading: isSaving } = usePut();
const saveSettings = async (settings) => {
const response = await saveSettingsFn("/settings", { settings });
if (response?.data) {
const data = response.data;
setIsApiKeySet(data.pagespeedKeySet);
setIsEmailPasswordSet(data.emailPasswordSet);
if (data.pagespeedKeySet === true) {
setApiKeyHasBeenReset(false);
}
if (data.emailPasswordSet === true) {
setEmailPasswordHasBeenReset(false);
}
setSettingsData(data);
}
};
// New API hooks to replace monitorHooks
const { post: postDemoMonitors, loading: isAddingDemoMonitors } = usePost();