import React, { useEffect, useState } from "react"; import { apiFetch } from "../api"; import { useAuth } from "../state"; export function AdminUsersPage() { const { tokens, refresh, me } = useAuth(); const [users, setUsers] = useState([]); const [form, setForm] = useState({ email: "", password: "", role: "viewer" }); const [emailSettings, setEmailSettings] = useState({ enabled: false, smtp_host: "", smtp_port: 587, smtp_username: "", smtp_password: "", clear_smtp_password: false, from_email: "", use_starttls: true, use_ssl: false, alert_recipients: "", }); const [smtpState, setSmtpState] = useState({ has_password: false, updated_at: null }); const [testRecipient, setTestRecipient] = useState(""); const [smtpInfo, setSmtpInfo] = useState(""); const [error, setError] = useState(""); const load = async () => { const [userRows, smtp] = await Promise.all([ apiFetch("/admin/users", {}, tokens, refresh), apiFetch("/admin/settings/email", {}, tokens, refresh), ]); setUsers(userRows); setEmailSettings((prev) => ({ ...prev, enabled: !!smtp.enabled, smtp_host: smtp.smtp_host || "", smtp_port: smtp.smtp_port || 587, smtp_username: smtp.smtp_username || "", smtp_password: "", clear_smtp_password: false, from_email: smtp.from_email || "", use_starttls: !!smtp.use_starttls, use_ssl: !!smtp.use_ssl, alert_recipients: (smtp.alert_recipients || []).join(", "), })); setSmtpState({ has_password: !!smtp.has_password, updated_at: smtp.updated_at }); setTestRecipient(smtp.from_email || ""); }; useEffect(() => { if (me?.role === "admin") load().catch((e) => setError(String(e.message || e))); }, [me]); if (me?.role !== "admin") return
| ID | Role | Action | |
|---|---|---|---|
| {u.id} | {u.email} | {u.role} | {u.id !== me.id && ( )} |
Configure outgoing SMTP for alert emails. This is send-only; no inbound mailbox is used.
{smtpInfo &&