/* global React, PR */ const { useState, useEffect, useCallback } = React; const { I, Avatar } = PR; const ROLE_LABELS = { admin: "Admin", lead: "R&D Lead", core: "Designer", orbit: "Analyst", viewer: "Viewer", }; const ROLE_DESCS = { admin: "Full access including user management and system settings.", lead: "Full access. Approves pitch sessions and stage gates.", core: "Authors hypotheses. Edits own projects, comments on others.", orbit: "Owns telemetry and Cold Test data. Attaches reports.", viewer: "Read-only. Procurement uses this to receive scaled packages.", }; const ROLE_PERMS = { admin: ["Edit registry", "Move stages", "Kill / Pivot / Scale", "Manage users", "System settings"], lead: ["Edit registry", "Move stages", "Decide Kill / Pivot / Scale", "Manage users"], core: ["Create hypothesis", "Edit own", "Comment", "Move own to next stage"], orbit: ["Edit metrics", "Attach reports", "Comment"], viewer: ["Read", "Export passport"], }; function fmtLast(s) { if (!s) return "—"; const d = new Date(s); if (isNaN(d.getTime())) return "—"; const diff = Math.floor((Date.now() - d.getTime()) / 86400000); if (diff <= 0) return "today"; if (diff === 1) return "1d ago"; if (diff < 30) return diff + "d ago"; return Math.floor(diff / 30) + "mo ago"; } function InviteModal({ onClose, onSuccess }) { const [form, setForm] = useState({ username: "", email: "", full_name: "", role: "core", password: "" }); const [saving, setSaving] = useState(false); const [error, setError] = useState(""); const set = (k, v) => setForm(f => ({ ...f, [k]: v })); const handleSubmit = async (e) => { e.preventDefault(); setSaving(true); setError(""); try { const resp = await fetch("/api/users", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(form), }); if (!resp.ok) { const err = await resp.json(); setError(err.detail || "Failed to create user"); return; } onSuccess(); onClose(); } finally { setSaving(false); } }; return (
{ROLE_DESCS[r]}
| Name | Role | Username | Status | Actions |
|---|---|---|---|---|
|
{u.full_name || u.username}
{u.email}
|
{ROLE_LABELS[u.role] || u.role} | {u.username} | {u.is_active ? "Active" : "Deactivated"} |
{u.is_active ? (
) : (
)}
|