import React, { useEffect, useState } from "react"; import { apiFetch } from "../api"; import { useAuth } from "../state"; const TEMPLATE_VARIABLES = [ "target_name", "target_id", "alert_name", "severity", "category", "description", "message", "value", "warning_threshold", "alert_threshold", "checked_at", "alert_key", ]; export function AdminUsersPage() { const { tokens, refresh, me } = useAuth(); const emptyCreateForm = { email: "", first_name: "", last_name: "", password: "", role: "viewer" }; const [users, setUsers] = useState([]); const [form, setForm] = useState(emptyCreateForm); const [editingUserId, setEditingUserId] = useState(null); const [editForm, setEditForm] = useState({ email: "", first_name: "", last_name: "", password: "", role: "viewer" }); const [emailSettings, setEmailSettings] = useState({ enabled: false, smtp_host: "", smtp_port: 587, smtp_username: "", smtp_password: "", clear_smtp_password: false, from_name: "", from_email: "", use_starttls: true, use_ssl: false, warning_subject_template: "", alert_subject_template: "", warning_body_template: "", alert_body_template: "", }); 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_name: smtp.from_name || "", from_email: smtp.from_email || "", use_starttls: !!smtp.use_starttls, use_ssl: !!smtp.use_ssl, warning_subject_template: smtp.warning_subject_template || "", alert_subject_template: smtp.alert_subject_template || "", warning_body_template: smtp.warning_body_template || "", alert_body_template: smtp.alert_body_template || "", })); 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
Manage users and outgoing notifications for this NexaPG instance.
{error &&Create accounts and manage access roles.
| ID | Name | Role | Action | |
|---|---|---|---|---|
| {u.id} |
{editingUserId === u.id ? (
setEditForm({ ...editForm, first_name: e.target.value })}
/>
setEditForm({ ...editForm, last_name: e.target.value })}
/>
) : (
{[u.first_name, u.last_name].filter(Boolean).join(" ") || "-"}
)}
|
{editingUserId === u.id ? ( setEditForm({ ...editForm, email: e.target.value })} /> ) : ( u.email )} | {editingUserId === u.id ? ( ) : ( {u.role} )} | {editingUserId === u.id && ( setEditForm({ ...editForm, password: e.target.value })} /> )} {editingUserId === u.id ? ( <> > ) : ( )} {u.id !== me.id && ( )} |
Configure send-only SMTP for warning and alert notifications.