Files
HealthLog/src/components/settings/channel-form-dirty.ts
T
Marc-André Bombeck 3bb08c3c8a fix(settings): hold the channel test until changes are saved
The webhook, ntfy, email and Telegram test routes send through the
saved channel config. After a field changed, the card kept showing the
Saved note from the last save and Test still ran, so it reported on the
old settings: a webhook switched to the Gotify format was tested with
the generic body and Gotify refused it. The note now disappears on a
change, and the test button stays off with a save-first hint while the
form differs from what is saved. Refs #947
2026-09-13 18:28:47 +02:00

58 lines
1.7 KiB
TypeScript

/**
* Whether a notification channel card's form differs from what is saved.
*
* The Test button on these cards always sends through the saved channel
* config, never the form. While the form holds an unsaved change, a test
* would report on something other than what is on screen, and a "Saved"
* note left over from an earlier save would say the opposite of the truth.
* A secret field (header value, auth token, bot token) is write-only: the
* server never returns it, so any typed value counts as a change.
*/
export function isWebhookFormDirty(
form: {
url: string;
headerName: string;
headerValue: string;
format: "generic" | "gotify";
},
saved: { url: string; headerName: string; format?: string } | undefined,
): boolean {
if (!saved) return false;
const savedFormat = saved.format === "gotify" ? "gotify" : "generic";
return (
form.url !== saved.url ||
form.headerName !== saved.headerName ||
form.headerValue !== "" ||
form.format !== savedFormat
);
}
export function isNtfyFormDirty(
form: { serverUrl: string; topic: string; authToken: string },
saved: { serverUrl: string; topic: string } | undefined,
): boolean {
if (!saved) return false;
return (
form.serverUrl !== saved.serverUrl ||
form.topic !== saved.topic ||
form.authToken !== ""
);
}
export function isEmailFormDirty(
form: { recipient: string },
saved: { recipient: string } | undefined,
): boolean {
if (!saved) return false;
return form.recipient !== saved.recipient;
}
export function isTelegramFormDirty(
form: { botToken: string; chatId: string },
saved: { chatId?: string | null } | undefined,
): boolean {
if (!saved) return false;
return form.botToken.trim() !== "" || form.chatId !== (saved.chatId ?? "");
}