Scaffold Homelab Manager foundation
Monorepo (Express+TS+Drizzle/libSQL server, React+Vite+Tabler web) matching the stack used by ScheduleTaskManager and Sloth Manager. Includes Authentik OIDC login with local admin/operator/viewer roles (first user becomes admin), a generalized audit log, encrypted-at-rest storage for future integration API tokens, the DB schema for all planned modules, and the Tabler-styled app shell/nav. Also ports the Secrets (expiry tracker) and IP Addresses (IPAM) modules from Sloth Manager onto the new stack. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
commit
6bd2ed52c1
52 files changed
+8103
No files matched your search
@@ -0,0 +1,83 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type UserRecord, type UserRole } from "../api/client";
|
||||
|
||||
const ROLES: UserRole[] = ["viewer", "operator", "admin"];
|
||||
|
||||
export default function Users() {
|
||||
const [users, setUsers] = useState<UserRecord[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [savingId, setSavingId] = useState<number | null>(null);
|
||||
|
||||
function load() {
|
||||
api.users
|
||||
.list()
|
||||
.then((res) => setUsers(res.users))
|
||||
.catch((err) => setError(String(err)));
|
||||
}
|
||||
|
||||
useEffect(load, []);
|
||||
|
||||
async function changeRole(id: number, role: UserRole) {
|
||||
setError(null);
|
||||
setSavingId(id);
|
||||
try {
|
||||
await api.users.updateRole(id, role);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setSavingId(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title mb-3">Users</h2>
|
||||
{error && <div className="alert alert-danger">{error}</div>}
|
||||
<div className="card">
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Email</th>
|
||||
<th>Role</th>
|
||||
<th>Last login</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{users?.map((u) => (
|
||||
<tr key={u.id}>
|
||||
<td>{u.name ?? "—"}</td>
|
||||
<td>{u.email ?? "—"}</td>
|
||||
<td style={{ maxWidth: 160 }}>
|
||||
<select
|
||||
className="form-select form-select-sm"
|
||||
value={u.role}
|
||||
disabled={savingId === u.id}
|
||||
onChange={(e) => changeRole(u.id, e.target.value as UserRole)}
|
||||
>
|
||||
{ROLES.map((r) => (
|
||||
<option key={r} value={r}>
|
||||
{r}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</td>
|
||||
<td>{u.lastLoginAt ? new Date(u.lastLoginAt).toLocaleString() : "never"}</td>
|
||||
</tr>
|
||||
))}
|
||||
{users?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={4} className="text-secondary text-center">
|
||||
No users yet.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user