This commit is contained in:
Alex Holliday committed 2026-02-19 17:55:55 +00:00
1 parent 216c7753b4
commit f2779160a1
3 files changed
+41 -11

No files matched your search

+4 -4
View File
@@ -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: "",
+33 -3
View File
@@ -65,6 +65,7 @@ export const SettingsPage = () => {
const form = useForm<SettingsFormData>({
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")}
</Button>
}
/>
@@ -347,6 +350,13 @@ export const SettingsPage = () => {
render={({ field, fieldState }) => (
<TextField
{...field}
value={
field.value === undefined || field.value === 0 ? "" : field.value
}
onChange={(e) => {
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 }) => (
<TextField
{...field}
value={
field.value === undefined || field.value === 0 ? "" : field.value
}
onChange={(e) => {
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 }) => (
<TextField
{...field}
value={
field.value === undefined || field.value === 0 ? "" : field.value
}
onChange={(e) => {
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 }) => (
<TextField
{...field}
value={
field.value === undefined || field.value === 0 ? "" : field.value
}
onChange={(e) => {
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")}
</Button>
</Stack>
<pre>{JSON.stringify(form.formState.isValid, null, 2)}</pre>
</BasePage>
);
};
+4 -4
View File
@@ -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(),
});