Skip to content

Commit 57e4a90

Browse files
HaoNguyen-Ronimrim12
authored andcommitted
refactor: user ui
1 parent 2b15736 commit 57e4a90

File tree

6 files changed

+382
-96
lines changed

6 files changed

+382
-96
lines changed

app/components/roles/AddEditRoleDialog.vue

+79-93
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import { VForm } from 'vuetify/components/VForm'
33
import { usePermissionStore } from '~/stores/admin/permission'
4-
import { type Role, useRoleStore } from '~/stores/admin/role'
54
65
interface Props {
76
isDialogVisible: boolean
@@ -15,10 +14,9 @@ interface Emit {
1514
const props = defineProps<Props>()
1615
const emit = defineEmits<Emit>()
1716
18-
const roleStore = useRoleStore()
19-
const { roleList } = storeToRefs(roleStore)
2017
const permissionStore = usePermissionStore()
2118
const { permissionList } = storeToRefs(permissionStore)
19+
const { fetchPermissions } = permissionStore
2220
2321
const refPermissionForm = ref<VForm>()
2422
const isFormValid = ref(false)
@@ -29,20 +27,32 @@ const localRoleData = ref<Partial<Role>>({
2927
name: '',
3028
})
3129
32-
// const checkedCount = computed(() => {
33-
// let counter = 0
34-
35-
// permissions.value.forEach((permission) => {
36-
// Object.entries(permission).forEach(([key, value]) => {
37-
// if (key !== 'name' && value)
38-
// counter++
39-
// })
40-
// })
41-
42-
// return counter
43-
// })
44-
45-
// const isIndeterminate = computed(() => checkedCount.value > 0 && checkedCount.value < (permissions.value.length * 3))
30+
const permissions = [
31+
{
32+
action: 'Read',
33+
subject: 'All',
34+
value: {
35+
action: 'read',
36+
subject: 'all',
37+
},
38+
},
39+
{
40+
action: 'Read',
41+
subject: 'Category',
42+
value: {
43+
action: 'read',
44+
subject: 'category',
45+
},
46+
},
47+
{
48+
action: 'Create',
49+
subject: 'All',
50+
value: {
51+
action: 'create',
52+
subject: 'all',
53+
},
54+
},
55+
]
4656
4757
// // select all
4858
// watch(isSelectAll, (val) => {
@@ -116,11 +126,15 @@ watch(() => props.roleData, (newRoleData) => {
116126
localRoleData.value = { ...newRoleData }
117127
}
118128
}, { immediate: true })
129+
130+
onMounted(() => {
131+
fetchPermissions()
132+
})
119133
</script>
120134

121135
<template>
122136
<VDialog
123-
:width="$vuetify.display.smAndDown ? 'auto' : 900"
137+
:width="$vuetify.display.smAndDown ? '100%' : 900"
124138
:model-value="props.isDialogVisible"
125139
@update:model-value="onReset"
126140
>
@@ -146,69 +160,59 @@ watch(() => props.roleData, (newRoleData) => {
146160
<VTextField
147161
v-model="localRoleData.name"
148162
:rules="[requiredValidator]"
163+
class="mb-6"
149164
label="Role Name"
150165
placeholder="Enter Role Name"
151166
/>
152167

153-
<h5 class="text-h5 my-6">
154-
Role Permissions
155-
</h5>
156-
157-
<!-- 👉 Role Permissions -->
158-
159-
<VTable class="permission-table text-no-wrap">
160-
<!-- 👉 Admin -->
161-
<!-- <tr>
162-
<td class="text-h6">
163-
Admin
164-
</td>
165-
<td colspan="3">
166-
<div class="d-flex justify-end">
167-
<VCheckbox
168-
v-model="isSelectAll"
169-
v-model:indeterminate="isIndeterminate"
170-
label="Select All"
168+
<!-- 👉 Role filter -->
169+
<VRow>
170+
<VCol cols="12" md="4" class="d-flex align-center">
171+
<h5 class="text-h5">
172+
Role Permissions
173+
</h5>
174+
</VCol>
175+
176+
<VCol cols="12" md="8">
177+
<div class="d-flex align-center gap-3 flex-wrap">
178+
<p>
179+
Select:
180+
</p>
181+
182+
<VBtn
183+
color="secondary"
184+
variant="text"
185+
text="All"
186+
/>
187+
188+
<VBtn
189+
color="secondary"
190+
variant="text"
191+
text="None"
192+
/>
193+
194+
<div class="flex-grow-1">
195+
<VTextField
196+
v-model="search"
197+
placeholder="Search"
198+
density="compact"
199+
prepend-inner-icon="ri-search-line"
171200
/>
172201
</div>
173-
</td>
174-
</tr> -->
202+
</div>
203+
</VCol>
204+
</VRow>
175205

176-
<!-- 👉 Other permission loop -->
177-
<!-- <template
178-
v-for="permission in permissionList"
179-
:key="permission.id"
180-
>
181-
<tr>
182-
<td class="text-h6">
183-
{{ permission.action }}
184-
</td>
185-
<td style="inline-size: 5.75rem;">
186-
<div class="d-flex justify-end">
187-
<VCheckbox
188-
v-model="permission.read"
189-
label="Read"
190-
/>
191-
</div>
192-
</td>
193-
<td style="inline-size: 5.75rem;">
194-
<div class="d-flex justify-end">
195-
<VCheckbox
196-
v-model="permission.write"
197-
label="Write"
198-
/>
199-
</div>
200-
</td>
201-
<td style="inline-size: 5.75rem;">
202-
<div class="d-flex justify-end">
203-
<VCheckbox
204-
v-model="permission.create"
205-
label="Create"
206-
/>
207-
</div>
208-
</td>
209-
</tr>
210-
</template> -->
211-
</VTable>
206+
<!-- 👉 Role Permissions -->
207+
<div class="mt-6 d-flex flex-wrap gap-3">
208+
<div v-for="permission in permissionList" :key="permission.id" class="d-flex align-center gap-2 flex-wrap border px-3 py-2">
209+
<VLabel>
210+
<VCheckboxBtn />
211+
212+
{{ permission.action }}:{{ permission.subject }}
213+
</VLabel>
214+
</div>
215+
</div>
212216

213217
<!-- 👉 Actions button -->
214218
<div class="d-flex align-center justify-center gap-3 mt-6">
@@ -230,23 +234,5 @@ watch(() => props.roleData, (newRoleData) => {
230234
</VDialog>
231235
</template>
232236

233-
<style lang="scss">
234-
.permission-table {
235-
td {
236-
border-block-end: 1px solid rgba(var(--v-border-color), var(--v-border-opacity));
237-
padding-block: 0.625rem;
238-
239-
.v-checkbox {
240-
min-inline-size: 4.75rem;
241-
}
242-
243-
&:not(:first-child) {
244-
padding-inline: 0.75rem;
245-
}
246-
247-
.v-label {
248-
white-space: nowrap;
249-
}
250-
}
251-
}
237+
<style lang="scss" scoped>
252238
</style>

app/pages/test-role.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface RoleDialog {
1717
1818
const roleStore = useRoleStore()
1919
const { roleList, totalRoles, roleDetail } = storeToRefs(roleStore)
20-
const { fetchRoles, fetchRoleDetail, createRole, updateRole, deleteRole } = roleStore
20+
const { fetchRoles, fetchRoleDetail, createRole, updateRole, deleteRole, joinRolePermissions } = roleStore
2121
2222
const currentRoleId = ref<string>('')
2323
const currentRoleData = ref<Partial<Role>>({
@@ -106,6 +106,7 @@ async function handleConfirmDeleteRole(isConfirm: boolean) {
106106
useLazyAsyncData(
107107
async () => {
108108
await fetchRoles()
109+
await joinRolePermissions()
109110
},
110111
)
111112
</script>

0 commit comments

Comments
 (0)