@7365admin1/layer-common 4.11.1-staging.314 → 4.11.1-staging.316

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.
@@ -99,10 +99,18 @@
99
99
  <template v-if="passType === 'NFC'">
100
100
  <div class="mt-3">
101
101
  <InputLabel title="Select Cards" />
102
- <v-select
102
+ <!-- Was a `v-select` over the first 100 cards, which only lets the
103
+ operator scroll. Typing now goes to the endpoint as `search`
104
+ (debounced, page 1), and reaching the end of the list fetches
105
+ the next page. Vuetify's own client-side match on `cardNo` is
106
+ left on as well: API-core does not read `search` yet, so until
107
+ it does that is what makes typing narrow the list. -->
108
+ <v-autocomplete
103
109
  v-model="selectedCards"
110
+ v-model:search="cardSearch"
104
111
  :items="filteredCardItems"
105
112
  :loading="cardsLoading"
113
+ :hide-no-data="false"
106
114
  item-title="cardNo"
107
115
  item-value="_id"
108
116
  density="comfortable"
@@ -110,10 +118,30 @@
110
118
  chips
111
119
  closable-chips
112
120
  hide-details
113
- placeholder="Select cards..."
121
+ placeholder="Search or select cards..."
114
122
  return-object
123
+ @update:model-value="cardSearch = ''"
115
124
  >
116
- </v-select>
125
+ <template #append-item>
126
+ <!-- Sentinel for infinite scroll. Keyed on the page so it
127
+ re-mounts after each append: an IntersectionObserver only
128
+ reports changes, so a sentinel that stays in view after a
129
+ short page would otherwise never fire again. -->
130
+ <div
131
+ v-if="cardHasMore"
132
+ :key="cardPage"
133
+ v-intersect="onCardListEndReached"
134
+ class="d-flex justify-center py-2"
135
+ >
136
+ <v-progress-circular
137
+ v-if="cardsLoadingMore"
138
+ indeterminate
139
+ size="20"
140
+ width="2"
141
+ />
142
+ </div>
143
+ </template>
144
+ </v-autocomplete>
117
145
  </div>
118
146
 
119
147
  <div class="mt-3">
@@ -322,6 +350,7 @@ const props = defineProps({
322
350
  const emit = defineEmits(["update:modelValue", "update:quantity", "update:cards", "update:availableQrCount"]);
323
351
 
324
352
  const { getAvailableContractorCards, generateQrVms } = useAccessManagement();
353
+ const { debounce } = useUtils();
325
354
 
326
355
  const nfcEnabled = computed(() => props.settings?.data?.settings?.nfcPass ?? false);
327
356
  const hidQrCodeEnabled = computed(() => {
@@ -367,21 +396,53 @@ const filteredCardItems = computed(() =>
367
396
  : cardItems.value
368
397
  );
369
398
  const cardsLoading = ref(false);
399
+ const cardsLoadingMore = ref(false);
400
+ // Typed text in the card picker. Reset after each pick so the next search
401
+ // starts from the full list instead of staying narrowed to the last term.
402
+ const cardSearch = ref("");
403
+ const CARD_PAGE_SIZE = 100;
404
+ const cardPage = ref(1);
405
+ const cardHasMore = ref(false);
406
+ // Bumped on every request. A response whose number is no longer current is
407
+ // dropped, so a slow page-1 search cannot overwrite a newer one and a
408
+ // load-more cannot append onto a list that has since been replaced.
409
+ let cardRequestSeq = 0;
370
410
  const generating = ref(false);
371
411
  const availableCount = ref<number | null>(null);
372
412
 
373
- async function fetchCards(type: "NFC" | "QRCODE" = "NFC") {
413
+ // The picker is NFC-only (see the template's `v-if`), so only NFC fetches
414
+ // carry the search term and only NFC reacts to typing. The QR path keeps
415
+ // its page-1, no-search fetch and its top-up generation untouched.
416
+ const cardFetchType = computed<"NFC" | "QRCODE" | null>(() =>
417
+ passType.value === "NFC" ? "NFC" : passType.value === "QR" ? "QRCODE" : null,
418
+ );
419
+
420
+ async function fetchCards(
421
+ type: "NFC" | "QRCODE" = "NFC",
422
+ opts: { page?: number; append?: boolean } = {},
423
+ ) {
374
424
  if (!props.siteId || !props.unitId) return;
375
- cardsLoading.value = true;
425
+ const page = opts.page ?? 1;
426
+ const append = opts.append === true;
427
+ const seq = ++cardRequestSeq;
428
+ const query = {
429
+ type,
430
+ siteId: props.siteId,
431
+ unitId: props.unitId,
432
+ page,
433
+ limit: CARD_PAGE_SIZE,
434
+ // Vuetify writes null into the search model when it clears the field.
435
+ search: type === "NFC" ? cardSearch.value ?? "" : undefined,
436
+ };
437
+
438
+ if (append) cardsLoadingMore.value = true;
439
+ else cardsLoading.value = true;
376
440
  if (type === "QRCODE") emit("update:availableQrCount", null);
377
441
  try {
378
- const res = await getAvailableContractorCards({
379
- type,
380
- siteId: props.siteId,
381
- unitId: props.unitId,
382
- });
383
- cardItems.value = res?.data?.[0]?.items ?? [];
384
- availableCount.value = (res?.data?.[2] as any)?.count ?? cardItems.value.length;
442
+ const res = await getAvailableContractorCards(query);
443
+ if (seq !== cardRequestSeq) return;
444
+ let items: any[] = res?.data?.[0]?.items ?? [];
445
+ availableCount.value = (res?.data?.[2] as any)?.count ?? items.length;
385
446
 
386
447
  if (type === "QRCODE" && props.settings?.data?._id && availableCount.value !== null && availableCount.value > 0 && availableCount.value < 50) {
387
448
  cardsLoading.value = false;
@@ -392,30 +453,64 @@ async function fetchCards(type: "NFC" | "QRCODE" = "NFC") {
392
453
  quantity: 50,
393
454
  });
394
455
  // Re-fetch to get the updated count after generation
395
- const refreshed = await getAvailableContractorCards({
396
- type,
397
- siteId: props.siteId,
398
- unitId: props.unitId,
399
- });
400
- cardItems.value = refreshed?.data?.[0]?.items ?? [];
401
- availableCount.value = (refreshed?.data?.[2] as any)?.count ?? cardItems.value.length;
456
+ const refreshed = await getAvailableContractorCards(query);
457
+ if (seq !== cardRequestSeq) return;
458
+ items = refreshed?.data?.[0]?.items ?? [];
459
+ availableCount.value = (refreshed?.data?.[2] as any)?.count ?? items.length;
402
460
  generating.value = false;
403
461
  }
404
462
 
463
+ cardItems.value = append ? [...cardItems.value, ...items] : items;
464
+ cardPage.value = page;
465
+ // A short page is the last one. An exact multiple of the page size costs
466
+ // one extra, empty fetch, which then turns this off.
467
+ cardHasMore.value = items.length === CARD_PAGE_SIZE;
468
+
405
469
  if (type === "QRCODE") emit("update:availableQrCount", availableCount.value);
406
470
  } catch (err: any) {
471
+ if (seq !== cardRequestSeq) return;
407
472
  const msg = err?.data?.message ?? err?.message ?? String(err);
408
473
  showSnackbar(`Entry pass service error: ${msg}`);
409
- availableCount.value = null;
410
- cardItems.value = [];
411
474
  generating.value = false;
412
- if (type === "QRCODE") emit("update:availableQrCount", null);
475
+ // A failed load-more keeps what is already listed; a failed first page
476
+ // clears the list as before.
477
+ if (!append) {
478
+ availableCount.value = null;
479
+ cardItems.value = [];
480
+ cardHasMore.value = false;
481
+ if (type === "QRCODE") emit("update:availableQrCount", null);
482
+ }
413
483
  } finally {
414
- cardsLoading.value = false;
415
- generating.value = false;
484
+ // Only the request that is still current may clear the flags; a stale
485
+ // one finishing late must not switch off a newer request's spinner.
486
+ if (seq === cardRequestSeq) {
487
+ cardsLoading.value = false;
488
+ cardsLoadingMore.value = false;
489
+ generating.value = false;
490
+ }
416
491
  }
417
492
  }
418
493
 
494
+ function onCardListEndReached(isIntersecting: boolean) {
495
+ if (!isIntersecting || !cardHasMore.value) return;
496
+ if (cardsLoading.value || cardsLoadingMore.value) return;
497
+ const type = cardFetchType.value;
498
+ if (!type) return;
499
+ fetchCards(type, { page: cardPage.value + 1, append: true });
500
+ }
501
+
502
+ const searchCards = debounce(() => {
503
+ if (cardFetchType.value !== "NFC") return;
504
+ fetchCards("NFC");
505
+ }, 500);
506
+
507
+ // Vuetify hands back null when it clears the field, and re-sets "" on blur;
508
+ // only a real change of the trimmed term should cost a request.
509
+ watch(cardSearch, (val, old) => {
510
+ if ((val ?? "").trim() === (old ?? "").trim()) return;
511
+ searchCards();
512
+ });
513
+
419
514
  function addCard(card: any) {
420
515
  const already = selectedCards.value.some((c) => c._id === card._id);
421
516
  if (!already) selectedCards.value = [...selectedCards.value, card];
@@ -68,8 +68,50 @@
68
68
  </v-autocomplete>
69
69
  </v-col>
70
70
 
71
- <!-- ROLE -->
72
- <v-col cols="12">
71
+ <!--
72
+ MODULES, for a NEW client (owner, 2026-09-14). Its owner gets the
73
+ client's own full-access owner role, bounded by exactly these, so
74
+ there is no role to pick; everything of the chosen service starts
75
+ ticked. A module unticked here is hidden from the client's people.
76
+ -->
77
+ <v-col v-if="newClient" cols="12" class="mt-2">
78
+ <div v-for="app in invite.app" :key="`modules-${app}`" class="mb-4">
79
+ <InputLabel :title="`Modules for ${appTitle(app)}`" required />
80
+ <p class="text-caption text-medium-emphasis mb-2">
81
+ The client's owner gets full access to the modules ticked here,
82
+ and nothing else. You can change this later on the client's
83
+ details.
84
+ </p>
85
+ <div v-for="group in inviteModuleGroups(app)" :key="`${app}-${group.key}`" class="mb-2">
86
+ <div class="text-subtitle-2">{{ group.label }}</div>
87
+ <v-row no-gutters>
88
+ <v-col v-for="key in group.modules" :key="`${app}-${group.key}-${key}`" cols="12" sm="6">
89
+ <v-checkbox
90
+ v-if="ALWAYS_ALLOWED_MODULES.includes(key)"
91
+ :model-value="true"
92
+ :label="`${formatResourceLabel(key)} — always included`"
93
+ disabled
94
+ density="compact"
95
+ hide-details
96
+ color="primary"
97
+ />
98
+ <v-checkbox
99
+ v-else
100
+ v-model="modulesByApp[app]"
101
+ :value="key"
102
+ :label="formatResourceLabel(key)"
103
+ density="compact"
104
+ hide-details
105
+ color="primary"
106
+ />
107
+ </v-col>
108
+ </v-row>
109
+ </div>
110
+ </div>
111
+ </v-col>
112
+
113
+ <!-- ROLE: only for an organisation that already exists -->
114
+ <v-col v-if="!newClient" cols="12">
73
115
  <InputLabel title="Role" required />
74
116
  <v-autocomplete
75
117
  v-model="invite.role"
@@ -147,6 +189,9 @@ import useUser from '../composables/useUser'
147
189
  import useUtils from '../composables/useUtils'
148
190
  import useOrg from '../composables/useOrg'
149
191
  import useMember from '../composables/useMember'
192
+ import { inviteModuleGroups } from '../utils/client-invite-modules'
193
+ import { ALWAYS_ALLOWED_MODULES } from '../utils/org-modules'
194
+ import { formatResourceLabel } from '../utils/permission-labels'
150
195
 
151
196
  const APP = useRuntimeConfig().public.APP
152
197
 
@@ -319,10 +364,34 @@ watch(
319
364
  }
320
365
  )
321
366
 
367
+ /* ================= NEW CLIENT: MODULES ================= */
368
+ /*
369
+ * No organisation yet means this invitation creates a client. The server drops
370
+ * any role on such an invitation (the owner gets the client's own owner role)
371
+ * and stores the modules chosen here, one application per request.
372
+ */
373
+ const newClient = computed(() => !org.value?._id)
374
+
375
+ const appTitle = (value: string) => APP_LIST.find(app => app.value === value)?.title ?? value
376
+
377
+ /** Ticked modules per chosen application; a newly chosen one starts with all ticked. */
378
+ const modulesByApp = ref<Record<string, string[]>>({})
379
+
380
+ function syncModules(chosen: string[]) {
381
+ const next: Record<string, string[]> = {}
382
+ for (const app of chosen) {
383
+ next[app] = modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)
384
+ }
385
+ modulesByApp.value = next
386
+ }
387
+
388
+ syncModules(invite.value.app)
389
+
322
390
  /* ================= EVENTS ================= */
323
391
  async function handleUpdateApp(value: string[]) {
324
392
  invite.value.role = ""
325
393
  invite.value.site = ""
394
+ syncModules(value)
326
395
  await refreshRoles()
327
396
  }
328
397
 
@@ -403,7 +472,18 @@ async function submit() {
403
472
 
404
473
  app: [app],
405
474
 
406
- role: invite.value.role,
475
+ ...(newClient.value
476
+ ? {
477
+ // Always-allowed modules are ticked and locked, so the list is
478
+ // never empty (an empty list would mean "everything").
479
+ modules: [
480
+ ...new Set([
481
+ ...ALWAYS_ALLOWED_MODULES,
482
+ ...(modulesByApp.value[app] ?? inviteModuleGroups(app).flatMap(group => group.modules)),
483
+ ]),
484
+ ],
485
+ }
486
+ : { role: invite.value.role }),
407
487
 
408
488
  org: org.value?._id,
409
489
 
@@ -228,7 +228,11 @@ export default function useAccessManagement() {
228
228
  unitId: string;
229
229
  page?: number;
230
230
  limit?: number;
231
+ /** Card-number search. Sent only when non-empty; API-core does not read
232
+ * it yet, so until it does the list comes back unfiltered. */
233
+ search?: string;
231
234
  }) {
235
+ const search = params.search?.trim();
232
236
  return useNuxtApp().$api<Record<string, any>>(
233
237
  `/api/access-management/available-card-contractor/${params.type}`,
234
238
  {
@@ -238,6 +242,7 @@ export default function useAccessManagement() {
238
242
  unitId: params.unitId,
239
243
  page: params.page ?? 1,
240
244
  limit: params.limit ?? 100,
245
+ ...(search ? { search } : {}),
241
246
  },
242
247
  }
243
248
  );
@@ -21,7 +21,8 @@ export default function useUser() {
21
21
  name = '',
22
22
  org = '',
23
23
  site = '',
24
- siteName = ''
24
+ siteName = '',
25
+ modules
25
26
  }: {
26
27
  email?: string
27
28
  app?: string[]
@@ -30,6 +31,8 @@ export default function useUser() {
30
31
  org?: string
31
32
  site?: string
32
33
  siteName?: string
34
+ /** A new client's modules (Seven365 staff only). */
35
+ modules?: string[]
33
36
  } = {}) {
34
37
  return useNuxtApp().$api<Record<string, any>>('/api/auth/invite/user', {
35
38
  method: 'POST',
@@ -40,7 +43,8 @@ export default function useUser() {
40
43
  name,
41
44
  org,
42
45
  ...(site && { siteId: site }),
43
- ...(siteName && { siteName })
46
+ ...(siteName && { siteName }),
47
+ ...(modules && { modules })
44
48
  }
45
49
  })
46
50
  }
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.11.1-staging.314",
5
+ "version": "4.11.1-staging.316",
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.",
@@ -0,0 +1,56 @@
1
+ import { PERMISSIONS } from "../constants/permissions";
2
+ import { applicationModules, groupModulesByApplication } from "./module-applications";
3
+
4
+ /**
5
+ * THE MODULES A NEW CLIENT IS OFFERED ON "INVITE CLIENT".
6
+ *
7
+ * Owner, 2026-09-14: *"Client Owner Super Admin can only have the full access on
8
+ * what Seven365 Super Admin given to them, same goes to the modules that they
9
+ * can access."* So the Super Admin chooses the modules when inviting, and the
10
+ * server enforces that list from the day the client is created.
11
+ *
12
+ * The same catalogue and the same narrowing as the Client details card
13
+ * (`web-app-org pages/super-admin/client-details.vue` + `utils/module-nature.js`):
14
+ * the flat catalogue plus every application's modules, grouped by application,
15
+ * then only the applications that go with the client's nature, plus the modules
16
+ * no application claims (`sites`, `customers`, ...). A client created here and
17
+ * opened on that card shows exactly what was ticked.
18
+ */
19
+
20
+ /**
21
+ * Nature of business -> the application groups that client is offered.
22
+ * Mirrors `web-app-org utils/module-nature.js NATURE_APPLICATIONS` (owner,
23
+ * 2026-09-12); `test/client-invite-modules.test.mjs` pins the pairs.
24
+ */
25
+ export const NATURE_APPLICATIONS: Readonly<Record<string, readonly string[]>> = Object.freeze({
26
+ security_agency: ["security"],
27
+ cleaning_services: ["cleaning"],
28
+ pest_control_services: ["pest"],
29
+ mechanical_electrical_services: ["mechanical-electrical"],
30
+ landscaping_services: ["landscape"],
31
+ pool_maintenance_services: ["pool"],
32
+ property_management_agency: ["property-management"],
33
+ real_estate_developer: ["property-management"],
34
+ });
35
+
36
+ export type ModuleGroup = { key: string; label: string; modules: string[] };
37
+
38
+ /**
39
+ * The groups to offer for a new client of `nature`, every module in them ticked
40
+ * by default. An unknown nature is offered everything, like the card.
41
+ */
42
+ export function inviteModuleGroups(nature: string): ModuleGroup[] {
43
+ const keys = [
44
+ ...new Set([
45
+ ...Object.keys(PERMISSIONS),
46
+ ...applicationModules().flatMap((application) => application.modules),
47
+ ]),
48
+ ];
49
+ const { groups, ungrouped } = groupModulesByApplication(keys);
50
+ const applications = Object.hasOwn(NATURE_APPLICATIONS, nature) ? NATURE_APPLICATIONS[nature] : null;
51
+
52
+ const shown = applications ? groups.filter((group) => applications.includes(group.key)) : groups;
53
+ return ungrouped.length
54
+ ? [...shown, { key: "other", label: "Not tied to a service application", modules: ungrouped }]
55
+ : shown;
56
+ }