Add admin page that can edit users
All checks were successful
/ build (push) Successful in 1m30s
/ deploy (push) Successful in 16s

Add admin page that's only accessible to admins with a listing of users
and the ability to edit the access types of those users.
This commit is contained in:
Hornwitser 2025-06-23 00:20:33 +02:00
parent 3be7f8be05
commit 87525a6ef5
5 changed files with 170 additions and 0 deletions

View file

@ -11,6 +11,9 @@
<li v-if="accountStore.canEdit">
<NuxtLink to="/edit">Edit</NuxtLink>
</li>
<li v-if="accountStore.isAdmin">
<NuxtLink to="/admin">Admin</NuxtLink>
</li>
</ul>
</nav>
<div class="account">

73
components/TableUsers.vue Normal file
View file

@ -0,0 +1,73 @@
<template>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Type</th>
<th>Last Update</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="user in usersStore.users.values()">
<td>{{ user.id }}</td>
<td>
{{ user.name }}
</td>
<td>
<select
v-if='user.type !== "anonymous"'
v-model="user.type"
>
<option value="regular">Regular</option>
<option value="crew">Crew</option>
<option value="admin">Admin</option>
</select>
<template v-else>
{{ user.type }}
</template>
</td>
<td>
{{ user.updatedAt.toFormat("yyyy-LL-dd HH:mm") }}
</td>
<td>
<button
v-if="user.isModified()"
type="button"
@click="saveUser(user);"
>Save</button>
<button
v-if="user.isModified()"
type="button"
@click="user.discard()"
>Discard</button>
</td>
</tr>
</tbody>
</table>
</template>
<script lang="ts" setup>
import { DateTime } from 'luxon';
useEventSource();
const usersStore = useUsersStore();
await usersStore.fetch();
async function saveUser(user: ClientUser) {
try {
await $fetch("/api/admin/user", {
method: "PATCH",
body: user.toApi(),
});
} catch (err: any) {
console.error(err);
alert(err?.data?.message ?? err.message);
}
}
</script>
<style>
</style>