fix(client): render settings tab panels conditionally

Code review caught that the tab panels never hid.

Each panel was a `<Stack hidden={activeTab !== key}>`. The `hidden`
attribute reaches the DOM, but the only rule acting on it is the user
agent's `[hidden] { display: none }`, and MUI's Stack sets
`display: flex` in an author-level emotion class
(@mui/system/Stack/createStack.js:70). Author origin beats user agent
regardless of specificity, so every panel stayed visible: all five tabs
rendered stacked down the page and clicking a tab changed nothing.

Panels are now conditionally rendered, matching Pages/Account. This also
fixes a second defect: BasePage wraps children in `Stack spacing`, whose
sibling selector keys on DOM position rather than visibility, so the four
empty panels a non-admin never sees still collected a margin-top each and
left four blank gaps below "About".

My commit message for the previous commit argued panels had to stay
mounted or a partial tree would compute a stale `isValid` and lock
saving. That was wrong. No Form*Field passes `shouldUnregister`, and
react-hook-form defaults it to false, so unmounting a panel preserves its
values and validation state.

Also moves the tab-reveal off `onError`, which was unreachable: the save
button is `disabled={!isValid}` under `mode: "onChange"`, so
handleSubmit's error branch never fires. The validation Alert renders
straight from `formState.errors`, so a field on a hidden tab could be
named with no way to reach it. Each field in the Alert is now a button
that switches to its own tab.

Claude-Session: https://claude.ai/code/session_01AbYLvwpEaZFXktHVcqrFRd
This commit is contained in:
gorkem-bwl committed 2026-08-28 21:36:10 -04:00
1 parent 9d0f0116f3
commit d59bdf6c0c
1 file changed
+43 -31
+43 -31
View File
@@ -347,15 +347,17 @@ export const SettingsPage = () => {
const onError = (errors: unknown) => { const onError = (errors: unknown) => {
logger.debug("Form validation errors", errors); logger.debug("Form validation errors", errors);
// The save bar lists errors by field name, so reveal the tab owning the };
// first one rather than naming a field the user cannot see.
const firstField = Object.keys(errors ?? {})[0]; // The save bar lists errors by field name, and the offending field may sit on
if (firstField) { // a tab that is not open. Submitting cannot reveal it -- the button is
const target = tabForField(firstField); // disabled while the form is invalid -- so each listed field switches to its
// own tab instead.
const revealField = (field: string) => {
const target = tabForField(field);
if (visibleTabs.some((tab) => tab.key === target)) { if (visibleTabs.some((tab) => tab.key === target)) {
handleTabChange(target); handleTabChange(target);
} }
}
}; };
const languages = Object.keys(i18n.options.resources || {}); const languages = Object.keys(i18n.options.resources || {});
@@ -398,10 +400,8 @@ export const SettingsPage = () => {
)} )}
{/* general tab */} {/* general tab */}
<Stack {activeTab === "general" && (
gap={theme.spacing(LAYOUT.MD)} <Stack gap={theme.spacing(LAYOUT.MD)}>
hidden={activeTab !== "general"}
>
<ConfigBox <ConfigBox
title={t("pages.settings.form.timezone.title")} title={t("pages.settings.form.timezone.title")}
subtitle={t("pages.settings.form.timezone.description")} subtitle={t("pages.settings.form.timezone.description")}
@@ -505,12 +505,11 @@ export const SettingsPage = () => {
} }
/> />
</Stack> </Stack>
)}
{/* monitoring tab */} {/* monitoring tab */}
<Stack {activeTab === "monitoring" && (
gap={theme.spacing(LAYOUT.MD)} <Stack gap={theme.spacing(LAYOUT.MD)}>
hidden={activeTab !== "monitoring"}
>
{/* Global Thresholds */} {/* Global Thresholds */}
{isAdmin && ( {isAdmin && (
<ConfigBox <ConfigBox
@@ -601,12 +600,11 @@ export const SettingsPage = () => {
/> />
)} )}
</Stack> </Stack>
)}
{/* email tab */} {/* email tab */}
<Stack {activeTab === "email" && (
gap={theme.spacing(LAYOUT.MD)} <Stack gap={theme.spacing(LAYOUT.MD)}>
hidden={activeTab !== "email"}
>
{/* Email Settings - Admin Only */} {/* Email Settings - Admin Only */}
{isAdmin && ( {isAdmin && (
<ConfigBox <ConfigBox
@@ -646,12 +644,14 @@ export const SettingsPage = () => {
pass: "<your_password>", pass: "<your_password>",
}, },
name: name:
form.watch("systemEmailConnectionHost") || "localhost", form.watch("systemEmailConnectionHost") ||
"localhost",
pool: form.watch("systemEmailPool") ?? false, pool: form.watch("systemEmailPool") ?? false,
tls: { tls: {
rejectUnauthorized: rejectUnauthorized:
form.watch("systemEmailRejectUnauthorized") ?? true, form.watch("systemEmailRejectUnauthorized") ?? true,
ignoreTLS: form.watch("systemEmailIgnoreTLS") ?? false, ignoreTLS:
form.watch("systemEmailIgnoreTLS") ?? false,
requireTLS: requireTLS:
form.watch("systemEmailRequireTLS") ?? false, form.watch("systemEmailRequireTLS") ?? false,
servername: servername:
@@ -761,7 +761,9 @@ export const SettingsPage = () => {
{/* TLS Servername (Optional) */} {/* TLS Servername (Optional) */}
<FormTextField <FormTextField
name="systemEmailTLSServername" name="systemEmailTLSServername"
fieldLabel={t("pages.settings.form.email.option.tlsServername.label")} fieldLabel={t(
"pages.settings.form.email.option.tlsServername.label"
)}
placeholder={t( placeholder={t(
"pages.settings.form.email.option.tlsServername.placeholder" "pages.settings.form.email.option.tlsServername.placeholder"
)} )}
@@ -815,12 +817,11 @@ export const SettingsPage = () => {
/> />
)} )}
</Stack> </Stack>
)}
{/* integrations tab */} {/* integrations tab */}
<Stack {activeTab === "integrations" && (
gap={theme.spacing(LAYOUT.MD)} <Stack gap={theme.spacing(LAYOUT.MD)}>
hidden={activeTab !== "integrations"}
>
{isAdmin && ( {isAdmin && (
<ConfigBox <ConfigBox
title={t("pages.settings.form.globalProxy.title")} title={t("pages.settings.form.globalProxy.title")}
@@ -863,7 +864,9 @@ export const SettingsPage = () => {
<FormTextField <FormTextField
name="pagespeedApiKey" name="pagespeedApiKey"
type="password" type="password"
fieldLabel={t("pages.settings.form.pagespeed.option.apiKey.label")} fieldLabel={t(
"pages.settings.form.pagespeed.option.apiKey.label"
)}
placeholder={t( placeholder={t(
"pages.settings.form.pagespeed.option.apiKey.placeholder" "pages.settings.form.pagespeed.option.apiKey.placeholder"
)} )}
@@ -889,12 +892,11 @@ export const SettingsPage = () => {
/> />
)} )}
</Stack> </Stack>
)}
{/* data tab */} {/* data tab */}
<Stack {activeTab === "data" && (
gap={theme.spacing(LAYOUT.MD)} <Stack gap={theme.spacing(LAYOUT.MD)}>
hidden={activeTab !== "data"}
>
{/* Export Monitors - Admin Only */} {/* Export Monitors - Admin Only */}
{isAdmin && ( {isAdmin && (
<ConfigBox <ConfigBox
@@ -968,6 +970,7 @@ export const SettingsPage = () => {
/> />
)} )}
</Stack> </Stack>
)}
{/* Clear Stats Confirmation Dialog */} {/* Clear Stats Confirmation Dialog */}
<Dialog <Dialog
@@ -1032,7 +1035,16 @@ export const SettingsPage = () => {
return ( return (
<li key={field}> <li key={field}>
<Typography variant="body2"> <Typography variant="body2">
<strong>{field}:</strong> {message} <Link
component="button"
type="button"
variant="body2"
color={theme.palette.error.main}
onClick={() => revealField(field)}
>
<strong>{field}</strong>
</Link>
: {message}
</Typography> </Typography>
</li> </li>
); );