fix: use form validation logic for testing notif

This commit is contained in:
Bima42
2025-11-30 18:08:37 +01:00
parent 559753eae3
commit dc4e8ecdc9

View File

@@ -1214,56 +1214,62 @@ export const HandleNotifications = ({ notificationId }: Props) => {
isLoadingLark isLoadingLark
} }
variant="secondary" variant="secondary"
type="button"
onClick={async () => { onClick={async () => {
const isValid = await form.trigger();
if (!isValid) return;
const data = form.getValues();
try { try {
if (type === "slack") { if (data.type === "slack") {
await testSlackConnection({ await testSlackConnection({
webhookUrl: form.getValues("webhookUrl"), webhookUrl: data.webhookUrl,
channel: form.getValues("channel"), channel: data.channel,
}); });
} else if (type === "telegram") { } else if (data.type === "telegram") {
await testTelegramConnection({ await testTelegramConnection({
botToken: form.getValues("botToken"), botToken: data.botToken,
chatId: form.getValues("chatId"), chatId: data.chatId,
messageThreadId: form.getValues("messageThreadId") || "", messageThreadId: data.messageThreadId || "",
}); });
} else if (type === "discord") { } else if (data.type === "discord") {
await testDiscordConnection({ await testDiscordConnection({
webhookUrl: form.getValues("webhookUrl"), webhookUrl: data.webhookUrl,
decoration: form.getValues("decoration"), decoration: data.decoration,
}); });
} else if (type === "email") { } else if (data.type === "email") {
await testEmailConnection({ await testEmailConnection({
smtpServer: form.getValues("smtpServer"), smtpServer: data.smtpServer,
smtpPort: form.getValues("smtpPort"), smtpPort: data.smtpPort,
username: form.getValues("username"), username: data.username,
password: form.getValues("password"), password: data.password,
toAddresses: form.getValues("toAddresses"), fromAddress: data.fromAddress,
fromAddress: form.getValues("fromAddress"), toAddresses: data.toAddresses,
}); });
} else if (type === "gotify") { } else if (data.type === "gotify") {
await testGotifyConnection({ await testGotifyConnection({
serverUrl: form.getValues("serverUrl"), serverUrl: data.serverUrl,
appToken: form.getValues("appToken"), appToken: data.appToken,
priority: form.getValues("priority"), priority: data.priority,
decoration: form.getValues("decoration"), decoration: data.decoration,
}); });
} else if (type === "ntfy") { } else if (data.type === "ntfy") {
await testNtfyConnection({ await testNtfyConnection({
serverUrl: form.getValues("serverUrl"), serverUrl: data.serverUrl,
topic: form.getValues("topic"), topic: data.topic,
accessToken: form.getValues("accessToken"), accessToken: data.accessToken,
priority: form.getValues("priority"), priority: data.priority,
}); });
} else if (type === "lark") { } else if (data.type === "lark") {
await testLarkConnection({ await testLarkConnection({
webhookUrl: form.getValues("webhookUrl"), webhookUrl: data.webhookUrl,
}); });
} }
toast.success("Connection Success"); toast.success("Connection Success");
} catch (error) { } catch (error) {
toast.error( toast.error(
`Error testing the provider ${error instanceof Error ? error.message : "Unknown error"}`, `Error testing the provider: ${error instanceof Error ? error.message : "Unknown error"}`,
); );
} }
}} }}