| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /** @var list<\App\Domain\User> $users */
- /** @var \App\Domain\User $currentUser */
- /** @var string $csrfToken */
- /** @var string $flash */
- /** @var string $error */
- use function App\Http\e;
- $errorMessages = [
- 'self_demote' => 'You cannot demote yourself — ask another admin.',
- 'last_admin' => 'Cannot demote the last remaining admin.',
- 'not_found' => 'User not found.',
- 'db_error' => 'Could not save. Try again.',
- ];
- $flashMessages = [
- 'promoted' => 'Admin granted.',
- 'demoted' => 'Admin revoked.',
- 'noop' => 'Nothing changed.',
- ];
- ?>
- <section class="space-y-6">
- <div>
- <h1 class="text-2xl font-semibold tracking-tight">Users</h1>
- <p class="text-slate-600 text-sm mt-1 max-w-prose">
- Everyone who has ever signed in. Toggle admin status here; you
- cannot demote yourself or the last admin. Users are never deleted
- — inactive accounts simply stop signing in.
- </p>
- </div>
- <?php if ($error !== '' && isset($errorMessages[$error])): ?>
- <div class="rounded-md border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800">
- <?= e($errorMessages[$error]) ?>
- </div>
- <?php endif; ?>
- <?php if ($flash !== '' && isset($flashMessages[$flash])): ?>
- <div class="rounded-md border border-green-200 bg-green-50 px-4 py-3 text-sm text-green-800">
- <?= e($flashMessages[$flash]) ?>
- </div>
- <?php endif; ?>
- <div class="rounded-lg border bg-white overflow-hidden">
- <?php if ($users === []): ?>
- <div class="p-8 text-center text-slate-500 text-sm">No users yet.</div>
- <?php else: ?>
- <table class="min-w-full text-sm">
- <thead class="bg-slate-50 text-slate-600 text-xs uppercase tracking-wider">
- <tr>
- <th class="text-left px-4 py-2 font-semibold">Email</th>
- <th class="text-left px-4 py-2 font-semibold">Display name</th>
- <th class="text-left px-4 py-2 font-semibold">Last login (UTC)</th>
- <th class="text-left px-4 py-2 font-semibold">Admin</th>
- <th class="text-right px-4 py-2 font-semibold"> </th>
- </tr>
- </thead>
- <tbody class="divide-y divide-slate-100">
- <?php foreach ($users as $u): $isSelf = $u->id === $currentUser->id; ?>
- <tr>
- <form method="post" action="/users/<?= (int) $u->id ?>" class="contents">
- <input type="hidden" name="_csrf" value="<?= e($csrfToken) ?>">
- <td class="px-4 py-2 font-mono text-xs">
- <?= e($u->email) ?>
- <?php if ($isSelf): ?>
- <span class="ml-1 inline-block px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider bg-slate-100 text-slate-700 rounded">you</span>
- <?php endif; ?>
- </td>
- <td class="px-4 py-2"><?= e($u->displayName) ?></td>
- <td class="px-4 py-2 text-slate-500 font-mono text-xs">
- <?= $u->lastLoginAt !== null ? e($u->lastLoginAt) : '<span class="text-slate-400">—</span>' ?>
- </td>
- <td class="px-4 py-2">
- <label class="inline-flex items-center gap-2">
- <input name="is_admin" type="checkbox" value="1"
- <?= $u->isAdmin ? 'checked' : '' ?>
- <?= $isSelf && $u->isAdmin ? 'disabled title="You cannot demote yourself"' : '' ?>
- class="rounded border-slate-300">
- <span class="text-slate-600">admin</span>
- </label>
- </td>
- <td class="px-4 py-2 text-right">
- <button type="submit"
- class="rounded-md border border-slate-300 bg-white text-slate-700 px-3 py-1 text-sm hover:bg-slate-100">
- Save
- </button>
- </td>
- </form>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- </div>
- </section>
|