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:
1 parent
8ef45a7fb9
commit
083c395f10
1 file changed
+26
-3
@@ -11,6 +11,7 @@ import { useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
|
import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments";
|
||||||
import { useSendTestEmail } from "../../Hooks/useSendTestEmail";
|
import { useSendTestEmail } from "../../Hooks/useSendTestEmail";
|
||||||
|
import { createToast } from "../../Utils/toastUtils";
|
||||||
|
|
||||||
const SettingsEmail = ({
|
const SettingsEmail = ({
|
||||||
isAdmin,
|
isAdmin,
|
||||||
@@ -29,7 +30,7 @@ const SettingsEmail = ({
|
|||||||
const [hasBeenReset, setHasBeenReset] = useState(false);
|
const [hasBeenReset, setHasBeenReset] = useState(false);
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
const [isSending, error, sendTestEmail] = useSendTestEmail();
|
const [isSending, , sendTestEmail] = useSendTestEmail(); // Using empty placeholder for unused error variable
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
const handlePasswordChange = (e) => {
|
const handlePasswordChange = (e) => {
|
||||||
@@ -136,9 +137,31 @@ const SettingsEmail = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="accent"
|
color="accent"
|
||||||
loading={isSending}
|
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>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
Reference in new issue
Block a user