AddNewUserDrawer.vue
5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<script setup>
import { PerfectScrollbar } from 'vue3-perfect-scrollbar'
const props = defineProps({
isDrawerOpen: {
type: Boolean,
required: true,
},
})
const emit = defineEmits([
'update:isDrawerOpen',
'userData',
])
const isFormValid = ref(false)
const refForm = ref()
const fullName = ref('')
const userName = ref('')
const email = ref('')
const company = ref('')
const country = ref()
const contact = ref('')
const role = ref()
const plan = ref()
const status = ref()
// 👉 drawer close
const closeNavigationDrawer = () => {
emit('update:isDrawerOpen', false)
nextTick(() => {
refForm.value?.reset()
refForm.value?.resetValidation()
})
}
const onSubmit = () => {
refForm.value?.validate().then(({ valid }) => {
if (valid) {
emit('userData', {
id: 0,
fullName: fullName.value,
company: company.value,
role: role.value,
username: userName.value,
country: country.value,
contact: contact.value,
email: email.value,
currentPlan: plan.value,
status: status.value,
avatar: '',
})
emit('update:isDrawerOpen', false)
nextTick(() => {
refForm.value?.reset()
refForm.value?.resetValidation()
})
}
})
}
const handleDrawerModelValueUpdate = val => {
emit('update:isDrawerOpen', val)
}
</script>
<template>
<VNavigationDrawer
temporary
:width="400"
location="end"
class="scrollable-content"
:model-value="props.isDrawerOpen"
@update:model-value="handleDrawerModelValueUpdate"
>
<!-- 👉 Title -->
<AppDrawerHeaderSection
title="Add User"
@cancel="closeNavigationDrawer"
/>
<VDivider />
<PerfectScrollbar :options="{ wheelPropagation: false }">
<VCard flat>
<VCardText>
<!-- 👉 Form -->
<VForm
ref="refForm"
v-model="isFormValid"
@submit.prevent="onSubmit"
>
<VRow>
<!-- 👉 Full name -->
<VCol cols="12">
<VTextField
v-model="fullName"
:rules="[requiredValidator]"
label="Full Name"
placeholder="John Doe"
/>
</VCol>
<!-- 👉 Username -->
<VCol cols="12">
<VTextField
v-model="userName"
:rules="[requiredValidator]"
label="Username"
placeholder="Johndoe"
/>
</VCol>
<!-- 👉 Email -->
<VCol cols="12">
<VTextField
v-model="email"
:rules="[requiredValidator, emailValidator]"
label="Email"
placeholder="johndoe@email.com"
/>
</VCol>
<!-- 👉 company -->
<VCol cols="12">
<VTextField
v-model="company"
:rules="[requiredValidator]"
label="Company"
placeholder="Themeselection"
/>
</VCol>
<!-- 👉 Country -->
<VCol cols="12">
<VSelect
v-model="country"
label="Select Country"
placeholder="Select Country"
:rules="[requiredValidator]"
:items="['USA', 'UK', 'India', 'Australia']"
/>
</VCol>
<!-- 👉 Contact -->
<VCol cols="12">
<VTextField
v-model="contact"
type="number"
:rules="[requiredValidator]"
label="Contact"
placeholder="+1-541-754-3010"
/>
</VCol>
<!-- 👉 Role -->
<VCol cols="12">
<VSelect
v-model="role"
label="Select Role"
placeholder="Select Role"
:rules="[requiredValidator]"
:items="['Admin', 'Author', 'Editor', 'Maintainer', 'Subscriber']"
/>
</VCol>
<!-- 👉 Plan -->
<VCol cols="12">
<VSelect
v-model="plan"
label="Select Plan"
placeholder="Select Plan"
:rules="[requiredValidator]"
:items="['Basic', 'Company', 'Enterprise', 'Team']"
/>
</VCol>
<!-- 👉 Status -->
<VCol cols="12">
<VSelect
v-model="status"
label="Select Status"
placeholder="Select Status"
:rules="[requiredValidator]"
:items="[{ title: 'Active', value: 'active' }, { title: 'Inactive', value: 'inactive' }, { title: 'Pending', value: 'pending' }]"
/>
</VCol>
<!-- 👉 Submit and Cancel -->
<VCol cols="12">
<VBtn
type="submit"
class="me-4"
>
Submit
</VBtn>
<VBtn
type="reset"
variant="outlined"
color="error"
@click="closeNavigationDrawer"
>
Cancel
</VBtn>
</VCol>
</VRow>
</VForm>
</VCardText>
</VCard>
</PerfectScrollbar>
</VNavigationDrawer>
</template>