@7365admin1/layer-common 1.11.52 → 1.11.54

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 1.11.54
4
+
5
+ ### Patch Changes
6
+
7
+ - 4eeaa88: add member site and org query params
8
+
9
+ ## 1.11.53
10
+
11
+ ### Patch Changes
12
+
13
+ - bb3d683: update endpoint for customer site
14
+ - bb3d683: update layer common
15
+
3
16
  ## 1.11.52
4
17
 
5
18
  ### Patch Changes
@@ -195,20 +195,27 @@ const props = defineProps({
195
195
  const { authenticate } = useLocalAuth();
196
196
  authenticate();
197
197
 
198
- const headers = [
199
- {
200
- title: "Date",
201
- value: "createdAt",
202
- },
203
- {
204
- title: "E-mail",
205
- value: "email",
206
- },
207
- {
208
- title: "Action",
209
- value: "action-table",
210
- },
211
- ];
198
+ const headers = computed(() => {
199
+ const baseHeaders = [
200
+ {
201
+ title: "Date",
202
+ value: "createdAt",
203
+ },
204
+ {
205
+ title: "E-mail",
206
+ value: "email",
207
+ },
208
+ ];
209
+
210
+ if (props.status === "pending" && props.cancelInvitation) {
211
+ baseHeaders.push({
212
+ title: "Action",
213
+ value: "action-table",
214
+ });
215
+ }
216
+
217
+ return baseHeaders;
218
+ });
212
219
 
213
220
  const { getVerifications: _getVerifications, cancelUserInvitation } =
214
221
  useVerification();
@@ -239,16 +246,21 @@ const {
239
246
  items: TMiniVerification[];
240
247
  pages: number;
241
248
  pageRange: string;
242
- }>("get-verifications" + props.status, () =>
243
- _getVerifications({
244
- page: page.value,
245
- status: props.status,
246
- search: headerSearch.value,
247
- type: "user-invite,member-invite",
248
- app: props.app,
249
- orgId: props.org,
250
- siteId: props.siteId,
251
- })
249
+ }>(
250
+ `get-verifications-${props.app}-${props.org}-${props.siteId}-${props.status}`,
251
+ () =>
252
+ _getVerifications({
253
+ page: page.value,
254
+ status: props.status,
255
+ search: headerSearch.value,
256
+ type: "user-invite,member-invite",
257
+ app: props.app,
258
+ orgId: props.org,
259
+ siteId: props.siteId,
260
+ }),
261
+ {
262
+ watch: [() => props.status]
263
+ }
252
264
  );
253
265
 
254
266
  const loading = computed(() => getVerificationsStatus.value === "pending");
@@ -261,7 +273,8 @@ watchEffect(() => {
261
273
  }
262
274
  });
263
275
 
264
- watch([headerSearch], () => {
276
+ watch([headerSearch, () => props.status], () => {
277
+ page.value = 1;
265
278
  getVerifications();
266
279
  });
267
280
 
@@ -159,8 +159,8 @@
159
159
  @click="handleUpdateMemberStatus"
160
160
  :loading="updateLoading"
161
161
  >
162
- {{ updateActionText }} Member
163
- </v-btn>
162
+ {{ updateActionText }} Member </v-btn
163
+ >r
164
164
  </template>
165
165
  </ConfirmDialog>
166
166
 
@@ -375,7 +375,7 @@ const {
375
375
  refresh: getAll,
376
376
  status: getAllReqStatus,
377
377
  } = useAsyncData(
378
- () => `get-all-members-${props.status}-${props.orgId}`,
378
+ `get-all-members-${props.type}-${props.orgId}-${props.siteId}-${props.status}`,
379
379
  () =>
380
380
  _getAll({
381
381
  status: props.status,
@@ -383,14 +383,23 @@ const {
383
383
  search: headerSearch.value,
384
384
  page: page.value,
385
385
  type: props.type,
386
+ siteId: props.siteId,
386
387
  }),
387
388
  {
388
- watch: [() => props.status, headerSearch],
389
+ watch: [() => props.status, () => props.orgId, () => props.siteId, headerSearch],
389
390
  }
390
391
  );
391
392
 
392
393
  const loading = computed(() => getAllReqStatus.value === "pending");
393
394
 
395
+ watch(headerSearch, () => {
396
+ page.value = 1;
397
+ });
398
+
399
+ watch([() => props.orgId, () => props.siteId], () => {
400
+ page.value = 1;
401
+ });
402
+
394
403
  watchEffect(() => {
395
404
  if (getAllReq.value) {
396
405
  items.value = getAllReq.value.items;
@@ -425,7 +434,7 @@ function setMember({
425
434
 
426
435
  const roles = ref<Array<Record<string, any>>>([]);
427
436
  const { getRoles } = useRole();
428
- const { data: getAllRoleReq } = useLazyAsyncData("get-roles", () =>
437
+ const { data: getAllRoleReq } = useLazyAsyncData(`get-roles-${props.type}-${props.orgId}`, () =>
429
438
  getRoles({ org: props.orgId, type: props.type, limit: 20 })
430
439
  );
431
440
 
@@ -38,7 +38,7 @@
38
38
  <v-card-text style="max-height: 100vh; overflow-y: auto" class="pa-0">
39
39
  <v-form v-model="validForm" :disabled="disable">
40
40
  <v-col cols="12" class="px-6">
41
- <InputLabel class="text-capitalize" title="Attachment" />
41
+ <InputLabel class="text-capitalize" title="Attachment (Optional)" />
42
42
 
43
43
  <div v-if="onlineForm.attachment" class="d-flex align-center" style="gap:8px">
44
44
  <v-card
@@ -91,7 +91,7 @@
91
91
  <v-col cols="12" class="px-6">
92
92
  <InputLabel class="text-capitalize" title="Name" />
93
93
  <v-text-field
94
- v-model.trim="onlineForm.name"
94
+ v-model.trim="onlineForm.formType"
95
95
  density="comfortable"
96
96
  ></v-text-field>
97
97
  </v-col>
@@ -202,7 +202,7 @@
202
202
  color="black"
203
203
  class="text-none"
204
204
  size="48"
205
- :disabled="!validForm || disable || onlineForm.name == ''"
205
+ :disabled="!validForm || disable || onlineForm.formType == ''"
206
206
  @click="submit"
207
207
  :loading="disable"
208
208
  >
@@ -215,7 +215,7 @@
215
215
  </template>
216
216
  <script setup lang="ts">
217
217
  import useFile from "../composables/useFile";
218
- import useOnlineForm from "../composables/useOnlineForm";
218
+ import useOnlineFormConfiguration from "../composables/useOnlineFormConfiguration";
219
219
  import useOnlineFormTemplates from "../composables/useOnlineFormTemplates";
220
220
 
221
221
  const prop = defineProps({
@@ -254,7 +254,7 @@ function applyTemplate(name: string | null) {
254
254
  if (!name) return;
255
255
  const template = formTemplates[name];
256
256
  if (!template) return;
257
- onlineForm.value.name = name;
257
+ onlineForm.value.formType = name;
258
258
  onlineForm.value.inputs = template.map((f) => ({ ...f }));
259
259
  }
260
260
 
@@ -263,15 +263,15 @@ const siteId = route.params.site as string;
263
263
  const orgId = route.params.org as string;
264
264
 
265
265
  const { addFile, getFileUrl } = useFile();
266
- const { add: _add, updateOnlineFormById: _update, getAllBySiteId: _getAllBySiteId } = useOnlineForm();
266
+ const { create: _add, updateById: _update, getAll: _getAll } = useOnlineFormConfiguration();
267
267
 
268
268
  const { data: existingFormsData } = useLazyAsyncData(
269
- `online-forms-template-filter-${siteId}`,
270
- () => _getAllBySiteId(siteId, { limit: 100 })
269
+ `online-form-configurations-filter-${siteId}-${Date.now()}`,
270
+ () => _getAll({ site: siteId, org: orgId, limit: 100 })
271
271
  );
272
272
 
273
273
  const availableTemplateNames = computed(() => {
274
- const existing = new Set(existingFormsData.value?.items?.map((f: any) => f.name) ?? []);
274
+ const existing = new Set(existingFormsData.value?.items?.map((f: any) => f.formType) ?? []);
275
275
  return templateNames.filter((name) => !existing.has(name));
276
276
  });
277
277
 
@@ -282,7 +282,7 @@ const attachmentFileName = ref("");
282
282
  const fileInputRef = ref<HTMLInputElement | null>(null);
283
283
 
284
284
  const onlineForm = ref<Record<string, any>>({
285
- name: "",
285
+ formType: "",
286
286
  attachment: "",
287
287
  inputs: [
288
288
  {
@@ -305,7 +305,7 @@ const dataTypes = ref([
305
305
 
306
306
  if (prop.mode === "edit") {
307
307
  onlineForm.value.attachment = prop.onlineForm.attachment;
308
- onlineForm.value.name = prop.onlineForm.name;
308
+ onlineForm.value.formType = prop.onlineForm.formType;
309
309
  onlineForm.value.inputs = prop.onlineForm.inputs;
310
310
  }
311
311
 
@@ -360,26 +360,32 @@ async function submit() {
360
360
  disable.value = true;
361
361
  try {
362
362
  if (prop.mode === "add") {
363
- const payload = {
364
- name: onlineForm.value.name,
365
- attachment: onlineForm.value.attachment,
366
- inputs: onlineForm.value.inputs,
363
+ const fields: Record<string, string> = Object.fromEntries(
364
+ onlineForm.value.inputs.map((input: any, i: number) => [String(i), JSON.stringify(input)])
365
+ );
366
+ if (onlineForm.value.attachment) fields["attachment"] = onlineForm.value.attachment;
367
+
368
+ await _add({
369
+ formType: onlineForm.value.formType,
370
+ fields,
367
371
  status: "active",
368
372
  org: orgId,
369
373
  site: siteId,
370
- };
371
-
372
- await _add(payload);
374
+ });
373
375
  }
374
376
 
375
377
  if (prop.mode === "edit") {
376
- const payload = {
377
- name: onlineForm.value.name,
378
- attachment: onlineForm.value.attachment,
379
- inputs: onlineForm.value.inputs,
380
- };
381
-
382
- await _update(prop.onlineForm._id ?? "", payload);
378
+ const fields: Record<string, string> = Object.fromEntries(
379
+ onlineForm.value.inputs.map((input: any, i: number) => [String(i), JSON.stringify(input)])
380
+ );
381
+ if (onlineForm.value.attachment) fields["attachment"] = onlineForm.value.attachment;
382
+
383
+ await _update(prop.onlineForm._id ?? "", {
384
+ _id: prop.onlineForm._id ?? "",
385
+ formType: onlineForm.value.formType,
386
+ fields,
387
+ status: onlineForm.value.status || "active",
388
+ });
383
389
  }
384
390
 
385
391
  emit("success");
@@ -8,7 +8,7 @@
8
8
  <v-card max-height="85vh" class="d-flex flex-column">
9
9
  <v-toolbar color="grey-darken-3" class="flex-grow-0">
10
10
  <v-toolbar-title class="text-subtitle-1 font-weight-bold text-white text-uppercase">
11
- {{ form?.name }}
11
+ {{ form?.formType }}
12
12
  </v-toolbar-title>
13
13
  </v-toolbar>
14
14
 
@@ -92,7 +92,7 @@
92
92
  <v-card-text style="max-height: 100vh; overflow-y: auto" class="pb-0">
93
93
  <v-row no-gutters class="mb-4">
94
94
  <v-col cols="12">
95
- <strong>Name:</strong> {{ selectedOnlineForm?.name ?? "N/A" }}
95
+ <strong>Name:</strong> {{ selectedOnlineForm?.formType ?? "N/A" }}
96
96
  </v-col>
97
97
  <v-col v-if="selectedOnlineForm?.attachment" cols="12">
98
98
  <strong>Document: </strong>
@@ -274,7 +274,7 @@ const props = defineProps({
274
274
  default: () => [
275
275
  {
276
276
  title: "Name",
277
- value: "name",
277
+ value: "formType",
278
278
  },
279
279
  { title: "Date Created", value: "createdAt" },
280
280
  { title: "Status", value: "status" },
@@ -372,8 +372,22 @@ const deleteLoading = ref(false);
372
372
  const confirmDialog = ref(false);
373
373
  const selectedOnlineFormId = ref<string | null>(null);
374
374
 
375
+ function parseFieldsToInputs(fields: Record<string, string>): any[] {
376
+ return Object.keys(fields)
377
+ .filter((key) => key !== "attachment")
378
+ .sort((a, b) => Number(a) - Number(b))
379
+ .map((key) => {
380
+ try { return JSON.parse(fields[key]); } catch { return fields[key]; }
381
+ });
382
+ }
383
+
375
384
  function tableRowClickHandler(_: any, data: any) {
376
- selectedOnlineForm.value = data.item as TOnlineForm;
385
+ const item = data.item;
386
+ selectedOnlineForm.value = {
387
+ ...item,
388
+ inputs: parseFieldsToInputs(item.fields ?? {}),
389
+ attachment: item.fields?.["attachment"] ?? "",
390
+ } as TOnlineForm;
377
391
  previewDialog.value = true;
378
392
  }
379
393
 
@@ -422,10 +436,12 @@ async function handleDeleteOnlineFormConfiguration() {
422
436
  selectedOnlineFormId.value = null;
423
437
  confirmDialog.value = false;
424
438
  previewDialog.value = false;
439
+ showMessage("Online form configuration deleted successfully!", "success");
425
440
  } catch (error: any) {
426
- message.value =
427
- error?.response?._data?.message ||
428
- "Failed to delete online form configuration";
441
+ showMessage(
442
+ error?.response?._data?.message || "Failed to delete online form configuration",
443
+ "error"
444
+ );
429
445
  } finally {
430
446
  deleteLoading.value = false;
431
447
  }
@@ -56,12 +56,44 @@ export default function useCustomerSite() {
56
56
  }
57
57
  )
58
58
  }
59
+ async function getById(id: string) {
60
+ return useNuxtApp().$api<Record<string, any>>(
61
+ `/api/customer-sites/${id}`,
62
+ {
63
+ method: "GET",
64
+ }
65
+ );
66
+ }
67
+ async function updateById(
68
+ id: string,
69
+ payload: Partial<TCustomerSite>,
70
+ ) {
71
+ return useNuxtApp().$api<Record<string, any>>(
72
+ `/api/customer-sites/${id}`,
73
+ {
74
+ method: "PUT",
75
+ body: payload,
76
+ }
77
+ );
78
+ }
79
+
80
+ async function deleteById(id: string) {
81
+ return useNuxtApp().$api<Record<string, any>>(
82
+ `/api/customer-sites/${id}`,
83
+ {
84
+ method: "DELETE",
85
+ }
86
+ );
87
+ }
59
88
 
60
89
  return {
61
90
  add,
62
91
  getAll,
63
92
  addViaInvite,
64
93
  getBySiteAsServiceProvider,
65
- getCustomerSites
94
+ getCustomerSites,
95
+ getById,
96
+ updateById,
97
+ deleteById,
66
98
  };
67
99
  }
@@ -51,10 +51,11 @@ export default function useMember() {
51
51
  org = "",
52
52
  type = "",
53
53
  status = "active",
54
+ siteId = "",
54
55
  } = {}) {
55
56
  return useNuxtApp().$api<Record<string, any>>("/api/members", {
56
57
  method: "GET",
57
- query: { page, limit, search, user, org, type, status },
58
+ query: { page, limit, search, user, org, type, status, siteId },
58
59
  });
59
60
  }
60
61
  function createUserByVerification(
@@ -109,35 +110,24 @@ export default function useMember() {
109
110
  siteId?: string;
110
111
  siteName?: string;
111
112
  }) {
112
- return useNuxtApp().$api<TMember>('/api/members/direct', {
113
- method: 'POST',
113
+ return useNuxtApp().$api<TMember>("/api/members/direct", {
114
+ method: "POST",
114
115
  body: payload,
115
- })
116
+ });
116
117
  }
117
-
118
- function updateMemberSite(
119
- id: string,
120
- siteId: string,
121
- siteName: string,
122
- ) {
123
- return useNuxtApp().$api(
124
- `/api/members/site`,
125
- {
126
- method: "PUT",
127
- body: {
128
- id,
129
- siteId,
130
- siteName,
131
- },
132
- }
133
- )
118
+
119
+ function updateMemberSite(id: string, siteId: string, siteName: string) {
120
+ return useNuxtApp().$api(`/api/members/site`, {
121
+ method: "PUT",
122
+ body: {
123
+ id,
124
+ siteId,
125
+ siteName,
126
+ },
127
+ });
134
128
  }
135
129
 
136
- function getByUserTypeOrg(
137
- user: string,
138
- type: string,
139
- org: string
140
- ) {
130
+ function getByUserTypeOrg(user: string, type: string, org: string) {
141
131
  return useNuxtApp().$api<TMember>(
142
132
  `/api/members/user/${user}/app/${type}/org`,
143
133
  {
@@ -165,6 +155,6 @@ export default function useMember() {
165
155
  createMemberDirect,
166
156
  updateMemberSite,
167
157
  getAllByUserId,
168
- getByUserTypeOrg
158
+ getByUserTypeOrg,
169
159
  };
170
160
  }
@@ -1,3 +1,31 @@
1
+ export type TFormEntryFields = Record<string | number, string | number | boolean | null>;
2
+
3
+ export type TFormEntryCreate = {
4
+ _id?: string;
5
+ formType: string;
6
+ block?: string;
7
+ level?: string;
8
+ unit?: string;
9
+ name?: string;
10
+ phoneNumber?: string;
11
+ fields: TFormEntryFields;
12
+ status?: string;
13
+ org?: string;
14
+ site?: string;
15
+ createdAt?: string;
16
+ updatedAt?: string | null;
17
+ deletedAt?: string | null;
18
+ };
19
+
20
+ export type TFormEntryUpdate = {
21
+ _id?: string;
22
+ formType: string;
23
+ fields: Record<string, string | number | boolean | null>;
24
+ status?: string;
25
+ updatedAt?: string | null;
26
+ deletedAt?: string | null;
27
+ };
28
+
1
29
  export default function useOnlineFormConfiguration() {
2
30
  function getAll({
3
31
  page = 1,
@@ -19,7 +47,14 @@ export default function useOnlineFormConfiguration() {
19
47
  });
20
48
  }
21
49
 
22
- function updateById(id: string, value: any) {
50
+ function create(value: TFormEntryCreate) {
51
+ return useNuxtApp().$api<Record<string, any>>("/api/online-form-configurations", {
52
+ method: "POST",
53
+ body: value,
54
+ });
55
+ }
56
+
57
+ function updateById(id: string, value: TFormEntryUpdate) {
23
58
  return useNuxtApp().$api<Record<string, any>>(`/api/online-form-configurations/id/${id}`, {
24
59
  method: "PUT",
25
60
  body: value,
@@ -32,5 +67,5 @@ export default function useOnlineFormConfiguration() {
32
67
  });
33
68
  }
34
69
 
35
- return { getAll, getById, updateById, deleteById };
70
+ return { getAll, getById, create, updateById, deleteById };
36
71
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.11.52",
5
+ "version": "1.11.54",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {