mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-16 14:49:48 -06:00
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user