@goweekdays/layer-common 1.0.0 → 1.0.2

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.
@@ -0,0 +1,452 @@
1
+ <template>
2
+ <v-row no-gutters>
3
+ <v-col v-if="props.seatManagement !== 'index'" cols="12" class="mb-2">
4
+ <v-row no-gutters>
5
+ <v-btn
6
+ class="text-none"
7
+ rounded="pill"
8
+ variant="tonal"
9
+ :to="{
10
+ name: props.seatManagement,
11
+ params: { organization: props.orgId },
12
+ }"
13
+ size="large"
14
+ >
15
+ Manage seats
16
+ </v-btn>
17
+ </v-row>
18
+ </v-col>
19
+
20
+ <v-col cols="12">
21
+ <v-card width="100%" variant="outlined" border="thin" rounded="lg">
22
+ <v-toolbar density="compact" color="grey-lighten-4">
23
+ <template #prepend>
24
+ <v-btn fab icon density="comfortable" @click="getAll()">
25
+ <v-icon>mdi-refresh</v-icon>
26
+ </v-btn>
27
+ </template>
28
+
29
+ <template #append>
30
+ <v-row no-gutters justify="end" align="center">
31
+ <span class="mr-2 text-caption text-font gray">
32
+ {{ pageRange }}
33
+ </span>
34
+ <local-pagination
35
+ v-model="page"
36
+ :length="pages"
37
+ @update:value="getAll()"
38
+ />
39
+ </v-row>
40
+ </template>
41
+
42
+ <template #extension>
43
+ <v-tabs>
44
+ <v-tab
45
+ v-for="tab in [
46
+ { name: 'Active', status: 'active' },
47
+ { name: 'Suspended', status: 'suspended' },
48
+ ]"
49
+ :key="tab.status"
50
+ :to="{
51
+ name: props.route,
52
+ params: setRouteParams({
53
+ status: tab.status,
54
+ organization: props.orgId,
55
+ }),
56
+ }"
57
+ >
58
+ {{ tab.name }}
59
+ </v-tab>
60
+ </v-tabs>
61
+ </template>
62
+ </v-toolbar>
63
+
64
+ <v-data-table
65
+ :headers="props.headers"
66
+ :items="items"
67
+ item-value="_id"
68
+ items-per-page="20"
69
+ fixed-header
70
+ hide-default-footer
71
+ style="max-height: calc(100vh - (126px))"
72
+ :loading="loading"
73
+ >
74
+ <template #item.nature="{ item }">
75
+ {{ replaceMatch(item.nature, "_", " ") }}
76
+ </template>
77
+ <template #item.action-table="{ item }">
78
+ <v-menu
79
+ v-if="
80
+ (status === 'active' &&
81
+ (canSuspendMembers || canDeleteMembers)) ||
82
+ (status === 'suspended' &&
83
+ (canActivateMembers || canDeleteMembers))
84
+ "
85
+ v-model="item.menuOpen"
86
+ offset-y
87
+ width="150"
88
+ >
89
+ <template v-slot:activator="{ props }">
90
+ <v-icon v-bind="props">mdi-dots-horizontal</v-icon>
91
+ </template>
92
+ <v-list>
93
+ <v-list-item
94
+ v-if="props.assignRole"
95
+ @click="
96
+ setMember({
97
+ dialog: true,
98
+ mode: 'assign-role',
99
+ role: item,
100
+ })
101
+ "
102
+ >
103
+ Assign Role
104
+ </v-list-item>
105
+
106
+ <v-list-item
107
+ v-if="status === 'active' && canSuspendMembers"
108
+ @click="openUpdateDialog(item.user, 'suspended')"
109
+ >
110
+ Suspend
111
+ </v-list-item>
112
+ <v-list-item
113
+ v-if="status === 'suspended' && canActivateMembers"
114
+ @click="openUpdateDialog(item.user, 'active')"
115
+ >
116
+ Activate
117
+ </v-list-item>
118
+ <v-list-item
119
+ v-if="canDeleteMembers"
120
+ @click="openUpdateDialog(item.user, 'deleted')"
121
+ >
122
+ Delete
123
+ </v-list-item>
124
+ </v-list>
125
+ </v-menu>
126
+ </template>
127
+ </v-data-table>
128
+ </v-card>
129
+ </v-col>
130
+ <ConfirmDialog
131
+ v-model="confirmDialog"
132
+ :loading="updateLoading"
133
+ @submit="handleUpdateMemberStatus"
134
+ >
135
+ <template #title>
136
+ <span class="font-weight-medium text-h5">
137
+ {{ updateActionText }} Member</span
138
+ >
139
+ </template>
140
+
141
+ <template #description>
142
+ <p class="text-subtitle-2">
143
+ Are you sure you want to {{ updateActionText }} this Member? This
144
+ action cannot be undone.
145
+ </p>
146
+ </template>
147
+
148
+ <template #footer>
149
+ <v-btn
150
+ variant="text"
151
+ @click="confirmDialog = false"
152
+ :disabled="updateLoading"
153
+ >
154
+ Close
155
+ </v-btn>
156
+ <v-btn
157
+ color="primary"
158
+ variant="flat"
159
+ @click="handleUpdateMemberStatus"
160
+ :loading="updateLoading"
161
+ >
162
+ {{ updateActionText }} Member
163
+ </v-btn>
164
+ </template>
165
+ </ConfirmDialog>
166
+
167
+ <Snackbar v-model="messageSnackbar" :text="message" :color="messageColor" />
168
+
169
+ <v-dialog v-model="assignRoleDialog" max-width="400px">
170
+ <v-card>
171
+ <v-card-title class="text-h5">Assign Role</v-card-title>
172
+ <v-card-text>
173
+ <v-form v-model="memberRoleForm" @submit.prevent="updateMemberRole()">
174
+ <v-row no-gutters>
175
+ <v-col cols="12" class="mb-2">
176
+ <v-row no-gutters>
177
+ <InputLabel class="text-capitalize" title="Name" required />
178
+ <v-col cols="12">
179
+ <v-select
180
+ v-model="selectedRole"
181
+ :items="roles"
182
+ item-value="_id"
183
+ item-title="name"
184
+ density="comfortable"
185
+ :rules="[requiredRule]"
186
+ :error-messages="
187
+ selectedRole === selectedMemberRole
188
+ ? 'Role already assigned'
189
+ : ''
190
+ "
191
+ persistent-hint
192
+ ></v-select>
193
+ </v-col>
194
+
195
+ <v-col cols="12" class="text-error text-center">
196
+ {{ message }}
197
+ </v-col>
198
+ </v-row>
199
+ </v-col>
200
+
201
+ <v-col cols="12">
202
+ <v-row>
203
+ <v-col cols="6">
204
+ <v-btn
205
+ block
206
+ variant="text"
207
+ @click="setMember({ mode: 'assign-role' })"
208
+ >
209
+ Cancel
210
+ </v-btn>
211
+ </v-col>
212
+ <v-col cols="6">
213
+ <v-btn
214
+ block
215
+ variant="flat"
216
+ color="black"
217
+ :disabled="!memberRoleForm"
218
+ type="submit"
219
+ >
220
+ Submit
221
+ </v-btn>
222
+ </v-col>
223
+ </v-row>
224
+ </v-col>
225
+ </v-row>
226
+ </v-form>
227
+ </v-card-text>
228
+ </v-card>
229
+ </v-dialog>
230
+ </v-row>
231
+ </template>
232
+
233
+ <script setup lang="ts">
234
+ const props = defineProps({
235
+ orgId: {
236
+ type: String,
237
+ default: "",
238
+ },
239
+ customerId: {
240
+ type: String,
241
+ default: "",
242
+ },
243
+ siteId: {
244
+ type: String,
245
+ default: "",
246
+ },
247
+ status: {
248
+ type: String,
249
+ default: "active",
250
+ },
251
+ type: {
252
+ type: String,
253
+ default: "organization",
254
+ },
255
+ seatManagement: {
256
+ type: String,
257
+ default: "index",
258
+ },
259
+ inviteMember: {
260
+ type: String,
261
+ default: "index",
262
+ },
263
+ route: {
264
+ type: String,
265
+ default: "index",
266
+ },
267
+ canActivateMembers: {
268
+ type: Boolean,
269
+ default: false,
270
+ },
271
+ canSuspendMembers: {
272
+ type: Boolean,
273
+ default: false,
274
+ },
275
+ canDeleteMembers: {
276
+ type: Boolean,
277
+ default: false,
278
+ },
279
+ assignRole: {
280
+ type: Boolean,
281
+ default: false,
282
+ },
283
+ headers: {
284
+ type: Array as PropType<Array<Record<string, string>>>,
285
+ default: () => [
286
+ {
287
+ title: "Name",
288
+
289
+ value: "name",
290
+ },
291
+ {
292
+ title: "Role",
293
+
294
+ value: "roleName",
295
+ },
296
+ {
297
+ title: "Organization",
298
+
299
+ value: "orgName",
300
+ },
301
+ {
302
+ title: "Action",
303
+ value: "action-table",
304
+ },
305
+ ],
306
+ },
307
+ });
308
+
309
+ const items = ref<Array<Record<string, any>>>([]);
310
+ const page = ref(1);
311
+ const pages = ref(10);
312
+ const pageRange = ref("-- - -- of --");
313
+
314
+ const message = ref("");
315
+ const messageSnackbar = ref(false);
316
+ const messageColor = ref("");
317
+
318
+ const {
319
+ getAll: _getAll,
320
+ updateMemberStatus: _updateMemberStatus,
321
+ updateMemberRole: _updateMemberRole,
322
+ } = useMember();
323
+
324
+ const { headerSearch } = useLocal();
325
+ const { replaceMatch, setRouteParams, requiredRule } = useUtils();
326
+
327
+ const {
328
+ data: getAllReq,
329
+ refresh: getAll,
330
+ status: getAllReqStatus,
331
+ } = useLazyAsyncData("get-all-members-by-status" + props.status, () =>
332
+ _getAll({
333
+ status: props.status,
334
+ org: props.orgId,
335
+ search: headerSearch.value,
336
+ page: page.value,
337
+ type: props.type,
338
+ })
339
+ );
340
+
341
+ const loading = computed(() => getAllReqStatus.value === "pending");
342
+
343
+ watchEffect(() => {
344
+ if (getAllReq.value) {
345
+ items.value = getAllReq.value.items;
346
+ pages.value = getAllReq.value.pages;
347
+ pageRange.value = getAllReq.value.pageRange;
348
+ }
349
+ });
350
+
351
+ watch(headerSearch, () => {
352
+ getAll();
353
+ });
354
+
355
+ const confirmDialog = ref(false);
356
+ const selectedMemberId = ref<string | null>(null);
357
+ const updateLoading = ref(false);
358
+ const updateAction = ref("");
359
+
360
+ const memberRoleForm = ref(false);
361
+ const assignRoleDialog = ref(false);
362
+ const selectedRole = ref<string | null>(null);
363
+ const selectedMemberRole = ref("");
364
+
365
+ function setMember({
366
+ dialog = false,
367
+ mode = "",
368
+ role = {} as Record<string, any>,
369
+ } = {}) {
370
+ if (mode === "assign-role") {
371
+ assignRoleDialog.value = dialog;
372
+ }
373
+
374
+ selectedMemberId.value = role._id;
375
+ selectedRole.value = role.role;
376
+ selectedMemberRole.value = role.role;
377
+ }
378
+
379
+ const roles = ref<Array<Record<string, any>>>([]);
380
+ const { getRoles } = useRole();
381
+ const { data: getAllRoleReq } = useLazyAsyncData("get-roles", () =>
382
+ getRoles({ org: props.orgId, type: props.type, limit: 20 })
383
+ );
384
+
385
+ watchEffect(() => {
386
+ if (getAllRoleReq.value) {
387
+ roles.value = getAllRoleReq.value.items;
388
+ }
389
+ });
390
+
391
+ watchEffect(() => {
392
+ if (selectedRole.value) {
393
+ message.value = "";
394
+ }
395
+ });
396
+
397
+ async function updateMemberRole() {
398
+ try {
399
+ await _updateMemberRole(
400
+ selectedMemberId.value ?? "",
401
+ selectedRole.value ?? "",
402
+ props.type,
403
+ props.orgId
404
+ );
405
+ await setMember({ mode: "assign-role" });
406
+ await getAll();
407
+ } catch (error: any) {
408
+ message.value = error?.response?._data?.message || "Failed to update role";
409
+ }
410
+ }
411
+
412
+ function openUpdateDialog(id: string, action: string) {
413
+ updateAction.value = action;
414
+ selectedMemberId.value = id;
415
+ confirmDialog.value = true;
416
+ }
417
+
418
+ function showMessage(msg: string, color: string) {
419
+ message.value = msg;
420
+ messageColor.value = color;
421
+ messageSnackbar.value = true;
422
+ }
423
+
424
+ async function handleUpdateMemberStatus() {
425
+ if (!selectedMemberId.value) return;
426
+ updateLoading.value = true;
427
+ try {
428
+ const res = await _updateMemberStatus(
429
+ selectedMemberId.value,
430
+ updateAction.value
431
+ );
432
+
433
+ confirmDialog.value = false;
434
+ showMessage(res.message, "success");
435
+ getAll();
436
+ } catch (error: any) {
437
+ const errorMessage = error?.response?._data?.message;
438
+ showMessage(errorMessage, "error");
439
+ } finally {
440
+ updateLoading.value = false;
441
+ selectedMemberId.value = null;
442
+ }
443
+ }
444
+ const updateActionText = computed(() => {
445
+ const map: Record<string, string> = {
446
+ active: "Activate",
447
+ suspended: "Suspend",
448
+ deleted: "Delete",
449
+ };
450
+ return map[updateAction.value] || updateAction.value;
451
+ });
452
+ </script>
@@ -0,0 +1,179 @@
1
+ <template>
2
+ <v-card width="100%">
3
+ <v-toolbar>
4
+ <v-row no-gutters class="fill-height px-6" align="center">
5
+ <span class="font-weight-bold text-h5">
6
+ {{ props.title }}
7
+ </span>
8
+ </v-row>
9
+ </v-toolbar>
10
+ <v-card-text style="max-height: 100vh; overflow-y: auto">
11
+ <v-form v-model="validForm" :disabled="disable">
12
+ <v-row no-gutters>
13
+ <v-col cols="12" class="mt-2">
14
+ <v-row no-gutters>
15
+ <InputLabel class="text-capitalize" title="Name" required />
16
+ <v-col cols="12">
17
+ <v-text-field
18
+ v-model="name"
19
+ density="comfortable"
20
+ :rules="[requiredRule]"
21
+ ></v-text-field>
22
+ </v-col>
23
+ </v-row>
24
+ </v-col>
25
+
26
+ <v-col v-if="props.types.length" cols="12" class="mt-2">
27
+ <v-row no-gutters>
28
+ <InputLabel class="text-capitalize" title="App" required />
29
+ <v-col cols="12">
30
+ <v-select
31
+ v-model="type"
32
+ :items="props.types"
33
+ density="comfortable"
34
+ :rules="[requiredRule]"
35
+ ></v-select>
36
+ </v-col>
37
+ </v-row>
38
+ </v-col>
39
+
40
+ <v-col v-if="type" cols="12">
41
+ <InputListGroupSelection
42
+ v-model="selectedPermissions"
43
+ :items="props.permissions"
44
+ variant="outlined"
45
+ border="thin"
46
+ :error-messages="requireListRule(selectedPermissions)"
47
+ />
48
+ </v-col>
49
+
50
+ <v-col cols="12" class="mt-2">
51
+ <v-checkbox v-model="createMore" density="comfortable" hide-details>
52
+ <template #label>
53
+ <span class="text-subtitle-2 font-weight-bold">
54
+ Create more
55
+ </span>
56
+ </template>
57
+ </v-checkbox>
58
+ </v-col>
59
+
60
+ <v-col cols="12" class="my-2">
61
+ <v-row no-gutters>
62
+ <v-col cols="12" class="text-center">
63
+ <span
64
+ class="text-none text-subtitle-2 font-weight-medium text-error"
65
+ >
66
+ {{ message }}
67
+ </span>
68
+ </v-col>
69
+ </v-row>
70
+ </v-col>
71
+ </v-row>
72
+ </v-form>
73
+ </v-card-text>
74
+
75
+ <v-toolbar>
76
+ <v-row class="px-6">
77
+ <v-col cols="6">
78
+ <v-btn
79
+ block
80
+ variant="text"
81
+ class="text-none"
82
+ size="large"
83
+ @click="cancel"
84
+ >
85
+ Cancel
86
+ </v-btn>
87
+ </v-col>
88
+
89
+ <v-col cols="6">
90
+ <v-btn
91
+ block
92
+ variant="flat"
93
+ color="black"
94
+ class="text-none"
95
+ size="large"
96
+ :disabled="!validForm"
97
+ @click="submit"
98
+ >
99
+ Submit
100
+ </v-btn>
101
+ </v-col>
102
+ </v-row>
103
+ </v-toolbar>
104
+ </v-card>
105
+ </template>
106
+
107
+ <script setup lang="ts">
108
+ const props = defineProps({
109
+ title: {
110
+ type: String,
111
+ default: "Role Permission Form",
112
+ },
113
+ permissions: {
114
+ type: Object,
115
+ default: () => ({}),
116
+ },
117
+ org: {
118
+ type: String,
119
+ default: "",
120
+ },
121
+ types: {
122
+ type: Array as PropType<Array<Record<string, string>>>,
123
+ default: () => [],
124
+ },
125
+ });
126
+
127
+ const emit = defineEmits(["cancel", "success", "success:create-more"]);
128
+
129
+ const validForm = ref(false);
130
+
131
+ const name = ref("");
132
+ const selectedPermissions = ref([]);
133
+ const createMore = ref(false);
134
+ const disable = ref(false);
135
+
136
+ const { requiredRule, requireListRule } = useUtils();
137
+
138
+ const message = ref("");
139
+ const type = defineModel("type", {
140
+ type: String,
141
+ default: "",
142
+ });
143
+
144
+ const { createRole } = useRole();
145
+
146
+ async function submit() {
147
+ disable.value = true;
148
+ try {
149
+ await createRole({
150
+ name: name.value,
151
+ permissions: selectedPermissions.value,
152
+ type: type.value,
153
+ org: props.org,
154
+ });
155
+
156
+ if (createMore.value) {
157
+ name.value = "";
158
+ selectedPermissions.value = [];
159
+ message.value = "";
160
+ emit("success:create-more");
161
+ return;
162
+ }
163
+
164
+ emit("success");
165
+ } catch (error: any) {
166
+ message.value = error.response._data.message;
167
+ } finally {
168
+ disable.value = false;
169
+ }
170
+ }
171
+
172
+ function cancel() {
173
+ name.value = "";
174
+ selectedPermissions.value = [];
175
+ createMore.value = false;
176
+ message.value = "";
177
+ emit("cancel");
178
+ }
179
+ </script>