initial commit

This commit is contained in:
Alex Holliday committed 2026-02-18 18:47:58 +00:00
1 parent 7cfbc85d9b
commit 8cbde4a705
5 files changed
+95 -62

No files matched your search

@@ -75,7 +75,6 @@ const SettingsStats = ({ isAdmin, HEADING_SX, errors }) => {
SettingsStats.propTypes = {
isAdmin: PropTypes.bool,
HEADING_SX: PropTypes.object,
errors: PropTypes.object,
};
export default SettingsStats;
+19 -6
View File
@@ -12,7 +12,6 @@ import SettingsGlobalThresholds from "./SettingsGlobalThresholds.jsx";
import SettingsExport from "./SettingsExport.jsx";
import Button from "@mui/material/Button";
// Utils
import { settingsValidation } from "@/Validation/validation.js";
import { Controller, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useSettingsForm } from "@/Hooks/useSettingsForm.js";
@@ -31,7 +30,6 @@ const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
const Settings = () => {
const { data: fetchedSettings, isLoading: isSettingsLoading } = useGet("/settings");
// Local state
const [errors, setErrors] = useState({});
const [isApiKeySet, setIsApiKeySet] = useState(
fetchedSettings?.pagespeedKeySet ?? false
);
@@ -60,7 +58,7 @@ const Settings = () => {
formState: { dirtyFields },
} = form;
useEffect(() => {
reset(defaults);
reset(defaults, { keepDirtyValues: false });
}, [defaults, reset]);
useEffect(() => {
@@ -88,7 +86,23 @@ const Settings = () => {
};
const onSubmit = async (data) => {
const toSubmit = { ...data };
// Convert undefined to empty strings for proper unsetting on backend
const toSubmit = Object.fromEntries(
Object.entries(data).map(([key, value]) => {
if (value === undefined) return [key, ""];
if (typeof value === "object" && value !== null) {
// Handle nested objects like globalThresholds
return [
key,
Object.fromEntries(
Object.entries(value).map(([k, v]) => [k, v === undefined ? "" : v])
),
];
}
return [key, value];
})
);
if (!form.formState.dirtyFields.systemEmailPassword) {
delete toSubmit.systemEmailPassword;
}
@@ -135,7 +149,6 @@ const Settings = () => {
<SettingsStats
isAdmin={isAdmin}
HEADING_SX={HEADING_SX}
errors={errors}
/>
<SettingsGlobalThresholds
isAdmin={isAdmin}
@@ -195,7 +208,7 @@ const Settings = () => {
loading={
isSaving || isDeletingMonitorStats || isSettingsLoading || isDeletingMonitors
}
disabled={Object.keys(errors).length > 0}
disabled={!form.formState.isValid}
variant="contained"
color="accent"
sx={{ px: theme.spacing(12), py: theme.spacing(8) }}