feat: Update email testing to use form values without saving

- Modify test email button to collect current form values
- Add validation for required fields before testing
- Pass configuration directly to test endpoint
- Improve user experience by allowing testing before saving
This commit is contained in:
mohadeseh safari
2025-05-16 19:29:44 -04:00
parent 8ef45a7fb9
commit 083c395f10

View File

@@ -11,6 +11,7 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
import { useSendTestEmail } from "../../Hooks/useSendTestEmail";
import { createToast } from "../../Utils/toastUtils";
const SettingsEmail = ({
isAdmin,
@@ -29,7 +30,7 @@ const SettingsEmail = ({
const [hasBeenReset, setHasBeenReset] = useState(false);
// Network
const [isSending, error, sendTestEmail] = useSendTestEmail();
const [isSending, , sendTestEmail] = useSendTestEmail(); // Using empty placeholder for unused error variable
// Handlers
const handlePasswordChange = (e) => {
@@ -136,9 +137,31 @@ const SettingsEmail = ({
variant="contained"
color="accent"
loading={isSending}
onClick={sendTestEmail}
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);
}}
>
Send test e-mail
{t("settingsTestEmail", "Send test e-mail")}
</Button>
</Box>
</Stack>