@7365admin1/layer-common 4.73.1-staging.456 → 4.75.0

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 +21 -4
  2. package/assets/css/primitives.css +0 -43
  3. package/components/AccessCardPreviewDialog.vue +50 -286
  4. package/components/AppSelect.vue +3 -77
  5. package/components/BuildingUnitFormEdit.vue +0 -6
  6. package/components/Dialog/UpdateMoreAction.vue +1 -11
  7. package/components/DocumentForm.vue +112 -407
  8. package/components/DocumentManagement.vue +12 -213
  9. package/components/Facility/BookingSetup.vue +0 -63
  10. package/components/HidAccessLogDashboard.vue +17 -74
  11. package/components/HidIntercomManagement.vue +14 -183
  12. package/components/HidQrCodeConfiguration.vue +195 -17
  13. package/components/HidReaderManagement.vue +0 -398
  14. package/components/HidReaderUserRoster.vue +3 -44
  15. package/components/HidUserEnrollment.vue +155 -845
  16. package/components/InvitationClientForm.vue +1 -19
  17. package/components/MemberMain.vue +3 -6
  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 -33
  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/utils/role.ts +1 -6
  37. package/components/BuildingUnitManagement.vue +0 -298
  38. package/components/HidAccessPermissions.vue +0 -424
  39. package/components/HidProfileQrCode.vue +0 -332
  40. package/composables/useHidReaderSelection.ts +0 -50
  41. package/composables/useSiteCategory.ts +0 -45
  42. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  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
@@ -46,33 +46,9 @@ export default function useHidNavigation() {
46
46
  },
47
47
  },
48
48
  {
49
- // "HID Reader Users" now points at `access-mgmt/administrator`, not at
50
- // `access-mgmt/hid-users`.
51
- //
52
- // Both routes mount a roster of the reader's users, but only this one
53
- // can act on them. `administrator` renders HidUserEnrollment WITHOUT
54
- // `card-management`, and that prop is what gates the Enroll action:
55
- // <template v-if="!props.cardManagement" #actions>
56
- // `hid-users` renders HidReaderUserRoster, which is read-only apart
57
- // from PIN management. So the menu entry with this name used to lead
58
- // to the screen that cannot enrol, while the screen that can was
59
- // reachable only by typing the URL.
60
- //
61
- // `hid-users` is left in place and simply unlisted - the same state
62
- // `administrator` was in - so any existing link to it still resolves.
63
49
  title: "HID Reader Users",
64
50
  route: {
65
- name: "org-site-access-mgmt-administrator",
66
- params: { org, site },
67
- },
68
- },
69
- {
70
- // The signed-in member's own pass, not somebody else's. Every other
71
- // entry in this group acts on a resident or a visitor; this one has
72
- // no subject but the caller.
73
- title: "HID QR Code",
74
- route: {
75
- name: "org-site-access-mgmt-hid-qr-code",
51
+ name: "org-site-access-mgmt-hid-users",
76
52
  params: { org, site },
77
53
  },
78
54
  },
@@ -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,9 +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
18
  };
22
19
 
23
20
  export type TSiteProviderCompany = {
@@ -93,8 +90,6 @@ export default function useServiceProvider() {
93
90
  status = "",
94
91
  /** "engagements": also providers engaged through an accepted invitation. */
95
92
  include = "",
96
- /** A building unit id, or "none": providers on no unit yet. */
97
- unit = "",
98
93
  } = {}) {
99
94
  return useNuxtApp().$api<Record<string, any>>("/api/service-providers", {
100
95
  method: "GET",
@@ -107,7 +102,6 @@ export default function useServiceProvider() {
107
102
  siteId,
108
103
  ...(status ? { status } : {}),
109
104
  ...(include ? { include } : {}),
110
- ...(unit ? { unit } : {}),
111
105
  },
112
106
  });
113
107
  }
@@ -275,17 +269,6 @@ export default function useServiceProvider() {
275
269
  );
276
270
  }
277
271
 
278
- /** Attach a provider to a building unit, or detach it (`unit` ""). */
279
- async function updateUnit(id: string, unit: string) {
280
- return useNuxtApp().$api<Record<string, any>>(
281
- `/api/service-providers/${id}/unit`,
282
- {
283
- method: "PATCH",
284
- body: { unit },
285
- }
286
- );
287
- }
288
-
289
272
  async function getByEmail({
290
273
  email = "",
291
274
  orgId = "",
@@ -310,29 +293,17 @@ export default function useServiceProvider() {
310
293
  * Members > Service Providers: the provider people with access to this
311
294
  * site, and one entry per provider company with its head count. The
312
295
  * site's own organisation only - the server refuses anyone else.
313
- * `unit`: a building unit id, or "none" (people on no unit yet).
314
296
  */
315
- function getSiteMembers(siteId: string, unit = ""): Promise<{
297
+ function getSiteMembers(siteId: string): Promise<{
316
298
  items: TSiteProviderMember[];
317
299
  companies: TSiteProviderCompany[];
318
300
  }> {
319
301
  return useNuxtApp().$api("/api/service-providers/site-members", {
320
302
  method: "GET",
321
- query: { siteId, ...(unit ? { unit } : {}) },
303
+ query: { siteId },
322
304
  });
323
305
  }
324
306
 
325
- /** Attach one of those people to a building unit, or detach them (`unit` ""). */
326
- function updateSiteMemberUnit(id: string, unit: string) {
327
- return useNuxtApp().$api<Record<string, any>>(
328
- `/api/service-providers/site-members/${id}/unit`,
329
- {
330
- method: "PATCH",
331
- body: { unit },
332
- }
333
- );
334
- }
335
-
336
307
  /** The same list as an Excel file, under the same filters. */
337
308
  function exportSiteMembers(
338
309
  siteId: string,
@@ -349,7 +320,6 @@ export default function useServiceProvider() {
349
320
 
350
321
  return {
351
322
  getSiteMembers,
352
- updateSiteMemberUnit,
353
323
  exportSiteMembers,
354
324
  serviceProviders,
355
325
  serviceProvider,
@@ -368,7 +338,6 @@ export default function useServiceProvider() {
368
338
  add,
369
339
  addViaInvite,
370
340
  updateStatus,
371
- updateUnit,
372
341
  getByEmail,
373
342
  };
374
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.73.1-staging.456",
5
+ "version": "4.75.0",
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 = {
package/utils/role.ts CHANGED
@@ -82,14 +82,9 @@ export function memberRoleChip(
82
82
  * re-assign a role for the right site, nobody's access is cut). `null` at 0 so
83
83
  * the banner disappears once every member here has this site's role.
84
84
  */
85
- export function otherSiteBannerText(count: unknown, orgLevel = false): string | null {
85
+ export function otherSiteBannerText(count: unknown): string | null {
86
86
  const n = typeof count === "number" && Number.isFinite(count) ? Math.floor(count) : 0;
87
87
  if (n <= 0) return null;
88
- if (orgLevel) {
89
- return n === 1
90
- ? "1 member holds a role created for one particular site. Fix roles from other sites gives them the right role."
91
- : `${n} members hold a role created for one particular site. Fix roles from other sites gives each one the right role.`;
92
- }
93
88
  return n === 1
94
89
  ? "1 member here has a role from another site. Assign them a role for this site."
95
90
  : `${n} members here have a role from another site. Assign each one a role for this site.`;
@@ -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>