1
1
<script setup lang="ts">
2
+ import type { User , UserWithRoles } from ' @base/stores/admin/user'
3
+ import { emailValidator , requiredValidator } from ' #imports'
2
4
import { useOrganizationStore } from ' @base/stores/admin/organization'
3
5
import { useRoleStore } from ' @base/stores/admin/role'
4
6
import { cloneDeep } from ' lodash-es'
5
7
import { PerfectScrollbar } from ' vue3-perfect-scrollbar'
6
- import type { User , UserWithRoles } from ' @base/stores/admin/user'
7
- import { emailValidator , requiredValidator } from ' #imports'
8
8
9
9
const props = defineProps <{
10
10
user? : UserWithRoles
11
11
}>()
12
12
13
13
const emit = defineEmits <{
14
- (e : ' edit' , payload : Partial <User >): void
15
- (e : ' create' , payload : Partial <User >): void
14
+ (e : ' edit' , payload : Partial <User > & { roles : string [], organizations : string [] } ): void
15
+ (e : ' create' , payload : Partial <User > & { roles : string [], organizations : string [] } ): void
16
16
(e : ' cancel' ): void
17
17
}>()
18
18
19
19
const modelValue = defineModel <boolean >(' modelValue' , {
20
20
default: false ,
21
21
})
22
22
23
- // const roleStore = useRoleStore()
23
+ const roleStore = useRoleStore ()
24
+
25
+ const organizationStore = useOrganizationStore ()
26
+
27
+ const { data : roleData, execute : fetchRoles } = useAsyncData (() => roleStore .fetchRoles (), {
28
+ immediate: false ,
29
+ })
24
30
25
- // const organizationStore = useOrganizationStore()
31
+ const { data : organizationData, execute : fetchOrganizations } = useAsyncData (() => organizationStore .fetchOrganizations (), {
32
+ immediate: false ,
33
+ })
26
34
27
- function getDefaultFormData(): Partial <User > {
35
+ function getDefaultFormData(): Partial <User > & { roles : string [], organizations : string [] } {
28
36
return {
29
37
email: ' ' ,
30
- email_verified: new Date (),
31
38
phone: ' ' ,
32
39
password: ' ' ,
33
40
full_name: ' ' ,
34
41
avatar_url: ' ' ,
35
42
country: ' ' ,
36
43
language: ' ' ,
37
44
postcode: ' ' ,
38
- status: ' resolved ' ,
45
+ status: ' active ' ,
39
46
address: ' ' ,
40
47
city: ' ' ,
48
+ roles: [],
49
+ organizations: [],
41
50
}
42
51
}
43
52
@@ -46,6 +55,10 @@ const formData = ref(getDefaultFormData())
46
55
let syncStop: () => void
47
56
watch (modelValue , (value ) => {
48
57
if (value ) {
58
+ // non-block fetching
59
+ fetchRoles ()
60
+ fetchOrganizations ()
61
+
49
62
syncStop = syncRef (computed (() => props .user ), formData , {
50
63
direction: ' ltr' ,
51
64
transform: {
@@ -130,18 +143,17 @@ function handleCancel() {
130
143
<!-- 👉 Form -->
131
144
<VForm ref =" formRef" >
132
145
<VRow >
133
- <!-- TODO: Add Role -->
134
- <!-- <VCol cols="12">
146
+ <VCol cols =" 12" >
135
147
<VSelect
136
- v-model="formData.role_id "
148
+ v-model =" formData.roles "
137
149
label =" Select Role"
138
- :rules="[requiredValidator]"
150
+ multiple
151
+ :items =" roleData?.data || []"
139
152
placeholder =" Select Role"
140
- :items="roleList"
141
153
item-title =" name"
142
154
item-value =" id"
143
155
/>
144
- </VCol> -->
156
+ </VCol >
145
157
146
158
<!-- 👉 Full name -->
147
159
<VCol cols =" 12" >
@@ -173,17 +185,16 @@ function handleCancel() {
173
185
/>
174
186
</VCol >
175
187
176
- <!-- TODO: Add Organization -->
177
- <!-- <VCol cols="12">
188
+ <VCol cols =" 12" >
178
189
<VSelect
179
- v-model="formData.organization_id "
190
+ v-model =" formData.organizations "
180
191
label =" Select Organization"
181
192
placeholder =" Select Organization"
182
- :items="[{ id: null, name: 'No Organization' }, ...localOrganization ]"
193
+ :items =" organizationData?.data || [ ]"
183
194
item-title =" name"
184
195
item-value =" id"
185
196
/>
186
- </VCol> -->
197
+ </VCol >
187
198
188
199
<!-- 👉 Country -->
189
200
<VCol cols =" 12" >
0 commit comments