Change API and Refactoring a handler function
This commit is contained in:
1 parent
aaba9e8d42
commit
d5d3e14d96
2 files changed
+30
-25
No files matched your search
@@ -41,6 +41,33 @@ const SettingsEmail = ({
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle sending test email with current form values
|
||||
*/
|
||||
const handleSendTestEmail = () => {
|
||||
// Collect current form values
|
||||
const emailConfig = {
|
||||
systemEmailHost: settingsData?.settings?.systemEmailHost,
|
||||
systemEmailPort: settingsData?.settings?.systemEmailPort,
|
||||
systemEmailUser: settingsData?.settings?.systemEmailUser,
|
||||
systemEmailAddress: settingsData?.settings?.systemEmailAddress,
|
||||
systemEmailPassword: password || settingsData?.settings?.systemEmailPassword,
|
||||
systemEmailConnectionHost: settingsData?.settings?.systemEmailConnectionHost
|
||||
};
|
||||
|
||||
// Basic validation
|
||||
if (!emailConfig.systemEmailHost || !emailConfig.systemEmailPort) {
|
||||
createToast({
|
||||
body: t("settingsEmailRequiredFields", "Email host and port are required"),
|
||||
variant: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Send test email with current form values
|
||||
sendTestEmail(emailConfig);
|
||||
};
|
||||
|
||||
if (!isAdmin) {
|
||||
return null;
|
||||
}
|
||||
@@ -137,29 +164,7 @@ const SettingsEmail = ({
|
||||
variant="contained"
|
||||
color="accent"
|
||||
loading={isSending}
|
||||
onClick={() => {
|
||||
// Collect current form values
|
||||
const emailConfig = {
|
||||
systemEmailHost: settingsData?.settings?.systemEmailHost,
|
||||
systemEmailPort: settingsData?.settings?.systemEmailPort,
|
||||
systemEmailUser: settingsData?.settings?.systemEmailUser,
|
||||
systemEmailAddress: settingsData?.settings?.systemEmailAddress,
|
||||
systemEmailPassword: password || settingsData?.settings?.systemEmailPassword,
|
||||
systemEmailConnectionHost: settingsData?.settings?.systemEmailConnectionHost
|
||||
};
|
||||
|
||||
// Basic validation
|
||||
if (!emailConfig.systemEmailHost || !emailConfig.systemEmailPort) {
|
||||
createToast({
|
||||
body: t("settingsEmailRequiredFields", "Email host and port are required"),
|
||||
variant: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Send test email with current form values
|
||||
sendTestEmail(emailConfig);
|
||||
}}
|
||||
onClick={handleSendTestEmail}
|
||||
>
|
||||
{t("settingsTestEmail", "Send test e-mail")}
|
||||
</Button>
|
||||
|
||||
@@ -1162,7 +1162,7 @@ class NetworkService {
|
||||
|
||||
// If emailConfig is provided, use the new endpoint with direct parameters
|
||||
if (emailConfig) {
|
||||
return this.axiosInstance.post(`/api/v1/settings/test-email`, {
|
||||
return this.axiosInstance.post(`/settings/test-email`, {
|
||||
to,
|
||||
systemEmailHost: emailConfig.systemEmailHost,
|
||||
systemEmailPort: emailConfig.systemEmailPort,
|
||||
@@ -1175,7 +1175,7 @@ class NetworkService {
|
||||
}
|
||||
|
||||
// Fallback to original behavior for backward compatibility
|
||||
return this.axiosInstance.post(`/monitors/test-email`, { to });
|
||||
return this.axiosInstance.post(`/settings/test-email`, { to });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user