@7365admin1/layer-common 4.35.1-staging.444 → 4.35.1-staging.445

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.
@@ -10,6 +10,7 @@
10
10
  <v-tab value="general">General</v-tab>
11
11
  <v-tab value="residents">Residents/Tenants</v-tab>
12
12
  <v-tab value="vehicles">Vehicles</v-tab>
13
+ <v-tab value="management">Management</v-tab>
13
14
  <v-tab value="others">Others</v-tab>
14
15
  </v-tabs>
15
16
  </v-toolbar>
@@ -170,6 +171,11 @@
170
171
  </TableMain>
171
172
  </template>
172
173
 
174
+ <template v-else-if="tab === 'management'">
175
+ <BuildingUnitManagement :unit-id="buildingUnit._id" :site-id="buildingUnit?.site?._id"
176
+ :can-update="canUpdateUnit" />
177
+ </template>
178
+
173
179
  <template v-else-if="tab === 'others'">
174
180
  <v-row>
175
181
  <!-- <v-col cols="12" md="6" class="mt-2">
@@ -0,0 +1,277 @@
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 providers" }} that are not assigned to a unit
79
+ 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
+ * providers attached to this unit. Each can be on one unit at a time, and
107
+ * only while active - the server detaches them the moment they are suspended,
108
+ * set inactive or deleted, so they simply drop off this list.
109
+ */
110
+ type TSection = "members" | "providers";
111
+ type TRow = { _id: string; name: string; email?: string; roleName?: string; type?: string };
112
+
113
+ const props = defineProps({
114
+ unitId: {
115
+ type: String,
116
+ required: true,
117
+ },
118
+ /** The unit's site. The route's `site` is used when this is empty. */
119
+ siteId: {
120
+ type: String,
121
+ default: "",
122
+ },
123
+ /** The membership type whose members manage the site. */
124
+ managementType: {
125
+ type: String,
126
+ default: "property_management_agency",
127
+ },
128
+ canUpdate: {
129
+ type: Boolean,
130
+ default: false,
131
+ },
132
+ });
133
+
134
+ const route = useRoute();
135
+ const org = computed(() => (route.params.org as string) ?? "");
136
+ const site = computed(() => props.siteId || ((route.params.site as string) ?? ""));
137
+
138
+ const { getAll: getMembers, updateMemberUnit } = useMember();
139
+ const { getAll: getProviders, updateUnit: updateProviderUnit } = useServiceProvider();
140
+ const { debounce } = useUtils();
141
+
142
+ const panels = ref<TSection[]>(["members", "providers"]);
143
+ const message = ref("");
144
+ const removing = ref("");
145
+
146
+ function membersQuery(unit: string, search = "") {
147
+ return getMembers({ org: org.value, siteId: site.value, type: props.managementType, status: "active", unit, search, limit: 50 });
148
+ }
149
+
150
+ function providersQuery(unit: string, search = "") {
151
+ return getProviders({ siteId: site.value, status: "active", unit, search, limit: 50 });
152
+ }
153
+
154
+ const { data: memberRes, pending: membersLoading, refresh: refreshMembers } = useLazyAsyncData(
155
+ `unit-management-members-${props.unitId}`,
156
+ () => membersQuery(props.unitId),
157
+ );
158
+ const { data: providerRes, pending: providersLoading, refresh: refreshProviders } = useLazyAsyncData(
159
+ `unit-management-providers-${props.unitId}`,
160
+ () => providersQuery(props.unitId),
161
+ );
162
+
163
+ function subtitleOf(row: TRow) {
164
+ return [row.roleName || row.type?.replace(/_/g, " "), row.email].filter(Boolean).join(" · ");
165
+ }
166
+
167
+ const sections = computed(() => [
168
+ {
169
+ key: "members" as TSection,
170
+ title: "Management",
171
+ empty: "management",
172
+ items: (memberRes.value?.items ?? []) as TRow[],
173
+ loading: membersLoading.value,
174
+ subtitle: subtitleOf,
175
+ },
176
+ {
177
+ key: "providers" as TSection,
178
+ title: "Service Providers",
179
+ empty: "service providers",
180
+ items: (providerRes.value?.items ?? []) as TRow[],
181
+ loading: providersLoading.value,
182
+ subtitle: subtitleOf,
183
+ },
184
+ ]);
185
+
186
+ function refresh(section: TSection) {
187
+ return section === "members" ? refreshMembers() : refreshProviders();
188
+ }
189
+
190
+ function assign(section: TSection, id: string, unit: string) {
191
+ return section === "members" ? updateMemberUnit(id, unit) : updateProviderUnit(id, unit);
192
+ }
193
+
194
+ function errorOf(error: any, fallback: string) {
195
+ return error?.response?._data?.message || error?.data?.message || fallback;
196
+ }
197
+
198
+ // --- Remove: confirmed first ---
199
+ const removeDialog = ref(false);
200
+ const pendingRemove = ref<{ section: TSection; id: string; name: string } | null>(null);
201
+
202
+ function confirmRemove(section: TSection, row: TRow) {
203
+ message.value = "";
204
+ pendingRemove.value = { section, id: row._id, name: row.name };
205
+ removeDialog.value = true;
206
+ }
207
+
208
+ async function remove() {
209
+ if (!pendingRemove.value) return;
210
+ const { section, id } = pendingRemove.value;
211
+ removing.value = id;
212
+ try {
213
+ await assign(section, id, "");
214
+ await refresh(section);
215
+ } catch (error: any) {
216
+ message.value = errorOf(error, "Failed to remove from unit.");
217
+ } finally {
218
+ removing.value = "";
219
+ removeDialog.value = false;
220
+ pendingRemove.value = null;
221
+ }
222
+ }
223
+
224
+ // --- Add dialog: active rows on no unit yet ---
225
+ const addDialog = ref(false);
226
+ const adding = ref<TSection>("members");
227
+ const selected = ref<string[]>([]);
228
+ const candidates = ref<TRow[]>([]);
229
+ const candidateSearch = ref("");
230
+ const candidatesLoading = ref(false);
231
+ const saving = ref(false);
232
+
233
+ async function loadCandidates() {
234
+ candidatesLoading.value = true;
235
+ try {
236
+ const search = candidateSearch.value?.trim() ?? "";
237
+ const res = adding.value === "members" ? await membersQuery("none", search) : await providersQuery("none", search);
238
+ // Keep what is already picked, so a new search does not drop the chips.
239
+ const picked = candidates.value.filter((c) => selected.value.includes(c._id));
240
+ const found = ((res?.items ?? []) as TRow[]).filter((c) => !selected.value.includes(c._id));
241
+ candidates.value = [...picked, ...found];
242
+ } catch (error: any) {
243
+ message.value = errorOf(error, "Failed to load the list.");
244
+ } finally {
245
+ candidatesLoading.value = false;
246
+ }
247
+ }
248
+
249
+ const debouncedLoad = debounce(loadCandidates, 400);
250
+ watch(candidateSearch, () => {
251
+ if (addDialog.value) debouncedLoad();
252
+ });
253
+
254
+ function openAdd(section: TSection) {
255
+ message.value = "";
256
+ adding.value = section;
257
+ selected.value = [];
258
+ candidates.value = [];
259
+ candidateSearch.value = "";
260
+ addDialog.value = true;
261
+ loadCandidates();
262
+ }
263
+
264
+ async function add() {
265
+ saving.value = true;
266
+ message.value = "";
267
+ const section = adding.value;
268
+ const results = await Promise.allSettled(selected.value.map((id) => assign(section, id, props.unitId)));
269
+ const failed = results.filter((r): r is PromiseRejectedResult => r.status === "rejected");
270
+ if (failed.length) {
271
+ message.value = errorOf(failed[0].reason, `${failed.length} could not be added.`);
272
+ }
273
+ await refresh(section);
274
+ saving.value = false;
275
+ addDialog.value = false;
276
+ }
277
+ </script>
@@ -70,6 +70,8 @@ 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 = "",
73
75
  } = {}) {
74
76
  const query: Record<string, any> = { page, limit, type, status };
75
77
 
@@ -79,6 +81,7 @@ export default function useMember() {
79
81
  if (user) query.user = user;
80
82
  if (org) query.org = org;
81
83
  if (siteId) query.siteId = siteId;
84
+ if (unit) query.unit = unit;
82
85
  return useNuxtApp().$api<Record<string, any>>("/api/members", {
83
86
  method: "GET",
84
87
  query,
@@ -154,6 +157,14 @@ export default function useMember() {
154
157
  });
155
158
  }
156
159
 
160
+ /** Attach a member to a building unit, or detach them (`unit` ""). */
161
+ function updateMemberUnit(id: string, unit: string) {
162
+ return useNuxtApp().$api<Record<string, any>>("/api/members/unit", {
163
+ method: "PUT",
164
+ body: { id, unit },
165
+ });
166
+ }
167
+
157
168
  function getByUserTypeOrg(user: string, type: string, org: string) {
158
169
  return useNuxtApp().$api<TMember>(
159
170
  `/api/members/user/${user}/app/${type}/org`,
@@ -197,6 +208,7 @@ export default function useMember() {
197
208
  return {
198
209
  getSiteAccess,
199
210
  saveSiteAccess,
211
+ updateMemberUnit,
200
212
  members,
201
213
  member,
202
214
  page,
@@ -90,6 +90,8 @@ export default function useServiceProvider() {
90
90
  status = "",
91
91
  /** "engagements": also providers engaged through an accepted invitation. */
92
92
  include = "",
93
+ /** A building unit id, or "none": providers on no unit yet. */
94
+ unit = "",
93
95
  } = {}) {
94
96
  return useNuxtApp().$api<Record<string, any>>("/api/service-providers", {
95
97
  method: "GET",
@@ -102,6 +104,7 @@ export default function useServiceProvider() {
102
104
  siteId,
103
105
  ...(status ? { status } : {}),
104
106
  ...(include ? { include } : {}),
107
+ ...(unit ? { unit } : {}),
105
108
  },
106
109
  });
107
110
  }
@@ -269,6 +272,17 @@ export default function useServiceProvider() {
269
272
  );
270
273
  }
271
274
 
275
+ /** Attach a provider to a building unit, or detach it (`unit` ""). */
276
+ async function updateUnit(id: string, unit: string) {
277
+ return useNuxtApp().$api<Record<string, any>>(
278
+ `/api/service-providers/${id}/unit`,
279
+ {
280
+ method: "PATCH",
281
+ body: { unit },
282
+ }
283
+ );
284
+ }
285
+
272
286
  async function getByEmail({
273
287
  email = "",
274
288
  orgId = "",
@@ -338,6 +352,7 @@ export default function useServiceProvider() {
338
352
  add,
339
353
  addViaInvite,
340
354
  updateStatus,
355
+ updateUnit,
341
356
  getByEmail,
342
357
  };
343
358
  }
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.35.1-staging.444",
5
+ "version": "4.35.1-staging.445",
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.",
package/types/member.d.ts CHANGED
@@ -10,6 +10,10 @@ 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;
13
17
  createdAt?: string;
14
18
  updatedAt?: string;
15
19
  deletedAt?: string;
@@ -7,6 +7,11 @@ 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;
10
15
  };
11
16
 
12
17
  declare type TServiceProviderName = {