From f2779160a1c1a0ad7397b59ecf313f17029c6b93 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 19 Feb 2026 17:55:55 +0000 Subject: [PATCH] port --- client/src/Hooks/useSettingsForm.ts | 8 +++---- client/src/Pages/Settings/index.tsx | 36 ++++++++++++++++++++++++++--- client/src/Validation/settings.ts | 8 +++---- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/client/src/Hooks/useSettingsForm.ts b/client/src/Hooks/useSettingsForm.ts index ee4227970..ce04a81e2 100644 --- a/client/src/Hooks/useSettingsForm.ts +++ b/client/src/Hooks/useSettingsForm.ts @@ -22,10 +22,10 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) => systemEmailTLSServername: data?.systemEmailTLSServername || "", systemEmailPort: data?.systemEmailPort, globalThresholds: { - cpu: data?.globalThresholds?.cpu, - memory: data?.globalThresholds?.memory, - disk: data?.globalThresholds?.disk, - temperature: data?.globalThresholds?.temperature, + cpu: data?.globalThresholds?.cpu ?? 0, + memory: data?.globalThresholds?.memory ?? 0, + disk: data?.globalThresholds?.disk ?? 0, + temperature: data?.globalThresholds?.temperature ?? 0, }, checkTTL: data?.checkTTL ?? 30, pagespeedApiKey: "", diff --git a/client/src/Pages/Settings/index.tsx b/client/src/Pages/Settings/index.tsx index b5d93b12e..66fb65f8d 100644 --- a/client/src/Pages/Settings/index.tsx +++ b/client/src/Pages/Settings/index.tsx @@ -65,6 +65,7 @@ export const SettingsPage = () => { const form = useForm({ resolver: zodResolver(schema), defaultValues: defaults, + mode: "onChange", }); // Reset form when defaults change @@ -136,10 +137,12 @@ export const SettingsPage = () => { (acc as any)[typedKey] = ""; } else if (typeof value === "object" && value !== null) { // Handle nested objects like globalThresholds + // Convert 0 to "" for unsetting thresholds (acc as any)[typedKey] = Object.entries(value).reduce( (nested, [nestedKey, nestedValue]) => ({ ...nested, - [nestedKey]: nestedValue === undefined ? "" : nestedValue, + [nestedKey]: + nestedValue === undefined || nestedValue === 0 ? "" : nestedValue, }), {} ); @@ -327,7 +330,7 @@ export const SettingsPage = () => { color="error" onClick={() => setIsStatsDialogOpen(true)} > - {t("pages.settings.form.stats.buttonText")} + {t("common.buttons.clear")} } /> @@ -347,6 +350,13 @@ export const SettingsPage = () => { render={({ field, fieldState }) => ( { + const val = e.target.value; + field.onChange(val === "" ? 0 : Number(val)); + }} fieldLabel={t("pages.settings.form.thresholds.option.cpu.label")} type="number" placeholder={t( @@ -364,6 +374,13 @@ export const SettingsPage = () => { render={({ field, fieldState }) => ( { + const val = e.target.value; + field.onChange(val === "" ? 0 : Number(val)); + }} fieldLabel={t("pages.settings.form.thresholds.option.memory.label")} type="number" placeholder={t( @@ -381,6 +398,13 @@ export const SettingsPage = () => { render={({ field, fieldState }) => ( { + const val = e.target.value; + field.onChange(val === "" ? 0 : Number(val)); + }} fieldLabel={t("pages.settings.form.thresholds.option.disk.label")} type="number" placeholder={t( @@ -398,6 +422,13 @@ export const SettingsPage = () => { render={({ field, fieldState }) => ( { + const val = e.target.value; + field.onChange(val === "" ? 0 : Number(val)); + }} fieldLabel={t( "pages.settings.form.thresholds.option.temperature.label" )} @@ -452,7 +483,6 @@ export const SettingsPage = () => { {t("common.buttons.save")} -
{JSON.stringify(form.formState.isValid, null, 2)}
); }; diff --git a/client/src/Validation/settings.ts b/client/src/Validation/settings.ts index 25390b241..5f6a06fd1 100644 --- a/client/src/Validation/settings.ts +++ b/client/src/Validation/settings.ts @@ -42,10 +42,10 @@ export const settingsSchema = z.object({ .optional(), globalThresholds: z .object({ - cpu: z.number().int().min(0).max(100).optional(), - memory: z.number().int().min(0).max(100).optional(), - disk: z.number().int().min(0).max(100).optional(), - temperature: z.number().int().min(0).max(150).optional(), + cpu: z.number().int().min(0).max(100), + memory: z.number().int().min(0).max(100), + disk: z.number().int().min(0).max(100), + temperature: z.number().int().min(0).max(150), }) .optional(), });