import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import ConfigBox from "@/Components/v1/ConfigBox/index.jsx"; import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx"; import Button from "@mui/material/Button"; import Stack from "@mui/material/Stack"; import { Switch } from "@mui/material"; import TextLink from "@/Components/v1/TextLink/index.jsx"; // Utils import { useTheme } from "@emotion/react"; import { PropTypes } from "prop-types"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx"; import { usePost } from "@/Hooks/UseApi"; import { useSelector } from "react-redux"; import { createToast } from "@/Utils/toastUtils.jsx"; import { Controller } from "react-hook-form"; const SettingsEmail = ({ isAdmin, HEADER_SX, isEmailPasswordSet, emailPasswordHasBeenReset, setEmailPasswordHasBeenReset, control, defaults, formValues, setValue, }) => { // Setup const { t } = useTranslation(); const theme = useTheme(); // Destructure settings with default values const { systemEmailHost = "", systemEmailPort = "", systemEmailSecure = false, systemEmailPool = false, systemEmailUser = "", systemEmailAddress = "", systemEmailPassword = "", systemEmailTLSServername = "", systemEmailConnectionHost = "localhost", systemEmailIgnoreTLS = false, systemEmailRequireTLS = false, systemEmailRejectUnauthorized = true, } = formValues || {}; // Network const { post: sendTestEmailFn, loading: isSending } = usePost(); const user = useSelector((state) => state.auth.user); // Handlers /** * Handle sending test email with current form values */ const handleSendTestEmail = () => { // Basic validation if ( !systemEmailHost || !systemEmailPort || !systemEmailAddress || !systemEmailPassword ) { createToast({ body: t("pages.settings.emailSettings.toastEmailRequiredFieldsError"), variant: "error", }); return; } // Send test email - only include optional fields if they have values sendTestEmailFn("/settings/test-email", { to: user.email, systemEmailHost, systemEmailPort, systemEmailAddress, systemEmailPassword, systemEmailSecure, systemEmailPool, systemEmailIgnoreTLS, systemEmailRequireTLS, systemEmailRejectUnauthorized, ...(systemEmailUser && { systemEmailUser }), ...(systemEmailTLSServername && { systemEmailTLSServername }), ...(systemEmailConnectionHost && { systemEmailConnectionHost }), }); }; if (!isAdmin) { return null; } return ( {t("pages.settings.emailSettings.title")} {t("pages.settings.emailSettings.description")} ( )} /> ( )} /> ( )} /> ( )} /> {(isEmailPasswordSet === false || emailPasswordHasBeenReset === true) && ( ( } error={!!fieldState.error} helperText={fieldState.error?.message} /> )} /> )} {isEmailPasswordSet === true && emailPasswordHasBeenReset === false && ( {t("pages.settings.emailSettings.labelPasswordSet")} )} ( )} /> ( )} /> {[ [ "pages.settings.emailSettings.labelSecure", "systemEmailSecure", systemEmailSecure, ], [ "pages.settings.emailSettings.labelPool", "systemEmailPool", systemEmailPool, ], [ "pages.settings.emailSettings.labelIgnoreTLS", "systemEmailIgnoreTLS", systemEmailIgnoreTLS, ], [ "pages.settings.emailSettings.labelRequireTLS", "systemEmailRequireTLS", systemEmailRequireTLS, ], [ "pages.settings.emailSettings.labelRejectUnauthorized", "systemEmailRejectUnauthorized", systemEmailRejectUnauthorized, ], ].map(([labelKey, name, value]) => ( ( {t(labelKey)} )} /> ))} {JSON.stringify( { host: systemEmailHost, port: systemEmailPort, secure: systemEmailSecure, auth: { user: systemEmailUser || systemEmailAddress, pass: "", }, name: systemEmailConnectionHost || "localhost", pool: systemEmailPool, tls: { rejectUnauthorized: systemEmailRejectUnauthorized, ignoreTLS: systemEmailIgnoreTLS, requireTLS: systemEmailRequireTLS, servername: systemEmailTLSServername, }, }, null, 2 )} {systemEmailHost && systemEmailPort && systemEmailAddress && systemEmailPassword && ( )} ); }; SettingsEmail.propTypes = { isAdmin: PropTypes.bool, HEADER_SX: PropTypes.object, isPasswordSet: PropTypes.bool, }; export default SettingsEmail;