send test email

This commit is contained in:
cesnimda
2026-03-21 13:04:56 +01:00
parent d09711dc97
commit 8cc4b0dfce
3 changed files with 88 additions and 4 deletions
+51 -1
View File
@@ -36,6 +36,11 @@ export default function AdminUsersPage() {
const [newPassword, setNewPassword] = useState("");
const [newIsAdmin, setNewIsAdmin] = useState(false);
const [testEmailTo, setTestEmailTo] = useState("");
const [testEmailSubject, setTestEmailSubject] = useState("Job Tracker SMTP test");
const [testEmailMessage, setTestEmailMessage] = useState("This is a test email from the Job Tracker admin panel.");
const [sendingTestEmail, setSendingTestEmail] = useState(false);
async function load() {
setLoading(true);
try {
@@ -50,7 +55,6 @@ export default function AdminUsersPage() {
useEffect(() => {
void load();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const canCreate = useMemo(() => newEmail.trim().length > 3 && newPassword.length >= 6, [newEmail, newPassword]);
@@ -76,6 +80,23 @@ export default function AdminUsersPage() {
}
};
const sendTestEmail = async () => {
setSendingTestEmail(true);
try {
await api.post("/users/send-test-email", {
toEmail: testEmailTo.trim() || null,
subject: testEmailSubject.trim() || null,
message: testEmailMessage.trim() || null,
});
toast("Test email sent.", "success");
} catch (e: any) {
const msg = e?.response?.data || e?.message || "Failed to send test email.";
toast(String(msg), "error");
} finally {
setSendingTestEmail(false);
}
};
const remove = async (u: UserDto) => {
if (!window.confirm(`Delete user ${u.email || u.userName || u.id}?`)) return;
try {
@@ -94,6 +115,35 @@ export default function AdminUsersPage() {
</Typography>
<Typography sx={{ color: "text.secondary", mb: 2 }}>Admin-only user management.</Typography>
<Paper sx={{ p: 2, mb: 2 }}>
<Typography sx={{ fontWeight: 900, mb: 1 }}>SMTP test email</Typography>
<Typography variant="body2" sx={{ color: "text.secondary", mb: 1.5 }}>
Send a quick delivery check using the configured SMTP settings. Leave the recipient blank to use your admin email.
</Typography>
<Box sx={{ display: "grid", gridTemplateColumns: { xs: "1fr", md: "1fr 1fr" }, gap: 1.5 }}>
<TextField
label="Recipient email"
value={testEmailTo}
onChange={(e) => setTestEmailTo(e.target.value)}
placeholder="Uses your admin email if left blank"
/>
<TextField label="Subject" value={testEmailSubject} onChange={(e) => setTestEmailSubject(e.target.value)} />
<TextField
label="Message"
multiline
minRows={3}
value={testEmailMessage}
onChange={(e) => setTestEmailMessage(e.target.value)}
sx={{ gridColumn: { xs: "1 / -1", md: "1 / -1" } }}
/>
</Box>
<Box sx={{ display: "flex", justifyContent: "flex-end", mt: 1.5 }}>
<Button variant="contained" disabled={sendingTestEmail} onClick={() => void sendTestEmail()}>
{sendingTestEmail ? "Sending..." : "Send test email"}
</Button>
</Box>
</Paper>
<Paper sx={{ p: 2, mb: 2 }}>
<Typography sx={{ fontWeight: 900, mb: 1 }}>Create user</Typography>
<Box sx={{ display: "grid", gridTemplateColumns: { xs: "1fr", md: "1fr 1fr" }, gap: 1.5 }}>