@7365admin1/layer-common 1.11.52 → 1.11.53

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,12 @@
1
1
  # @iservice365/layer-common
2
2
 
3
+ ## 1.11.53
4
+
5
+ ### Patch Changes
6
+
7
+ - bb3d683: update endpoint for customer site
8
+ - bb3d683: update layer common
9
+
3
10
  ## 1.11.52
4
11
 
5
12
  ### Patch Changes
@@ -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
  }
@@ -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.53",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {