@frigear-nu/users 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/module.d.mts +1 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +8 -10
  5. package/dist/runtime/app/components/UserCreateSlideover.d.vue.ts +11 -0
  6. package/dist/runtime/app/components/UserCreateSlideover.vue +91 -0
  7. package/dist/runtime/app/components/UserCreateSlideover.vue.d.ts +11 -0
  8. package/dist/runtime/app/composables/useUserActions.d.ts +29 -0
  9. package/dist/runtime/app/composables/useUserActions.js +71 -0
  10. package/dist/runtime/app/pages/admin-user.vue +32 -15
  11. package/dist/runtime/app/pages/admin.vue +98 -187
  12. package/dist/runtime/app/tabs/Overview.d.vue.ts +2 -2
  13. package/dist/runtime/app/tabs/Overview.vue +37 -98
  14. package/dist/runtime/app/tabs/Overview.vue.d.ts +2 -2
  15. package/dist/runtime/app/utils/admin-user.d.ts +29 -3
  16. package/dist/runtime/app/utils/admin-user.js +1 -0
  17. package/dist/runtime/app/widgets/NewUsers.vue +49 -0
  18. package/dist/runtime/app/widgets/NewUsersStat.vue +18 -0
  19. package/dist/runtime/db/email-changes.postgresql.d.ts +194 -0
  20. package/dist/runtime/db/email-changes.postgresql.js +16 -0
  21. package/dist/runtime/db/schema.postgresql.d.ts +126 -0
  22. package/dist/runtime/db/schema.postgresql.js +10 -0
  23. package/dist/runtime/i18n/lang/da.json +25 -20
  24. package/dist/runtime/i18n/lang/en.json +25 -20
  25. package/dist/runtime/server/routes/admin/stats.get.js +1 -1
  26. package/dist/runtime/server/user-store.js +41 -11
  27. package/package.json +19 -17
  28. package/dist/runtime/app/widgets/NewMembers.vue +0 -45
  29. package/dist/runtime/app/widgets/NewMembersStat.vue +0 -20
  30. /package/dist/runtime/app/widgets/{NewMembers.d.vue.ts → NewUsers.d.vue.ts} +0 -0
  31. /package/dist/runtime/app/widgets/{NewMembers.vue.d.ts → NewUsers.vue.d.ts} +0 -0
  32. /package/dist/runtime/app/widgets/{NewMembersStat.d.vue.ts → NewUsersStat.d.vue.ts} +0 -0
  33. /package/dist/runtime/app/widgets/{NewMembersStat.vue.d.ts → NewUsersStat.vue.d.ts} +0 -0
  34. /package/dist/runtime/server/routes/admin/{new-members.get.d.ts → new.get.d.ts} +0 -0
  35. /package/dist/runtime/server/routes/admin/{new-members.get.js → new.get.js} +0 -0
@@ -1,34 +1,18 @@
1
1
  <script setup>
2
+ import { ADMIN_USERS_KEY } from "../utils/admin-user";
3
+ import { useUserActions } from "../composables/useUserActions";
2
4
  defineOptions({ name: "UsersAdminPage" });
3
5
  const t = useModuleT("users");
4
- const toast = useToast();
5
- const route = useRoute();
6
- const userPath = (id) => `${route.path.replace(/\/+$/, "")}/${id}`;
7
- const search = ref("");
8
- const q = ref("");
9
- let searchTimer;
10
- watch(search, (value) => {
11
- clearTimeout(searchTimer);
12
- searchTimer = setTimeout(() => {
13
- q.value = value.trim();
14
- }, 300);
6
+ const format = useFormat();
7
+ const actions = useUserActions();
8
+ const { page, pageSize, search, sort: sortState, filters, query, filtered, reset } = useTableQuery({
9
+ sort: { id: "createdAt", desc: true },
10
+ filters: { verified: "all", role: "all" }
15
11
  });
16
- onBeforeUnmount(() => clearTimeout(searchTimer));
17
- const verified = ref("all");
18
- const role = ref("all");
19
- const page = ref(1);
20
- const pageSize = ref(20);
21
- const sorting = ref([{ id: "createdAt", desc: true }]);
22
- const query = computed(() => ({
23
- page: page.value,
24
- pageSize: pageSize.value,
25
- q: q.value || void 0,
26
- verified: verified.value === "all" ? void 0 : verified.value,
27
- role: role.value === "all" ? void 0 : role.value,
28
- sort: sorting.value[0]?.id,
29
- order: sorting.value[0] ? sorting.value[0].desc ? "desc" : "asc" : void 0
30
- }));
12
+ const sort = useTableSort(null, sortState);
13
+ const { sorting } = sort;
31
14
  const { data, status } = await useFetch("/api/admin/users", {
15
+ key: ADMIN_USERS_KEY,
32
16
  query,
33
17
  default: () => ({ items: [], total: 0, page: 1, pageSize: 20, hasRoles: false, hasSubscriptions: false, roles: [] })
34
18
  });
@@ -37,216 +21,143 @@ const hasSubscriptions = computed(() => data.value.hasSubscriptions);
37
21
  const roleLabel = (value) => t(`admin.roleNames.${value}`, value.charAt(0).toUpperCase() + value.slice(1));
38
22
  const roleItems = computed(() => data.value.roles.map((value) => ({ label: roleLabel(value), value })));
39
23
  const roleFilterItems = computed(() => [{ label: t("admin.filters.allRoles", "All roles"), value: "all" }, ...roleItems.value]);
40
- const loading = computed(() => status.value === "pending");
41
- watch([q, verified, role, pageSize, sorting], () => {
42
- page.value = 1;
43
- });
44
- const dateFormat = (value) => value ? new Date(value).toLocaleString() : "\u2013";
45
- const sortable = (accessorKey, label) => ({
46
- accessorKey,
47
- header: () => h(resolveComponent("UButton"), {
48
- color: "neutral",
49
- variant: "ghost",
50
- label,
51
- class: "-mx-2.5",
52
- icon: sorting.value[0]?.id === accessorKey ? sorting.value[0].desc ? "i-lucide-arrow-down" : "i-lucide-arrow-up" : "i-lucide-arrow-up-down",
53
- onClick: () => {
54
- const current = sorting.value[0];
55
- sorting.value = [{ id: accessorKey, desc: current?.id === accessorKey ? !current.desc : false }];
56
- }
57
- })
58
- });
24
+ const pending = computed(() => status.value === "pending");
25
+ const loading = computed(() => pending.value && !data.value.items.length);
26
+ const refreshing = computed(() => pending.value && !!data.value.items.length);
27
+ const UBadge = resolveComponent("UBadge");
28
+ const TableIdentity = resolveComponent("TableIdentity");
29
+ const RowMenu = resolveComponent("RowMenu");
30
+ const dateCell = (value) => value ? h("time", { datetime: value, title: format.dateTime(value), class: "tabular-nums" }, format.date(value)) : emptyCell();
59
31
  const columns = computed(() => [
60
- sortable("id", "ID"),
61
- sortable("name", t("admin.name", "Name")),
62
- sortable("email", t("admin.email", "Email")),
63
- ...hasRoles.value ? [{ ...sortable("role", t("admin.role", "Role")), cell: ({ row }) => row.original.role ? roleLabel(row.original.role) : "\u2013" }] : [],
32
+ {
33
+ accessorKey: "name",
34
+ header: sort.header("name", t("admin.user", "User")),
35
+ cell: ({ row }) => h(TableIdentity, {
36
+ title: row.original.name,
37
+ description: row.original.email,
38
+ avatar: { alt: row.original.name }
39
+ })
40
+ },
41
+ ...hasRoles.value ? [{
42
+ accessorKey: "role",
43
+ header: sort.header("role", t("admin.role", "Role")),
44
+ cell: ({ row }) => row.original.role ? roleLabel(row.original.role) : emptyCell()
45
+ }] : [],
64
46
  ...hasSubscriptions.value ? [{
65
47
  id: "subscription",
66
48
  header: t("admin.subscription", "Subscription"),
67
49
  cell: ({ row }) => {
68
50
  const subscription = row.original.subscription;
69
- return subscription ? h(resolveComponent("UBadge"), {
70
- variant: "subtle",
71
- color: ["active", "trialing"].includes(subscription.status) ? "success" : "neutral",
72
- label: subscription.planKey ?? subscription.status
73
- }) : "\u2013";
51
+ return subscription ? h(UBadge, { variant: "subtle", color: statusColor(subscription.status), label: subscription.planKey ?? subscription.status }) : emptyCell();
74
52
  }
75
53
  }] : [],
76
- { id: "verified", header: t("admin.verified", "Verified"), cell: ({ row }) => row.original.emailVerifiedAt ? "\u2713" : "\u2013" },
77
- { ...sortable("lastLoginAt", t("admin.lastLogin", "Last sign-in")), cell: ({ row }) => dateFormat(row.original.lastLoginAt) },
78
- { ...sortable("createdAt", t("admin.created", "Created")), cell: ({ row }) => dateFormat(row.original.createdAt) }
54
+ {
55
+ id: "verified",
56
+ header: t("admin.verified", "Verified"),
57
+ cell: ({ row }) => h(UBadge, {
58
+ variant: "subtle",
59
+ color: row.original.emailVerifiedAt ? "success" : "neutral",
60
+ label: row.original.emailVerifiedAt ? t("admin.filters.verified", "Verified") : t("admin.filters.unverified", "Unverified")
61
+ })
62
+ },
63
+ { accessorKey: "lastLoginAt", header: sort.header("lastLoginAt", t("admin.lastLogin", "Last sign-in")), cell: ({ row }) => dateCell(row.original.lastLoginAt) },
64
+ { accessorKey: "createdAt", header: sort.header("createdAt", t("admin.created", "Created")), cell: ({ row }) => dateCell(row.original.createdAt) },
65
+ {
66
+ accessorKey: "id",
67
+ header: sort.header("id", "ID"),
68
+ meta: { class: { th: "w-0", td: "w-0 text-dimmed tabular-nums" } }
69
+ },
70
+ {
71
+ id: "actions",
72
+ meta: { class: { th: "w-0", td: "w-0" } },
73
+ cell: ({ row }) => h(RowMenu, { items: actions.menu(row.original), subject: row.original.name })
74
+ }
79
75
  ]);
80
76
  const verifiedOptions = computed(() => [
81
77
  { label: t("admin.filters.all", "All"), value: "all" },
82
78
  { label: t("admin.filters.verified", "Verified"), value: "true" },
83
79
  { label: t("admin.filters.unverified", "Unverified"), value: "false" }
84
80
  ]);
85
- const pageSizes = [10, 20, 50, 100];
86
- const filtersActive = computed(() => !!(search.value || role.value !== "all" || verified.value !== "all"));
87
- function resetFilters() {
88
- search.value = "";
89
- role.value = "all";
90
- verified.value = "all";
91
- }
92
- const open = ref(false);
93
- const form = reactive({ name: "", email: "", role: "", emailVerified: false, sendWelcomeEmail: true });
94
- const saving = ref(false);
95
- function startCreate() {
96
- Object.assign(form, { name: "", email: "", role: "", emailVerified: false, sendWelcomeEmail: true });
97
- open.value = true;
98
- }
99
81
  function openUser(_event, row) {
100
- return navigateTo(userPath(row.original.id));
82
+ return navigateTo(actions.userPath(row.original.id));
101
83
  }
102
- async function save() {
103
- saving.value = true;
104
- try {
105
- const created = await $fetch("/api/admin/users", {
106
- method: "POST",
107
- body: { ...form, role: hasRoles.value && form.role ? form.role : void 0 }
108
- });
109
- open.value = false;
110
- toast.add({ title: t("admin.created_ok", "User created."), color: "success" });
111
- await navigateTo(userPath(created.id));
112
- } catch (cause) {
113
- toast.add({ title: cause.statusMessage ?? t("admin.error", "Something went wrong."), color: "error" });
114
- } finally {
115
- saving.value = false;
116
- }
84
+ async function addUser() {
85
+ const created = await actions.create({ roles: hasRoles.value ? data.value.roles : [] });
86
+ if (created) await navigateTo(actions.userPath(created.id));
117
87
  }
118
88
  </script>
119
89
 
120
90
  <template>
121
- <AdminPage>
122
- <AdminPageHeader :title="t('admin.title', 'Users')">
123
- <template #links>
91
+ <div class="flex flex-col gap-4">
92
+ <PageHeading :title="t('admin.title', 'Users')">
93
+ <template #actions>
124
94
  <UButton
125
95
  icon="i-lucide-user-plus"
126
- :label="t('admin.create', 'Create user')"
127
- @click="startCreate"
96
+ :label="t('admin.create', 'Add user')"
97
+ @click="addUser"
128
98
  />
129
99
  </template>
130
- </AdminPageHeader>
131
- <AdminToolbar>
100
+ </PageHeading>
101
+
102
+ <PageToolbar>
132
103
  <UInput
133
104
  v-model="search"
134
105
  class="w-full max-w-sm"
135
106
  icon="i-lucide-search"
136
- :loading="loading"
107
+ :loading="pending"
137
108
  :placeholder="t('admin.search', 'Search name, email or role...')"
138
109
  />
139
110
  <USelect
140
- v-model="verified"
111
+ v-model="filters.verified"
141
112
  :items="verifiedOptions"
142
113
  class="w-40"
143
114
  />
144
115
  <USelect
145
116
  v-if="hasRoles"
146
- v-model="role"
117
+ v-model="filters.role"
147
118
  :items="roleFilterItems"
148
119
  class="w-48"
149
120
  icon="i-lucide-shield"
150
121
  />
151
122
  <UButton
152
- v-if="filtersActive"
123
+ v-if="filtered"
153
124
  variant="ghost"
154
125
  color="neutral"
155
126
  icon="i-lucide-x"
156
127
  :label="t('admin.filters.clear', 'Clear filters')"
157
- @click="resetFilters"
128
+ @click="reset"
158
129
  />
159
- </AdminToolbar>
160
- <AdminTable
161
- :data="data.items"
162
- :columns="columns"
130
+ </PageToolbar>
131
+
132
+ <TableCard
163
133
  :loading="loading"
164
- @select="openUser"
134
+ :refreshing="refreshing"
165
135
  >
166
- <template #empty>
167
- <AdminEmpty
168
- icon="i-lucide-users"
169
- :title="t('admin.empty', 'No users match.')"
170
- />
171
- </template>
172
- </AdminTable>
173
- <div class="flex flex-wrap items-center justify-between gap-3">
174
- <div class="flex items-center gap-3 text-sm text-muted">
175
- <span>{{ t("admin.total", "{count} users", { count: data.total }) }}</span>
176
- <USelect
177
- v-model="pageSize"
178
- :items="pageSizes"
179
- class="w-20"
180
- />
181
- </div>
182
- <UPagination
183
- v-model:page="page"
184
- :items-per-page="pageSize"
185
- :total="data.total"
186
- />
187
- </div>
188
- <UModal
189
- v-model:open="open"
190
- :title="t('admin.create', 'Create user')"
191
- >
192
- <template #body>
193
- <form
194
- id="admin-user-form"
195
- class="flex flex-col gap-4"
196
- @submit.prevent="save"
197
- >
198
- <UFormField :label="t('admin.name', 'Name')">
199
- <UInput
200
- v-model="form.name"
201
- class="w-full"
202
- required
203
- />
204
- </UFormField>
205
- <UFormField :label="t('admin.email', 'Email')">
206
- <UInput
207
- v-model="form.email"
208
- type="email"
209
- class="w-full"
210
- required
211
- />
212
- </UFormField>
213
- <UFormField
214
- v-if="hasRoles"
215
- :label="t('admin.role', 'Role')"
216
- >
217
- <USelect
218
- v-model="form.role"
219
- :items="roleItems"
220
- class="w-full"
221
- :placeholder="t('admin.rolePlaceholder', 'Select a role')"
222
- />
223
- </UFormField>
224
- <UCheckbox
225
- v-model="form.emailVerified"
226
- :label="t('admin.emailVerified', 'Mark the email address as verified')"
136
+ <UTable
137
+ v-model:sorting="sorting"
138
+ :data="data.items"
139
+ :columns="columns"
140
+ :sorting-options="{ manualSorting: true }"
141
+ :ui="tableUi({}, { sticky: true })"
142
+ sticky
143
+ @select="openUser"
144
+ >
145
+ <template #empty>
146
+ <UEmpty
147
+ icon="i-lucide-users"
148
+ variant="naked"
149
+ :title="t('admin.empty', 'No users match')"
150
+ :actions="[filtered ? { label: t('admin.filters.clear', 'Clear filters'), color: 'neutral', variant: 'outline', onClick: reset } : { label: t('admin.create', 'Add user'), icon: 'i-lucide-user-plus', onClick: addUser }]"
227
151
  />
228
- <UCheckbox
229
- v-model="form.sendWelcomeEmail"
230
- :label="t('admin.sendWelcome', 'Email a sign-in link')"
231
- />
232
- </form>
233
- </template>
152
+ </template>
153
+ </UTable>
234
154
  <template #footer>
235
- <div class="flex w-full justify-end gap-2">
236
- <UButton
237
- variant="subtle"
238
- color="neutral"
239
- :label="t('admin.cancel', 'Cancel')"
240
- @click="open = false"
241
- />
242
- <UButton
243
- type="submit"
244
- form="admin-user-form"
245
- :loading="saving"
246
- :label="t('admin.save', 'Save')"
247
- />
248
- </div>
155
+ <TablePagination
156
+ v-model:page="page"
157
+ v-model:page-size="pageSize"
158
+ :total="data.total"
159
+ />
249
160
  </template>
250
- </UModal>
251
- </AdminPage>
161
+ </TableCard>
162
+ </div>
252
163
  </template>
@@ -1,6 +1,6 @@
1
- import type { AdminUserDetail } from '../utils/admin-user.js';
1
+ import type { UserDetail } from '../utils/admin-user.js';
2
2
  type __VLS_Props = {
3
- user: AdminUserDetail;
3
+ user: UserDetail;
4
4
  };
5
5
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
6
  refresh: () => any;
@@ -1,14 +1,14 @@
1
1
  <script setup>
2
+ import { useUserActions } from "../composables/useUserActions";
2
3
  defineOptions({ name: "UsersAdminOverviewTab" });
3
4
  const props = defineProps({
4
5
  user: { type: Object, required: true }
5
6
  });
6
7
  const emit = defineEmits(["refresh"]);
7
8
  const t = useModuleT("users");
8
- const route = useRoute();
9
- const toast = useToast();
10
- const id = computed(() => props.user.id);
11
- const listPath = computed(() => route.path.replace(/\/[^/]+\/?$/, ""));
9
+ const format = useFormat();
10
+ const actions = useUserActions();
11
+ const { busy: saving, run } = useAction();
12
12
  const OverviewWidgets = resolveComponent("WidgetArea");
13
13
  const overviewWidgets = typeof OverviewWidgets === "string" ? void 0 : OverviewWidgets;
14
14
  const form = reactive({ name: "", email: "", role: "", emailVerified: false });
@@ -24,22 +24,16 @@ const roleItems = computed(() => {
24
24
  return [...roles].map((value) => ({ label: roleLabel(value), value }));
25
25
  });
26
26
  const accountFacts = computed(() => [
27
- { key: "created", label: t("admin.created", "Created"), value: dateFormat(props.user.createdAt) },
28
- { key: "lastLogin", label: t("admin.lastLogin", "Last sign-in"), value: dateFormat(props.user.lastLoginAt) },
29
- { key: "password", label: t("admin.detail.password", "Password"), value: props.user.hasPassword ? t("admin.detail.set", "Set") : t("admin.detail.notSet", "Not set") },
27
+ { key: "created", label: t("admin.created", "Created"), value: format.dateTime(props.user.createdAt) },
28
+ { key: "lastLogin", label: t("admin.lastLogin", "Last sign-in"), value: format.dateTime(props.user.lastLoginAt) || t("admin.detail.never", "Never") },
29
+ { key: "password", label: t("admin.detail.password", "Password"), value: props.user.hasPassword ? t("admin.detail.set", "Set") : null },
30
30
  { key: "passkeys", label: t("admin.detail.passkeys", "Passkeys"), value: props.user.passkeys }
31
31
  ]);
32
- const dateFormat = (value) => value ? new Date(value).toLocaleString() : "\u2013";
33
32
  const dirty = computed(() => form.name !== props.user.name || form.email !== props.user.email || props.user.hasRoles && form.role !== (props.user.role ?? "") || form.emailVerified !== !!props.user.emailVerifiedAt);
34
- function fail(cause) {
35
- toast.add({ title: cause.statusMessage ?? t("admin.error", "Something went wrong."), color: "error" });
36
- }
37
- const saving = ref(false);
38
33
  async function save() {
39
- saving.value = true;
40
- try {
41
- const emailChanged = form.email !== props.user.email;
42
- await $fetch(`/api/admin/users/${id.value}`, {
34
+ const emailChanged = form.email !== props.user.email;
35
+ const saved = await run(
36
+ () => $fetch(`/api/admin/users/${props.user.id}`, {
43
37
  method: "PATCH",
44
38
  body: {
45
39
  name: form.name,
@@ -48,49 +42,20 @@ async function save() {
48
42
  // An unchanged address keeps its state unless staff toggled it; a changed one is verified by email.
49
43
  ...emailChanged ? {} : { emailVerified: form.emailVerified }
50
44
  }
51
- });
52
- toast.add({
53
- title: emailChanged ? t("admin.detail.savedEmail", "Saved. A verification email was sent to the new address.") : t("admin.detail.saved", "Saved."),
54
- color: "success"
55
- });
56
- emit("refresh");
57
- } catch (cause) {
58
- fail(cause);
59
- } finally {
60
- saving.value = false;
61
- }
45
+ }).then(() => true),
46
+ { success: emailChanged ? t("admin.detail.savedEmail", "Saved. A verification email was sent to the new address.") : t("admin.detail.saved", "Saved.") }
47
+ );
48
+ if (saved) emit("refresh");
62
49
  }
63
- const resending = ref(false);
64
- async function resend() {
65
- resending.value = true;
66
- try {
67
- await $fetch(`/api/admin/users/${id.value}/resend`, { method: "POST" });
68
- toast.add({ title: t("admin.detail.resent", "Sign-in link sent."), color: "success" });
69
- } catch (cause) {
70
- fail(cause);
71
- } finally {
72
- resending.value = false;
50
+ const remove = () => actions.remove(props.user, {
51
+ onRemoved: async () => {
52
+ await navigateTo(actions.listPath.value);
73
53
  }
74
- }
75
- const confirmDelete = ref(false);
76
- const deleting = ref(false);
77
- async function remove() {
78
- deleting.value = true;
79
- try {
80
- await $fetch(`/api/admin/users/${id.value}`, { method: "DELETE" });
81
- toast.add({ title: t("admin.detail.deleted", "User deleted."), color: "success" });
82
- await navigateTo(listPath.value);
83
- } catch (cause) {
84
- fail(cause);
85
- } finally {
86
- deleting.value = false;
87
- confirmDelete.value = false;
88
- }
89
- }
54
+ });
90
55
  </script>
91
56
 
92
57
  <template>
93
- <div class="flex flex-col gap-6">
58
+ <div class="flex flex-col gap-4">
94
59
  <component
95
60
  :is="overviewWidgets"
96
61
  v-if="overviewWidgets"
@@ -98,9 +63,10 @@ async function remove() {
98
63
  :context="{ user }"
99
64
  />
100
65
 
101
- <div class="grid gap-6 lg:grid-cols-[2fr_1fr]">
102
- <AdminSection :title="t('admin.detail.profile', 'Profile')">
66
+ <div class="grid gap-4 lg:grid-cols-[2fr_1fr]">
67
+ <SectionCard :title="t('admin.detail.profile', 'Profile')">
103
68
  <form
69
+ id="user-profile-form"
104
70
  class="flex flex-col gap-4"
105
71
  @submit.prevent="save"
106
72
  >
@@ -141,66 +107,39 @@ async function remove() {
141
107
  :label="t('admin.emailVerified', 'Mark the email address as verified')"
142
108
  :disabled="!user.can.update || form.email !== user.email"
143
109
  />
110
+ </form>
111
+ <template #footer>
144
112
  <div class="flex justify-end">
145
113
  <UButton
146
114
  type="submit"
115
+ form="user-profile-form"
147
116
  :loading="saving"
148
117
  :disabled="!dirty || !user.can.update"
149
- :label="t('admin.save', 'Save')"
118
+ :label="t('admin.detail.saveProfile', 'Save profile')"
150
119
  />
151
120
  </div>
152
- </form>
153
- </AdminSection>
121
+ </template>
122
+ </SectionCard>
154
123
 
155
- <div class="flex flex-col gap-6">
156
- <AdminSection :title="t('admin.detail.account', 'Account')">
157
- <AdminKeyValue :items="accountFacts" />
158
- <UButton
159
- v-if="user.can.update"
160
- variant="outline"
161
- color="neutral"
162
- icon="i-lucide-mail"
163
- :loading="resending"
164
- :label="user.emailVerifiedAt ? t('admin.detail.sendLink', 'Email a sign-in link') : t('admin.detail.sendVerification', 'Resend verification email')"
165
- @click="resend"
166
- />
167
- </AdminSection>
124
+ <div class="flex flex-col gap-4">
125
+ <SectionCard :title="t('admin.detail.account', 'Account')">
126
+ <DescriptionList :items="accountFacts" />
127
+ </SectionCard>
168
128
 
169
- <AdminSection
129
+ <SectionCard
170
130
  v-if="user.can.delete"
171
131
  :title="t('admin.detail.danger', 'Danger zone')"
132
+ :description="t('admin.detail.dangerHint', 'Removes the account and its sign-in methods for good.')"
172
133
  >
173
134
  <UButton
174
135
  color="error"
175
136
  variant="soft"
176
137
  icon="i-lucide-trash-2"
177
- :label="t('admin.detail.delete', 'Delete user')"
178
- @click="confirmDelete = true"
138
+ :label="t('admin.deleteUser', 'Delete user')"
139
+ @click="remove"
179
140
  />
180
- </AdminSection>
141
+ </SectionCard>
181
142
  </div>
182
143
  </div>
183
-
184
- <UModal
185
- v-model:open="confirmDelete"
186
- :title="t('admin.detail.deleteTitle', 'Delete this user?')"
187
- :description="t('admin.detail.deleteBody', 'This permanently removes the account and its sign-in methods. It cannot be undone.')"
188
- >
189
- <template #footer>
190
- <div class="flex w-full justify-end gap-2">
191
- <UButton
192
- variant="subtle"
193
- :label="t('admin.cancel', 'Cancel')"
194
- @click="confirmDelete = false"
195
- />
196
- <UButton
197
- color="error"
198
- :loading="deleting"
199
- :label="t('admin.detail.delete', 'Delete user')"
200
- @click="remove"
201
- />
202
- </div>
203
- </template>
204
- </UModal>
205
144
  </div>
206
145
  </template>
@@ -1,6 +1,6 @@
1
- import type { AdminUserDetail } from '../utils/admin-user.js';
1
+ import type { UserDetail } from '../utils/admin-user.js';
2
2
  type __VLS_Props = {
3
- user: AdminUserDetail;
3
+ user: UserDetail;
4
4
  };
5
5
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
6
  refresh: () => any;
@@ -1,8 +1,30 @@
1
- export type AdminUserSubscription = {
1
+ export type UserSubscription = {
2
2
  planKey: string | null;
3
3
  status: string;
4
4
  };
5
- export type AdminUserDetail = {
5
+ /** One row of `GET /api/admin/users`. */
6
+ export type UserRow = {
7
+ id: number;
8
+ name: string;
9
+ email: string;
10
+ role?: string;
11
+ emailVerifiedAt: string | null;
12
+ lastLoginAt?: string | null;
13
+ createdAt: string;
14
+ subscription?: UserSubscription | null;
15
+ };
16
+ /** `GET /api/admin/users` */
17
+ export type UsersPage = {
18
+ items: UserRow[];
19
+ total: number;
20
+ page: number;
21
+ pageSize: number;
22
+ hasRoles: boolean;
23
+ hasSubscriptions: boolean;
24
+ roles: string[];
25
+ };
26
+ /** The shape of `GET /api/admin/users/:id`. */
27
+ export type UserDetail = {
6
28
  id: number;
7
29
  name: string;
8
30
  email: string;
@@ -12,7 +34,7 @@ export type AdminUserDetail = {
12
34
  createdAt: string;
13
35
  hasPassword: boolean;
14
36
  passkeys: number;
15
- subscription: AdminUserSubscription | null;
37
+ subscription: UserSubscription | null;
16
38
  hasRoles: boolean;
17
39
  roles: string[];
18
40
  can: {
@@ -20,3 +42,7 @@ export type AdminUserDetail = {
20
42
  delete: boolean;
21
43
  };
22
44
  };
45
+ /** What the actions need of a user: the list rows and the detail both satisfy it. */
46
+ export type UserSubject = Pick<UserRow, 'id' | 'name' | 'emailVerifiedAt'>;
47
+ /** The key of the list's `useFetch`, refreshed after a user is created or deleted. */
48
+ export declare const ADMIN_USERS_KEY = "admin-users";
@@ -0,0 +1 @@
1
+ export const ADMIN_USERS_KEY = "admin-users";