@7365admin1/layer-common 4.81.1-staging.467 → 4.81.1

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +10 -4
  2. package/assets/css/primitives.css +0 -57
  3. package/components/AccessCardDetailsDialog.vue +4 -57
  4. package/components/AccessCardPreviewDialog.vue +50 -291
  5. package/components/AppSelect.vue +4 -143
  6. package/components/BuildingUnitFormEdit.vue +0 -6
  7. package/components/Dialog/UpdateMoreAction.vue +1 -11
  8. package/components/DocumentForm.vue +112 -407
  9. package/components/DocumentManagement.vue +12 -213
  10. package/components/Facility/BookingSetup.vue +0 -63
  11. package/components/HidAccessLogDashboard.vue +17 -74
  12. package/components/HidIntercomManagement.vue +14 -183
  13. package/components/HidQrCodeConfiguration.vue +195 -17
  14. package/components/HidReaderManagement.vue +0 -398
  15. package/components/HidReaderUserRoster.vue +3 -44
  16. package/components/HidUserEnrollment.vue +248 -1521
  17. package/components/InvitationClientForm.vue +1 -19
  18. package/components/VisitorForm.vue +0 -12
  19. package/components/VisitorManagement.vue +5 -267
  20. package/composables/useDocument.ts +0 -7
  21. package/composables/useFacility.ts +0 -11
  22. package/composables/useHidAmico.ts +0 -165
  23. package/composables/useHidNavigation.ts +1 -25
  24. package/composables/useMember.ts +0 -12
  25. package/composables/usePeople.ts +0 -19
  26. package/composables/useServiceProvider.ts +2 -40
  27. package/package.json +1 -1
  28. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  29. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  30. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  31. package/types/document.d.ts +0 -14
  32. package/types/facility.d.ts +0 -4
  33. package/types/member.d.ts +0 -4
  34. package/types/people.d.ts +1 -28
  35. package/types/service-provider.d.ts +0 -5
  36. package/components/BuildingUnitManagement.vue +0 -298
  37. package/components/HidAccessPermissions.vue +0 -424
  38. package/components/HidProfileQrCode.vue +0 -332
  39. package/composables/useHidReaderSelection.ts +0 -50
  40. package/composables/useSiteCategory.ts +0 -45
  41. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  42. package/utils/hid-enrolment-subject.ts +0 -144
  43. package/utils/hid-permission-assignments.ts +0 -190
  44. package/utils/hid-reader-selection.ts +0 -52
  45. package/utils/occupancy-role.ts +0 -109
  46. package/utils/service-type.ts +0 -30
@@ -70,8 +70,6 @@ export default function useMember() {
70
70
  status = "active",
71
71
  siteId = "",
72
72
  roleState = "",
73
- /** A building unit id, or "none": members on no unit yet. */
74
- unit = "",
75
73
  people = false,
76
74
  } = {}) {
77
75
  const query: Record<string, any> = { page, limit, type, status };
@@ -85,7 +83,6 @@ export default function useMember() {
85
83
  if (user) query.user = user;
86
84
  if (org) query.org = org;
87
85
  if (siteId) query.siteId = siteId;
88
- if (unit) query.unit = unit;
89
86
  return useNuxtApp().$api<Record<string, any>>("/api/members", {
90
87
  method: "GET",
91
88
  query,
@@ -161,14 +158,6 @@ export default function useMember() {
161
158
  });
162
159
  }
163
160
 
164
- /** Attach a member to a building unit, or detach them (`unit` ""). */
165
- function updateMemberUnit(id: string, unit: string) {
166
- return useNuxtApp().$api<Record<string, any>>("/api/members/unit", {
167
- method: "PUT",
168
- body: { id, unit },
169
- });
170
- }
171
-
172
161
  function getByUserTypeOrg(user: string, type: string, org: string) {
173
162
  return useNuxtApp().$api<TMember>(
174
163
  `/api/members/user/${user}/app/${type}/org`,
@@ -237,7 +226,6 @@ export default function useMember() {
237
226
  undoCrossSiteRoleFix,
238
227
  getSiteAccess,
239
228
  saveSiteAccess,
240
- updateMemberUnit,
241
229
  members,
242
230
  member,
243
231
  page,
@@ -115,24 +115,6 @@ export default function () {
115
115
  });
116
116
  }
117
117
 
118
- /**
119
- * The blocks, levels and units at a site that actually have an occupant.
120
- * The other half of the unit picker: this narrows the cascade, then
121
- * `getPeopleByUnit` answers "which person in this unit?".
122
- */
123
- async function getOccupiedStructure(
124
- site: string,
125
- { type = "", status = "active", block = "", level = "" } = {}
126
- ) {
127
- return await useNuxtApp().$api<Record<string, any>>(
128
- `/api/people/site/${site}/occupied-structure`,
129
- {
130
- method: "GET",
131
- query: { type, status, block, level },
132
- }
133
- );
134
- }
135
-
136
118
  async function getPeopleByUnit(
137
119
  _id: string,
138
120
  { status = "active", type = "" } = {}
@@ -166,7 +148,6 @@ export default function () {
166
148
  findPersonByPlateNumberMultipleResult,
167
149
  findPersonByContact,
168
150
  getPeopleByUnit,
169
- getOccupiedStructure,
170
151
  searchCompanyList,
171
152
  findUsersByPlateNumber,
172
153
  reviewResidentPerson,
@@ -15,16 +15,6 @@ export type TSiteProviderMember = {
15
15
  lastLoginAt?: string | null;
16
16
  /** a subcontractor: the provider that brought its company onto the site */
17
17
  invitedVia?: string;
18
- /** The building unit this person is attached to (a unit's Management tab). */
19
- unit?: string | null;
20
- unitName?: string;
21
- /**
22
- * The person's user account. NOT yet returned by the endpoint — the
23
- * repository projects it but the service layer drops it. Anything acting on
24
- * the PERSON (assigning an access card writes it onto the card as `userId`)
25
- * needs this rather than `_id`, which identifies the membership.
26
- */
27
- user?: string | null;
28
18
  };
29
19
 
30
20
  export type TSiteProviderCompany = {
@@ -100,8 +90,6 @@ export default function useServiceProvider() {
100
90
  status = "",
101
91
  /** "engagements": also providers engaged through an accepted invitation. */
102
92
  include = "",
103
- /** A building unit id, or "none": providers on no unit yet. */
104
- unit = "",
105
93
  } = {}) {
106
94
  return useNuxtApp().$api<Record<string, any>>("/api/service-providers", {
107
95
  method: "GET",
@@ -114,7 +102,6 @@ export default function useServiceProvider() {
114
102
  siteId,
115
103
  ...(status ? { status } : {}),
116
104
  ...(include ? { include } : {}),
117
- ...(unit ? { unit } : {}),
118
105
  },
119
106
  });
120
107
  }
@@ -282,17 +269,6 @@ export default function useServiceProvider() {
282
269
  );
283
270
  }
284
271
 
285
- /** Attach a provider to a building unit, or detach it (`unit` ""). */
286
- async function updateUnit(id: string, unit: string) {
287
- return useNuxtApp().$api<Record<string, any>>(
288
- `/api/service-providers/${id}/unit`,
289
- {
290
- method: "PATCH",
291
- body: { unit },
292
- }
293
- );
294
- }
295
-
296
272
  async function getByEmail({
297
273
  email = "",
298
274
  orgId = "",
@@ -317,29 +293,17 @@ export default function useServiceProvider() {
317
293
  * Members > Service Providers: the provider people with access to this
318
294
  * site, and one entry per provider company with its head count. The
319
295
  * site's own organisation only - the server refuses anyone else.
320
- * `unit`: a building unit id, or "none" (people on no unit yet).
321
296
  */
322
- function getSiteMembers(siteId: string, unit = ""): Promise<{
297
+ function getSiteMembers(siteId: string): Promise<{
323
298
  items: TSiteProviderMember[];
324
299
  companies: TSiteProviderCompany[];
325
300
  }> {
326
301
  return useNuxtApp().$api("/api/service-providers/site-members", {
327
302
  method: "GET",
328
- query: { siteId, ...(unit ? { unit } : {}) },
303
+ query: { siteId },
329
304
  });
330
305
  }
331
306
 
332
- /** Attach one of those people to a building unit, or detach them (`unit` ""). */
333
- function updateSiteMemberUnit(id: string, unit: string) {
334
- return useNuxtApp().$api<Record<string, any>>(
335
- `/api/service-providers/site-members/${id}/unit`,
336
- {
337
- method: "PATCH",
338
- body: { unit },
339
- }
340
- );
341
- }
342
-
343
307
  /** The same list as an Excel file, under the same filters. */
344
308
  function exportSiteMembers(
345
309
  siteId: string,
@@ -356,7 +320,6 @@ export default function useServiceProvider() {
356
320
 
357
321
  return {
358
322
  getSiteMembers,
359
- updateSiteMemberUnit,
360
323
  exportSiteMembers,
361
324
  serviceProviders,
362
325
  serviceProvider,
@@ -375,7 +338,6 @@ export default function useServiceProvider() {
375
338
  add,
376
339
  addViaInvite,
377
340
  updateStatus,
378
- updateUnit,
379
341
  getByEmail,
380
342
  };
381
343
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.81.1-staging.467",
5
+ "version": "4.81.1",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing HID users."
7
7
  >
8
- <HidUserEnrollment :site="siteId" :org="orgId" />
8
+ <HidUserEnrollment :site="siteId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing physical HID cards."
7
7
  >
8
- <HidUserEnrollment :site="siteId" :org="orgId" card-management />
8
+ <HidUserEnrollment :site="siteId" card-management />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -5,7 +5,7 @@
5
5
  :org="orgId"
6
6
  message="Enable HID as a service for this site before managing HID readers."
7
7
  >
8
- <HidReaderManagement :site="siteId" :org="orgId" />
8
+ <HidReaderManagement :site="siteId" />
9
9
  </HidEnabledGate>
10
10
  </v-container>
11
11
  </template>
@@ -3,18 +3,4 @@ declare type TDocument = {
3
3
  name: string;
4
4
  attachment: string;
5
5
  type: string;
6
- /**
7
- * Set at upload or renewal, absent when the document never expires.
8
- *
9
- * An ISO instant on the way out of the API and a `YYYY-MM-DD` string on the
10
- * way back in, which is what `InputDatePicker` binds to - hence the loose
11
- * type rather than `string`.
12
- */
13
- expiryDate?: string | Date | null;
14
- remarks?: string;
15
- size?: number;
16
- parentId?: string | null;
17
- createdAt?: string | Date;
18
- updatedAt?: string | Date;
19
- status?: string;
20
6
  };
@@ -73,10 +73,6 @@ declare type TFacility = {
73
73
  hourInterval?: number;
74
74
  isBookingFeeEnabled: boolean;
75
75
  isGuestEnabled: boolean;
76
- /** Residents may complete this facility's checklist themselves. */
77
- isResidentChecklistEnabled?: boolean;
78
- /** Security may complete it. Mutually exclusive with the above. */
79
- isSecurityChecklistEnabled?: boolean;
80
76
  bookingAmount: number | null;
81
77
  peakBookingFeeAmount?: number | null;
82
78
  bookingFeeGuestAmount?: number | null;
package/types/member.d.ts CHANGED
@@ -10,10 +10,6 @@ declare type TMember = {
10
10
  customerOrgId?: string;
11
11
  customerSiteId?: string;
12
12
  status?: string;
13
- email?: string;
14
- /** The building unit this member manages (a unit's Management tab). */
15
- unit?: string | null;
16
- unitName?: string;
17
13
  createdAt?: string;
18
14
  updatedAt?: string;
19
15
  deletedAt?: string;
package/types/people.d.ts CHANGED
@@ -22,38 +22,11 @@ declare type TPeople = {
22
22
  email?: string;
23
23
  files?: { name: string, id: string }[];
24
24
  isOwner?: boolean;
25
- /**
26
- * Owner / occupant / person-in-charge, as the BUSINESS people form asks it.
27
- * Absent on everyone else - `isOwner` is still the flag that decides unit
28
- * ownership, and the server derives it from this when it is sent. See
29
- * `OccupancyRoles` in core's `person.model.ts`.
30
- */
31
- occupancyRole?: TOccupancyRole;
32
- // Link to this person's `users` row. Empty for the person types that carry
33
- // no login, and empty for a resident whose account was never written.
34
- user?: string;
35
- };
36
-
37
- declare type TOccupancyRole = "owner" | "occupant" | "person-in-charge";
38
-
39
- /** One standing and everything the product says about it. See `utils/occupancy-role.ts`. */
40
- declare type TOccupancyRoleOption = {
41
- value: TOccupancyRole;
42
- /** The label a stored role is printed with. */
43
- title: string;
44
- /** The row menu's wording. */
45
- action: string;
46
- /** The confirmation's heading and its sentence. */
47
- prompt: string;
48
- description: string;
49
25
  };
50
26
 
51
27
  declare type TPlateNumber = { plateNumber: string, recNo?: string, _id?: string, status: TVehicleStatus, type: TVehicleType, anprCameras?: TVehicleAnprCamera[] };
52
28
 
53
29
 
54
- // `""` is the FORM's "nothing picked yet" - it is stripped from the payload
55
- // before it is sent, because absence is what the server reads as "never
56
- // asked". See `PeopleFormMgmt.vue`.
57
- declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string; user?: string; occupancyRole?: TOccupancyRole | "" }
30
+ declare type TPeoplePayload = Pick<TGuest, "name" | "block" | "level" | "unit" | "unitName" | "contact" | "plateNumber" | "nric" | "contact" | "remarks" | "org" | "site" | "start" | "end" | "type" | "isOwner"> & { status?: string }
58
31
 
59
32
  declare type TPeopleType = "guest" | "resident" | "tenant"
@@ -7,11 +7,6 @@ declare type TServiceProvider = {
7
7
  serviceProviderOrgId: string;
8
8
  type: string;
9
9
  nature: string;
10
- status?: string;
11
- email?: string;
12
- /** The building unit this provider serves (a unit's Management tab). */
13
- unit?: string | null;
14
- unitName?: string;
15
10
  };
16
11
 
17
12
  declare type TServiceProviderName = {
@@ -1,298 +0,0 @@
1
- <template>
2
- <v-card width="100%">
3
- <v-expansion-panels v-model="panels" variant="accordion" multiple>
4
- <v-expansion-panel v-for="section in sections" :key="section.key" :value="section.key">
5
- <v-expansion-panel-title class="bg-primary">
6
- <span>{{ section.title }} ({{ section.items.length }})</span>
7
- <v-spacer />
8
- <!-- @click.stop: the button sits in the panel header, so a click must
9
- not also open or close the panel. -->
10
- <v-btn v-if="canUpdate" size="small" variant="tonal" class="text-none mr-4" prepend-icon="mdi-plus"
11
- @click.stop="openAdd(section.key)">
12
- Add
13
- </v-btn>
14
- </v-expansion-panel-title>
15
-
16
- <v-expansion-panel-text>
17
- <v-progress-linear v-if="section.loading" indeterminate color="primary" />
18
- <v-list v-if="section.items.length" density="compact" class="bg-transparent">
19
- <v-list-item v-for="item in section.items" :key="item._id" :title="item.name"
20
- :subtitle="section.subtitle(item)">
21
- <template v-if="canUpdate" #append>
22
- <v-btn icon="mdi-close" size="small" variant="text" :loading="removing === item._id"
23
- :aria-label="`Remove ${item.name} from this unit`" @click="confirmRemove(section.key, item)" />
24
- </template>
25
- </v-list-item>
26
- </v-list>
27
- <p v-else-if="!section.loading" class="font-weight-semibold text-caption ml-2 mt-5">
28
- **No {{ section.empty }} to display**
29
- </p>
30
- </v-expansion-panel-text>
31
- </v-expansion-panel>
32
- </v-expansion-panels>
33
-
34
- <p v-if="message" class="text-center text-subtitle-2 font-weight-medium text-error mt-4">
35
- {{ message }}
36
- </p>
37
-
38
- <v-dialog v-model="removeDialog" width="450" persistent>
39
- <v-card width="100%">
40
- <v-toolbar density="compact" class="pl-4">
41
- <span class="font-weight-medium text-h5">
42
- Remove {{ pendingRemove?.section === "members" ? "Management" : "Service Provider" }}
43
- </span>
44
- </v-toolbar>
45
-
46
- <v-card-text>
47
- <p class="text-subtitle-2 text-center">
48
- Are you sure you want to remove <strong>{{ pendingRemove?.name }}</strong> from this unit?
49
- </p>
50
- </v-card-text>
51
-
52
- <v-toolbar density="compact">
53
- <v-row no-gutters>
54
- <v-col cols="6">
55
- <v-btn tile block size="48" variant="text" class="text-none" :disabled="!!removing"
56
- @click="removeDialog = false">
57
- Cancel
58
- </v-btn>
59
- </v-col>
60
- <v-col cols="6">
61
- <v-btn tile block size="48" color="primary-button" variant="flat" class="text-none"
62
- :loading="!!removing" @click="remove">
63
- Remove
64
- </v-btn>
65
- </v-col>
66
- </v-row>
67
- </v-toolbar>
68
- </v-card>
69
- </v-dialog>
70
-
71
- <v-dialog v-model="addDialog" width="520" persistent>
72
- <v-card>
73
- <v-toolbar density="compact" class="pl-4">
74
- <span class="font-weight-medium text-h6">Add {{ adding === "members" ? "Management" : "Service Providers" }}</span>
75
- </v-toolbar>
76
- <v-card-text>
77
- <p class="text-caption mb-3">
78
- Only active {{ adding === "members" ? "members" : "service provider people" }} that are not assigned to a
79
- unit yet are listed.
80
- </p>
81
- <v-autocomplete v-model="selected" v-model:search="candidateSearch" :items="candidates"
82
- :loading="candidatesLoading" item-title="name" item-value="_id" multiple chips closable-chips
83
- no-filter density="comfortable" placeholder="Search by name"
84
- :no-data-text="candidatesLoading ? 'Loading...' : 'No one available'">
85
- <template #item="{ props: itemProps, item }">
86
- <v-list-item v-bind="itemProps" :subtitle="subtitleOf(item.raw)" />
87
- </template>
88
- </v-autocomplete>
89
- </v-card-text>
90
- <v-card-actions>
91
- <v-spacer />
92
- <v-btn class="text-none" :disabled="saving" @click="addDialog = false">Cancel</v-btn>
93
- <v-btn class="text-none" color="primary" variant="flat" :loading="saving" :disabled="!selected.length"
94
- @click="add">
95
- Add
96
- </v-btn>
97
- </v-card-actions>
98
- </v-card>
99
- </v-dialog>
100
- </v-card>
101
- </template>
102
-
103
- <script setup lang="ts">
104
- /**
105
- * A building unit's Management tab: the management members and the service
106
- * provider people (Members > Service Providers, not the provider companies)
107
- * attached to this unit. Each can be on one unit at a time, and only while
108
- * active - the server detaches them the moment they are suspended or deleted,
109
- * so they simply drop off this list.
110
- */
111
- type TSection = "members" | "providers";
112
- type TRow = {
113
- _id: string;
114
- name: string;
115
- email?: string;
116
- roleName?: string;
117
- type?: string;
118
- company?: string;
119
- role?: string;
120
- status?: string;
121
- };
122
-
123
- const props = defineProps({
124
- unitId: {
125
- type: String,
126
- required: true,
127
- },
128
- /** The unit's site. The route's `site` is used when this is empty. */
129
- siteId: {
130
- type: String,
131
- default: "",
132
- },
133
- /** The membership type whose members manage the site. */
134
- managementType: {
135
- type: String,
136
- default: "property_management_agency",
137
- },
138
- canUpdate: {
139
- type: Boolean,
140
- default: false,
141
- },
142
- });
143
-
144
- const route = useRoute();
145
- const org = computed(() => (route.params.org as string) ?? "");
146
- const site = computed(() => props.siteId || ((route.params.site as string) ?? ""));
147
-
148
- const { getAll: getMembers, updateMemberUnit } = useMember();
149
- const { getSiteMembers: getProviderPeople, updateSiteMemberUnit: updateProviderUnit } = useServiceProvider();
150
- const { debounce } = useUtils();
151
-
152
- const panels = ref<TSection[]>(["members", "providers"]);
153
- const message = ref("");
154
- const removing = ref("");
155
-
156
- function membersQuery(unit: string, search = "") {
157
- return getMembers({ org: org.value, siteId: site.value, type: props.managementType, status: "active", unit, search, limit: 50 });
158
- }
159
-
160
- /**
161
- * The site's provider people on `unit`, active only. The endpoint returns the
162
- * whole list (no paging or search), so `search` is matched here.
163
- */
164
- async function providersQuery(unit: string, search = "") {
165
- const res = await getProviderPeople(site.value, unit);
166
- const q = search.toLowerCase();
167
- const items = (res?.items ?? []).filter(
168
- (p) => p.status === "active" && (!q || [p.name, p.email, p.company].some((v) => v?.toLowerCase().includes(q))),
169
- );
170
- return { items };
171
- }
172
-
173
- const { data: memberRes, pending: membersLoading, refresh: refreshMembers } = useLazyAsyncData(
174
- `unit-management-members-${props.unitId}`,
175
- () => membersQuery(props.unitId),
176
- );
177
- const { data: providerRes, pending: providersLoading, refresh: refreshProviders } = useLazyAsyncData(
178
- `unit-management-providers-${props.unitId}`,
179
- () => providersQuery(props.unitId),
180
- );
181
-
182
- function subtitleOf(row: TRow) {
183
- return [row.company, row.roleName || row.role || row.type?.replace(/_/g, " "), row.email]
184
- .filter(Boolean)
185
- .join(" · ");
186
- }
187
-
188
- const sections = computed(() => [
189
- {
190
- key: "members" as TSection,
191
- title: "Management",
192
- empty: "management",
193
- items: (memberRes.value?.items ?? []) as TRow[],
194
- loading: membersLoading.value,
195
- subtitle: subtitleOf,
196
- },
197
- {
198
- key: "providers" as TSection,
199
- title: "Service Providers",
200
- empty: "service providers",
201
- items: (providerRes.value?.items ?? []) as TRow[],
202
- loading: providersLoading.value,
203
- subtitle: subtitleOf,
204
- },
205
- ]);
206
-
207
- function refresh(section: TSection) {
208
- return section === "members" ? refreshMembers() : refreshProviders();
209
- }
210
-
211
- function assign(section: TSection, id: string, unit: string) {
212
- return section === "members" ? updateMemberUnit(id, unit) : updateProviderUnit(id, unit);
213
- }
214
-
215
- function errorOf(error: any, fallback: string) {
216
- return error?.response?._data?.message || error?.data?.message || fallback;
217
- }
218
-
219
- // --- Remove: confirmed first ---
220
- const removeDialog = ref(false);
221
- const pendingRemove = ref<{ section: TSection; id: string; name: string } | null>(null);
222
-
223
- function confirmRemove(section: TSection, row: TRow) {
224
- message.value = "";
225
- pendingRemove.value = { section, id: row._id, name: row.name };
226
- removeDialog.value = true;
227
- }
228
-
229
- async function remove() {
230
- if (!pendingRemove.value) return;
231
- const { section, id } = pendingRemove.value;
232
- removing.value = id;
233
- try {
234
- await assign(section, id, "");
235
- await refresh(section);
236
- } catch (error: any) {
237
- message.value = errorOf(error, "Failed to remove from unit.");
238
- } finally {
239
- removing.value = "";
240
- removeDialog.value = false;
241
- pendingRemove.value = null;
242
- }
243
- }
244
-
245
- // --- Add dialog: active rows on no unit yet ---
246
- const addDialog = ref(false);
247
- const adding = ref<TSection>("members");
248
- const selected = ref<string[]>([]);
249
- const candidates = ref<TRow[]>([]);
250
- const candidateSearch = ref("");
251
- const candidatesLoading = ref(false);
252
- const saving = ref(false);
253
-
254
- async function loadCandidates() {
255
- candidatesLoading.value = true;
256
- try {
257
- const search = candidateSearch.value?.trim() ?? "";
258
- const res = adding.value === "members" ? await membersQuery("none", search) : await providersQuery("none", search);
259
- // Keep what is already picked, so a new search does not drop the chips.
260
- const picked = candidates.value.filter((c) => selected.value.includes(c._id));
261
- const found = ((res?.items ?? []) as TRow[]).filter((c) => !selected.value.includes(c._id));
262
- candidates.value = [...picked, ...found];
263
- } catch (error: any) {
264
- message.value = errorOf(error, "Failed to load the list.");
265
- } finally {
266
- candidatesLoading.value = false;
267
- }
268
- }
269
-
270
- const debouncedLoad = debounce(loadCandidates, 400);
271
- watch(candidateSearch, () => {
272
- if (addDialog.value) debouncedLoad();
273
- });
274
-
275
- function openAdd(section: TSection) {
276
- message.value = "";
277
- adding.value = section;
278
- selected.value = [];
279
- candidates.value = [];
280
- candidateSearch.value = "";
281
- addDialog.value = true;
282
- loadCandidates();
283
- }
284
-
285
- async function add() {
286
- saving.value = true;
287
- message.value = "";
288
- const section = adding.value;
289
- const results = await Promise.allSettled(selected.value.map((id) => assign(section, id, props.unitId)));
290
- const failed = results.filter((r): r is PromiseRejectedResult => r.status === "rejected");
291
- if (failed.length) {
292
- message.value = errorOf(failed[0].reason, `${failed.length} could not be added.`);
293
- }
294
- await refresh(section);
295
- saving.value = false;
296
- addDialog.value = false;
297
- }
298
- </script>