|
| 1 | +import Link from "next/link"; |
| 2 | +import { auth } from "@/auth"; |
| 3 | +import { AdminUsersTable } from "@/components/dashboard/AdminUsersTable"; |
| 4 | +import type { AdminUser } from "@/components/dashboard/AdminUsersTable"; |
| 5 | +import { ADMIN_ROLES, ROLE_LABELS, ROLE_DESCRIPTIONS } from "@/lib/permissions"; |
| 6 | + |
| 7 | +async function fetchUsers(adminJwt: string): Promise<AdminUser[]> { |
| 8 | + const serverUrl = process.env.FLUID_SERVER_URL; |
| 9 | + const adminToken = process.env.FLUID_ADMIN_TOKEN; |
| 10 | + |
| 11 | + if (!serverUrl || !adminToken) return []; |
| 12 | + |
| 13 | + try { |
| 14 | + const res = await fetch(`${serverUrl}/admin/users`, { |
| 15 | + headers: { |
| 16 | + "x-admin-token": adminToken, |
| 17 | + "x-admin-jwt": adminJwt, |
| 18 | + }, |
| 19 | + cache: "no-store", |
| 20 | + }); |
| 21 | + if (!res.ok) return []; |
| 22 | + return await res.json(); |
| 23 | + } catch { |
| 24 | + return []; |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +const ROLE_KEY_PERMISSIONS: Record<string, string[]> = { |
| 29 | + SUPER_ADMIN: ["Manage users", "Full operational control", "Billing & payments", "Config changes"], |
| 30 | + ADMIN: ["Full operational control", "View billing", "Config changes", "Manage API keys & tenants"], |
| 31 | + READ_ONLY: ["View transactions, analytics, signers", "View API keys & tenants", "View SAR & audit logs", "View billing"], |
| 32 | + BILLING: ["View transactions & analytics", "View tenants", "Manage billing & payments"], |
| 33 | +}; |
| 34 | + |
| 35 | +export default async function AdminUsersPage() { |
| 36 | + const session = await auth(); |
| 37 | + const users = await fetchUsers(session?.user?.adminJwt ?? ""); |
| 38 | + |
| 39 | + return ( |
| 40 | + <main className="min-h-screen bg-slate-100"> |
| 41 | + <div className="border-b border-slate-200 bg-white/90 backdrop-blur"> |
| 42 | + <div className="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8"> |
| 43 | + <div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between"> |
| 44 | + <div> |
| 45 | + <p className="text-sm font-semibold uppercase tracking-[0.25em] text-sky-600"> |
| 46 | + Fluid Admin — Access Control |
| 47 | + </p> |
| 48 | + <h1 className="mt-2 text-3xl font-bold text-slate-900">Admin Users</h1> |
| 49 | + <p className="mt-2 max-w-2xl text-sm text-slate-600"> |
| 50 | + Manage admin accounts and role assignments. |
| 51 | + </p> |
| 52 | + </div> |
| 53 | + <div className="flex items-center gap-4"> |
| 54 | + <div className="rounded-2xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-600"> |
| 55 | + <div className="font-medium text-slate-900">{session?.user?.email}</div> |
| 56 | + <div>{session?.user?.role ?? "Unknown role"}</div> |
| 57 | + </div> |
| 58 | + <Link |
| 59 | + href="/admin/dashboard" |
| 60 | + className="inline-flex min-h-10 items-center justify-center rounded-full border border-slate-300 bg-white px-4 text-sm font-semibold text-slate-700 transition hover:border-slate-400 hover:bg-slate-50" |
| 61 | + > |
| 62 | + Back to dashboard |
| 63 | + </Link> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + |
| 69 | + <div className="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8 space-y-10"> |
| 70 | + <AdminUsersTable users={users} currentUserRole={session?.user?.role ?? ""} /> |
| 71 | + |
| 72 | + {/* Role permissions reference */} |
| 73 | + <div> |
| 74 | + <h2 className="mb-3 text-base font-semibold text-slate-800">Role Permissions Reference</h2> |
| 75 | + <div className="overflow-hidden rounded-2xl border border-slate-200 bg-white"> |
| 76 | + <div className="overflow-x-auto"> |
| 77 | + <table className="min-w-full divide-y divide-slate-200"> |
| 78 | + <thead> |
| 79 | + <tr className="bg-slate-50"> |
| 80 | + <th className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Role</th> |
| 81 | + <th className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Description</th> |
| 82 | + <th className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Key Permissions</th> |
| 83 | + </tr> |
| 84 | + </thead> |
| 85 | + <tbody className="divide-y divide-slate-100"> |
| 86 | + {ADMIN_ROLES.map(role => ( |
| 87 | + <tr key={role} className="align-top"> |
| 88 | + <td className="whitespace-nowrap px-4 py-3"> |
| 89 | + <span className={`inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold ring-1 ring-inset ${ |
| 90 | + role === "SUPER_ADMIN" |
| 91 | + ? "bg-purple-50 text-purple-700 ring-purple-200" |
| 92 | + : role === "ADMIN" |
| 93 | + ? "bg-blue-50 text-blue-700 ring-blue-200" |
| 94 | + : role === "BILLING" |
| 95 | + ? "bg-emerald-50 text-emerald-700 ring-emerald-200" |
| 96 | + : "bg-slate-100 text-slate-600 ring-slate-200" |
| 97 | + }`}> |
| 98 | + {ROLE_LABELS[role]} |
| 99 | + </span> |
| 100 | + </td> |
| 101 | + <td className="px-4 py-3 text-sm text-slate-600">{ROLE_DESCRIPTIONS[role]}</td> |
| 102 | + <td className="px-4 py-3"> |
| 103 | + <ul className="space-y-0.5"> |
| 104 | + {ROLE_KEY_PERMISSIONS[role].map(perm => ( |
| 105 | + <li key={perm} className="text-xs text-slate-500"> |
| 106 | + {perm} |
| 107 | + </li> |
| 108 | + ))} |
| 109 | + </ul> |
| 110 | + </td> |
| 111 | + </tr> |
| 112 | + ))} |
| 113 | + </tbody> |
| 114 | + </table> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + </main> |
| 120 | + ); |
| 121 | +} |
0 commit comments