Skip to content

Commit bbfa0ed

Browse files
committed
feat: prepare user management
1 parent d6a3e5e commit bbfa0ed

File tree

1 file changed

+29
-98
lines changed

1 file changed

+29
-98
lines changed

app/pages/admin/users.vue

+29-98
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import type { UserWithRoles } from '@base/stores/admin/user'
44
import { avatarText } from '#imports'
55
import { useRoleStore } from '@base/stores/admin/role'
66
import { useUserStore } from '@base/stores/admin/user'
7-
import { sortBy } from 'lodash-es'
8-
// import UserList from '@base/components/roles/UserList.vue'
7+
import { match } from 'ts-pattern'
98
109
definePageMeta({
1110
sidebar: {
@@ -46,8 +45,10 @@ const headers = [
4645
{ title: 'User', key: 'name' },
4746
{ title: 'Email', key: 'email' },
4847
{ title: 'Role', key: 'role' },
49-
// { title: 'Plan', key: 'plan' },
5048
{ title: 'Status', key: 'status' },
49+
// TODO: user credits / subscriptions
50+
// { title: 'Plan', key: 'plan' },
51+
{ title: 'Verified', key: 'email_verified' },
5152
{ title: 'Actions', key: 'actions', sortable: false },
5253
]
5354
@@ -59,30 +60,10 @@ function handleUpdateOptions(options: any) {
5960
function resolveUserRoleVariant(role: string) {
6061
const roleLowerCase = role.toLowerCase()
6162
62-
if (roleLowerCase === 'subscriber')
63-
return { color: 'success', icon: 'ri-user-line' }
64-
if (roleLowerCase === 'author')
65-
return { color: 'error', icon: 'ri-computer-line' }
66-
if (roleLowerCase === 'maintainer')
67-
return { color: 'info', icon: 'ri-pie-chart-line' }
68-
if (roleLowerCase === 'editor')
69-
return { color: 'warning', icon: 'ri-edit-box-line' }
70-
if (roleLowerCase === 'admin')
71-
return { color: 'primary', icon: 'ri-vip-crown-line' }
72-
73-
return { color: 'success', icon: 'ri-user-line' }
74-
}
75-
76-
function resolveUserStatusVariant(stat: string) {
77-
const statLowerCase = stat.toLowerCase()
78-
if (statLowerCase === 'pending')
79-
return 'warning'
80-
if (statLowerCase === 'active')
81-
return 'success'
82-
if (statLowerCase === 'inactive')
83-
return 'secondary'
84-
85-
return 'primary'
63+
return match(roleLowerCase)
64+
.with('admin', () => ({ color: 'primary', icon: 'ri-vip-crown-line' }))
65+
.with('editor', () => ({ color: 'warning', icon: 'ri-edit-box-line' }))
66+
.otherwise(() => ({ color: 'success', icon: 'ri-user-line' }))
8667
}
8768
8869
async function handleDeleteUser(user: UserWithRoles) {
@@ -104,77 +85,25 @@ async function handleDeleteUser(user: UserWithRoles) {
10485
<VRow>
10586
<VCol cols="12">
10687
<VCard class="mb-6">
107-
<VCardItem class="pb-4">
108-
<VCardTitle>Filters</VCardTitle>
109-
</VCardItem>
110-
<VCardText>
111-
<VRow>
112-
<!-- 👉 Select Role -->
113-
<VCol
114-
cols="12"
115-
sm="4"
116-
>
117-
<VSelect
118-
v-model="selectedRole"
119-
label="Select Role"
120-
placeholder="Select Role"
121-
:items="roleData?.data || []"
122-
clearable
123-
clear-icon="ri-close-line"
124-
/>
125-
</VCol>
126-
<!-- 👉 Select Plan -->
127-
<!-- <VCol
128-
cols="12"
129-
sm="4"
130-
>
131-
<VSelect
132-
v-model="selectedPlan"
133-
label="Select Plan"
134-
placeholder="Select Plan"
135-
:items="plans"
136-
clearable
137-
clear-icon="ri-close-line"
138-
/>
139-
</VCol> -->
140-
<!-- 👉 Select Status -->
141-
<!-- <VCol
142-
cols="12"
143-
sm="4"
144-
>
145-
<VSelect
146-
v-model="selectedStatus"
147-
label="Select Status"
148-
placeholder="Select Status"
149-
:items="status"
150-
clearable
151-
clear-icon="ri-close-line"
152-
/>
153-
</VCol> -->
154-
</VRow>
155-
</VCardText>
156-
157-
<VDivider />
158-
15988
<VCardText class="d-flex flex-wrap gap-4 align-center">
16089
<!-- 👉 Export button -->
161-
<VBtn
162-
variant="outlined"
163-
color="secondary"
164-
prepend-icon="ri-upload-2-line"
165-
>
166-
Export
167-
</VBtn>
90+
<VSelect
91+
v-model="selectedRole"
92+
label="Select Role"
93+
placeholder="Select Role"
94+
:items="roleData?.data || []"
95+
clearable
96+
clear-icon="ri-close-line"
97+
/>
16898
<VSpacer />
16999
<div class="d-flex align-center gap-4 flex-wrap">
170100
<!-- 👉 Search -->
171-
<div class="app-user-search-filter">
172-
<VTextField
173-
v-model="userQuery.keyword"
174-
placeholder="Search User"
175-
density="compact"
176-
/>
177-
</div>
101+
<VTextField
102+
v-model="userQuery.keyword"
103+
placeholder="Search User"
104+
density="compact"
105+
style="min-width: 200px;"
106+
/>
178107
<!-- 👉 Add user button -->
179108
<VBtn>
180109
Add New User
@@ -228,21 +157,23 @@ async function handleDeleteUser(user: UserWithRoles) {
228157
:color="resolveUserRoleVariant(item.roles[0]?.role.name || '').color"
229158
size="22"
230159
/>
231-
<span class="text-capitalize text-high-emphasis">{{ item.roles[0]?.role.name || '' }}</span>
160+
<span class="text-capitalize text-high-emphasis">
161+
{{ item.roles[0]?.role.name || $t('No role') }}
162+
</span>
232163
</div>
233164
</template>
234-
<!-- TODO: user subscription -->
165+
<!-- TODO: user credits / subscriptions -->
235166
<!-- <template #item.plan="{ item }">
236167
<span class="text-capitalize text-high-emphasis">{{ item.currentPlan }}</span>
237168
</template> -->
238169
<!-- Status -->
239-
<template #item.status="{ item }">
170+
<template #item.email_verified="{ item }">
240171
<VChip
241-
:color="resolveUserStatusVariant(item.status || '')"
172+
:color="item.email_verified ? 'success' : 'secondary'"
242173
size="small"
243174
class="text-capitalize"
244175
>
245-
{{ item.status }}
176+
{{ item.email_verified ? $t('Verified') : $t('Pending') }}
246177
</VChip>
247178
</template>
248179

0 commit comments

Comments
 (0)