Skip to content

Commit 25aecab

Browse files
authored
Merge pull request #3142 from Bima42/fix/notification-returns-raw-json-on-email-test
fix(notification): use form validation logic for testing
2 parents 9e11b80 + dc4e8ec commit 25aecab

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

apps/dokploy/components/dashboard/settings/notifications/handle-notifications.tsx

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,56 +1214,62 @@ export const HandleNotifications = ({ notificationId }: Props) => {
12141214
isLoadingLark
12151215
}
12161216
variant="secondary"
1217+
type="button"
12171218
onClick={async () => {
1219+
const isValid = await form.trigger();
1220+
if (!isValid) return;
1221+
1222+
const data = form.getValues();
1223+
12181224
try {
1219-
if (type === "slack") {
1225+
if (data.type === "slack") {
12201226
await testSlackConnection({
1221-
webhookUrl: form.getValues("webhookUrl"),
1222-
channel: form.getValues("channel"),
1227+
webhookUrl: data.webhookUrl,
1228+
channel: data.channel,
12231229
});
1224-
} else if (type === "telegram") {
1230+
} else if (data.type === "telegram") {
12251231
await testTelegramConnection({
1226-
botToken: form.getValues("botToken"),
1227-
chatId: form.getValues("chatId"),
1228-
messageThreadId: form.getValues("messageThreadId") || "",
1232+
botToken: data.botToken,
1233+
chatId: data.chatId,
1234+
messageThreadId: data.messageThreadId || "",
12291235
});
1230-
} else if (type === "discord") {
1236+
} else if (data.type === "discord") {
12311237
await testDiscordConnection({
1232-
webhookUrl: form.getValues("webhookUrl"),
1233-
decoration: form.getValues("decoration"),
1238+
webhookUrl: data.webhookUrl,
1239+
decoration: data.decoration,
12341240
});
1235-
} else if (type === "email") {
1241+
} else if (data.type === "email") {
12361242
await testEmailConnection({
1237-
smtpServer: form.getValues("smtpServer"),
1238-
smtpPort: form.getValues("smtpPort"),
1239-
username: form.getValues("username"),
1240-
password: form.getValues("password"),
1241-
toAddresses: form.getValues("toAddresses"),
1242-
fromAddress: form.getValues("fromAddress"),
1243+
smtpServer: data.smtpServer,
1244+
smtpPort: data.smtpPort,
1245+
username: data.username,
1246+
password: data.password,
1247+
fromAddress: data.fromAddress,
1248+
toAddresses: data.toAddresses,
12431249
});
1244-
} else if (type === "gotify") {
1250+
} else if (data.type === "gotify") {
12451251
await testGotifyConnection({
1246-
serverUrl: form.getValues("serverUrl"),
1247-
appToken: form.getValues("appToken"),
1248-
priority: form.getValues("priority"),
1249-
decoration: form.getValues("decoration"),
1252+
serverUrl: data.serverUrl,
1253+
appToken: data.appToken,
1254+
priority: data.priority,
1255+
decoration: data.decoration,
12501256
});
1251-
} else if (type === "ntfy") {
1257+
} else if (data.type === "ntfy") {
12521258
await testNtfyConnection({
1253-
serverUrl: form.getValues("serverUrl"),
1254-
topic: form.getValues("topic"),
1255-
accessToken: form.getValues("accessToken"),
1256-
priority: form.getValues("priority"),
1259+
serverUrl: data.serverUrl,
1260+
topic: data.topic,
1261+
accessToken: data.accessToken,
1262+
priority: data.priority,
12571263
});
1258-
} else if (type === "lark") {
1264+
} else if (data.type === "lark") {
12591265
await testLarkConnection({
1260-
webhookUrl: form.getValues("webhookUrl"),
1266+
webhookUrl: data.webhookUrl,
12611267
});
12621268
}
12631269
toast.success("Connection Success");
12641270
} catch (error) {
12651271
toast.error(
1266-
`Error testing the provider ${error instanceof Error ? error.message : "Unknown error"}`,
1272+
`Error testing the provider: ${error instanceof Error ? error.message : "Unknown error"}`,
12671273
);
12681274
}
12691275
}}

0 commit comments

Comments
 (0)