mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-03 23:19:37 -05:00
Merge pull request #2294 from bluewave-labs/feature/email-testing-without-saving
Feature/email testing without saving
This commit is contained in:
@@ -10,24 +10,40 @@ const useSendTestEmail = () => {
|
||||
const user = useSelector((state) => state.auth.user);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const sendTestEmail = async () => {
|
||||
/**
|
||||
* Send a test email with optional email configuration
|
||||
* @param {Object} emailConfig - Optional email configuration parameters
|
||||
*/
|
||||
const sendTestEmail = async (emailConfig = null) => {
|
||||
try {
|
||||
setIsSending(true);
|
||||
setError(null);
|
||||
|
||||
const response = await networkService.sendTestEmail({ to: user.email });
|
||||
// Send the test email with or without configuration
|
||||
const response = await networkService.sendTestEmail({
|
||||
to: user.email,
|
||||
emailConfig
|
||||
});
|
||||
|
||||
if (typeof response?.data?.data?.messageId !== "undefined") {
|
||||
createToast({
|
||||
body: t("emailSent"),
|
||||
body: t("settingsTestEmailSuccess", "Test email sent successfully"),
|
||||
});
|
||||
} else {
|
||||
throw new Error(t("failedToSendEmail"));
|
||||
throw new Error(response?.data?.error || t("settingsTestEmailFailed", "Failed to send test email"));
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
createToast({
|
||||
body: t("failedToSendEmail"),
|
||||
});
|
||||
setError(error);
|
||||
createToast({
|
||||
body: t("settingsTestEmailFailedWithReason", "Failed to send test email: {{reason}}", {
|
||||
reason: error.message || t("settingsTestEmailUnknownError", "Unknown error")
|
||||
}),
|
||||
variant: "error"
|
||||
});
|
||||
} finally {
|
||||
setIsSending(false);
|
||||
}
|
||||
|
||||
@@ -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) => {
|
||||
@@ -40,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;
|
||||
}
|
||||
@@ -136,9 +164,9 @@ const SettingsEmail = ({
|
||||
variant="contained"
|
||||
color="accent"
|
||||
loading={isSending}
|
||||
onClick={sendTestEmail}
|
||||
onClick={handleSendTestEmail}
|
||||
>
|
||||
Send test e-mail
|
||||
{t("settingsTestEmail", "Send test e-mail")}
|
||||
</Button>
|
||||
</Box>
|
||||
</Stack>
|
||||
|
||||
@@ -1157,11 +1157,28 @@ class NetworkService {
|
||||
}
|
||||
|
||||
// ************************************
|
||||
// Send tes t email
|
||||
// Send test email
|
||||
// ************************************
|
||||
async sendTestEmail(config) {
|
||||
const { to } = config;
|
||||
return this.axiosInstance.post(`/monitors/test-email`, { to });
|
||||
// Extract recipient and email configuration
|
||||
const { to, emailConfig } = config;
|
||||
|
||||
// If emailConfig is provided, use the new endpoint with direct parameters
|
||||
if (emailConfig) {
|
||||
return this.axiosInstance.post(`/settings/test-email`, {
|
||||
to,
|
||||
systemEmailHost: emailConfig.systemEmailHost,
|
||||
systemEmailPort: emailConfig.systemEmailPort,
|
||||
systemEmailAddress: emailConfig.systemEmailAddress,
|
||||
systemEmailPassword: emailConfig.systemEmailPassword,
|
||||
// Only include these if they are present
|
||||
...(emailConfig.systemEmailConnectionHost && { systemEmailConnectionHost: emailConfig.systemEmailConnectionHost }),
|
||||
...(emailConfig.systemEmailUser && { systemEmailUser: emailConfig.systemEmailUser })
|
||||
});
|
||||
}
|
||||
|
||||
// Fallback to original behavior for backward compatibility
|
||||
return this.axiosInstance.post(`/settings/test-email`, { to });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,15 +112,21 @@
|
||||
"settingsFailedToAddDemoMonitors": "Failed to add demo monitors",
|
||||
"settingsMonitorsDeleted": "Successfully deleted all monitors",
|
||||
"settingsFailedToDeleteMonitors": "Failed to delete all monitors",
|
||||
"settingsEmail": "Email settings",
|
||||
"settingsEmailDescription": "Configure email settings",
|
||||
"settingsEmail": "Email",
|
||||
"settingsEmailDescription": "Configure the email settings for your system. This is used to send notifications and alerts.",
|
||||
"settingsEmailHost": "Email host - Hostname or IP address of the SMTP server",
|
||||
"settingsEmailPort": "Email port - Port to connect to",
|
||||
"settingsEmailUser": "Email user - Username for authentication, overrides email address if specified",
|
||||
"settingsEmailAddress": "Email address - Used for authentication",
|
||||
"settingsEmailPassword": "Email password - Password for authentication",
|
||||
"settingsEmailUser": "Email user - Username for authentication, overrides email address if specified",
|
||||
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
|
||||
"settingsEmailConnectionHost": "Email connection host - Hostname to use in the HELO/EHLO greeting",
|
||||
"settingsTestEmail": "Send test e-mail",
|
||||
"settingsTestEmailSuccess": "Test email sent successfully",
|
||||
"settingsTestEmailFailed": "Failed to send test email",
|
||||
"settingsTestEmailFailedWithReason": "Failed to send test email: {{reason}}",
|
||||
"settingsTestEmailUnknownError": "Unknown error",
|
||||
"settingsEmailRequiredFields": "Email host and port are required",
|
||||
"settingsEmailFieldResetLabel": "Password is set. Click Reset to change it.",
|
||||
"backendUnreachable": "Server Connection Error",
|
||||
"backendUnreachableMessage": "We're unable to connect to the server. Please check your internet connection or verify your deployment configuration if the problem persists.",
|
||||
"backendUnreachableError": "Cannot connect to the server. Please try again later.",
|
||||
@@ -522,8 +528,6 @@
|
||||
"logOut": "Log out"
|
||||
},
|
||||
"navControls": "Controls",
|
||||
"statusBreadCrumbsStatusPages": "Status Pages",
|
||||
"statusBreadCrumbsDetails": "Details",
|
||||
"incidentsPageTitle": "Incidents",
|
||||
"passwordPanel": {
|
||||
"passwordChangedSuccess": "Your password was changed successfully.",
|
||||
|
||||
@@ -115,6 +115,21 @@
|
||||
"settingsRemoveAllMonitorsDialogConfirm": "Да, удалить все мониторы",
|
||||
"settingsWallet": "Кошелёк",
|
||||
"settingsWalletDescription": "Подключите свой кошелек здесь. Это необходимо для того, чтобы монитор Distributed Uptime мог подключиться к нескольким узлам по всему миру.",
|
||||
"settingsEmail": "Настройки электронной почты",
|
||||
"settingsEmailDescription": "Настройте параметры электронной почты",
|
||||
"settingsEmailHost": "Хост электронной почты - имя хоста или IP-адрес SMTP-сервера",
|
||||
"settingsEmailPort": "Порт электронной почты - порт для подключения",
|
||||
"settingsEmailAddress": "Адрес электронной почты - используется для аутентификации",
|
||||
"settingsEmailPassword": "Пароль электронной почты - пароль для аутентификации",
|
||||
"settingsEmailUser": "Пользователь электронной почты - имя пользователя для аутентификации, переопределяет адрес электронной почты, если указан",
|
||||
"settingsEmailFieldResetLabel": "Пароль установлен. Нажмите «Сбросить», чтобы изменить его.",
|
||||
"settingsEmailConnectionHost": "Хост подключения электронной почты - имя хоста, используемое в приветствии HELO/EHLO",
|
||||
"settingsTestEmail": "Отправить тестовое письмо",
|
||||
"settingsTestEmailSuccess": "Тестовое письмо успешно отправлено",
|
||||
"settingsTestEmailFailed": "Не удалось отправить тестовое письмо",
|
||||
"settingsTestEmailFailedWithReason": "Не удалось отправить тестовое письмо: {{reason}}",
|
||||
"settingsTestEmailUnknownError": "Неизвестная ошибка",
|
||||
"settingsEmailRequiredFields": "Требуются хост и порт электронной почты",
|
||||
"settingsAbout": "О",
|
||||
"settingsDevelopedBy": "Developed by Bluewave Labs.",
|
||||
"settingsSave": "Сохранить",
|
||||
|
||||
@@ -99,6 +99,20 @@
|
||||
"settingsRemoveAllMonitorsDialogConfirm": "Evet, tüm monitörleri kaldır",
|
||||
"settingsWallet": "Cüzdan",
|
||||
"settingsWalletDescription": "Cüzdanınızı buradan bağlayın. Bu, Dağıtılmış Çalışma Süresi monitörünün küresel olarak birden çok düğüme bağlanması için gereklidir.",
|
||||
"settingsTestEmail": "Test e-postası gönder",
|
||||
"settingsTestEmailSuccess": "Test e-postası başarıyla gönderildi",
|
||||
"settingsTestEmailFailed": "Test e-postası gönderilemedi",
|
||||
"settingsTestEmailFailedWithReason": "Test e-postası gönderilemedi: {{reason}}",
|
||||
"settingsTestEmailUnknownError": "Bilinmeyen hata",
|
||||
"settingsEmail": "E-posta",
|
||||
"settingsEmailDescription": "Sisteminiz için e-posta ayarlarını yapılandırın. Bu, bildirim ve uyarıları göndermek için kullanılır.",
|
||||
"settingsEmailHost": "E-posta sunucusu - SMTP sunucusunun ana bilgisayar adı veya IP adresi",
|
||||
"settingsEmailPort": "E-posta portu - Bağlanılacak port",
|
||||
"settingsEmailUser": "E-posta kullanıcısı - Kimlik doğrulama için kullanıcı adı, belirtilirse e-posta adresini geçersiz kılar",
|
||||
"settingsEmailAddress": "E-posta adresi - Kimlik doğrulama için kullanılır",
|
||||
"settingsEmailPassword": "E-posta şifresi - Kimlik doğrulama için şifre",
|
||||
"settingsEmailConnectionHost": "E-posta bağlantı sunucusu - HELO/EHLO selamlamasında kullanılacak ana bilgisayar adı",
|
||||
"settingsEmailRequiredFields": "E-posta sunucusu ve port gereklidir",
|
||||
"settingsAbout": "Hakkında",
|
||||
"settingsDevelopedBy": "Bluewave Labs tarafından geliştirilmiştir.",
|
||||
"settingsSave": "Kaydet",
|
||||
|
||||
Reference in New Issue
Block a user