@7365admin1/layer-common 4.35.1-staging.379 → 4.35.1-staging.381

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.
@@ -70,7 +70,10 @@
70
70
  :key="item._id"
71
71
  type="button"
72
72
  class="notif-card"
73
- :class="{ 'notif-card--unread': !item.hasRead }"
73
+ :class="{
74
+ 'notif-card--unread': !item.hasRead,
75
+ 'notif-card--plain': !targetFor(item),
76
+ }"
74
77
  @click="openNotification(item)"
75
78
  >
76
79
  <div class="notif-card__top">
@@ -134,7 +137,7 @@ import {
134
137
  timeAgo,
135
138
  type TInboxItem,
136
139
  } from "../utils/notification-inbox";
137
- import { externalTargetUrl, notificationTarget } from "../utils/notification-target";
140
+ import { chooseNavigation, notificationTarget } from "../utils/notification-target";
138
141
 
139
142
  /**
140
143
  * The top-bar notification feed for the web, in every signed-in app.
@@ -304,26 +307,59 @@ function markRead(item: Record<string, any>) {
304
307
  * layer: the ten apps that have no order queue simply do not match it, and the
305
308
  * click there stays what it always was.
306
309
  */
307
- async function goToSubject(item: Record<string, any>) {
308
- const target = notificationTarget(item as any, {
310
+ function targetFor(item: Record<string, any>) {
311
+ return notificationTarget(item as any, {
309
312
  // The org app nests under `organization`; the service apps under `org`.
310
- organization: String(route.params?.organization ?? route.params?.org ?? ""),
313
+ // Staff pages and the org app have neither, so the person's own default
314
+ // organisation builds a service-app link from there.
315
+ organization: String(
316
+ route.params?.organization ?? route.params?.org ?? currentUser.value?.defaultOrg ?? "",
317
+ ),
318
+ site: String(route.params?.site ?? ""),
311
319
  });
312
- if (!target) return;
313
-
314
- if (typeof router.hasRoute !== "function" || !router.hasRoute(target.name)) {
315
- // The page lives in another web app (the invitation is answered in the
316
- // organisation app): go there by URL, or stay put if it is not configured.
317
- const href = externalTargetUrl(target, { org: String(appConfig?.public?.APP_ORG ?? "") });
318
- if (!href) return;
319
- open.value = false;
320
- window.location.assign(href);
321
- return;
320
+ }
321
+
322
+ /** A path this app really has a page for (every app has a 404 fallback, so check the match). */
323
+ function hasLocalPage(path: string) {
324
+ try {
325
+ const resolved = router.resolve(path);
326
+ return resolved.matched.length > 0 && !resolved.matched.some((m) => m.path.includes("pathMatch"));
327
+ } catch {
328
+ return false;
322
329
  }
330
+ }
331
+
332
+ /** Every web app's URL, keyed like `TAppKey`, from the layer's runtime config. */
333
+ function appUrls() {
334
+ const p = appConfig?.public ?? {};
335
+ return {
336
+ org: String(p.APP_ORG ?? ""),
337
+ security: String(p.APP_SECURITY ?? ""),
338
+ "property-management": String(p.APP_PROPERTY_MANAGEMENT ?? ""),
339
+ hygiene: String(p.APP_HYGIENE ?? ""),
340
+ "mechanical-electrical": String(p.APP_MECHANICAL_ELECTRICAL ?? ""),
341
+ "pest-control": String(p.APP_PEST_CONTROL ?? ""),
342
+ landscaping: String(p.APP_LANDSCAPING ?? ""),
343
+ "pool-maintenance": String(p.APP_POOL_MAINTENANCE ?? ""),
344
+ };
345
+ }
346
+
347
+ /** The decision is `chooseNavigation` (unit-tested); this only carries it out. */
348
+ async function goToSubject(item: Record<string, any>) {
349
+ const nav = chooseNavigation(targetFor(item), {
350
+ hasRoute: (name) => typeof router.hasRoute === "function" && router.hasRoute(name),
351
+ hasPage: hasLocalPage,
352
+ appUrls: appUrls(),
353
+ });
354
+ if (!nav) return;
323
355
 
324
356
  open.value = false;
357
+ if (nav.type === "href") {
358
+ window.location.assign(nav.href);
359
+ return;
360
+ }
325
361
  try {
326
- await router.push({ name: target.name, params: target.params, query: target.query });
362
+ await router.push(nav.to as any);
327
363
  } catch {
328
364
  // A cancelled or duplicate navigation is not worth an error in the top bar.
329
365
  }
@@ -462,6 +498,11 @@ onBeforeUnmount(() => {
462
498
  background: var(--hover);
463
499
  }
464
500
 
501
+ /* Nothing to open: still marks read on click, but does not look like a link. */
502
+ .notif-card--plain {
503
+ cursor: default;
504
+ }
505
+
465
506
  .notif-card__top {
466
507
  display: flex;
467
508
  align-items: baseline;
@@ -101,9 +101,14 @@
101
101
  style="max-height: calc(100vh - 280px)"
102
102
  >
103
103
  <template #item.companyName="{ item }">
104
- <span class="d-block text-truncate sp-col-company">{{
105
- item.companyName
106
- }}</span>
104
+ <span
105
+ class="d-block text-truncate sp-col-company"
106
+ :class="{ 'sp-muted': item.companyKnown === false }"
107
+ >{{ item.companyName }}</span>
108
+ <div v-if="item.contactPhone" class="sp-sub">{{ item.contactPhone }}</div>
109
+ </template>
110
+ <template #item.invited="{ item }">
111
+ <span class="d-block text-truncate">{{ item.invitedLine || "-" }}</span>
107
112
  </template>
108
113
  <template #item.email="{ item }">
109
114
  <span class="d-block text-truncate sp-col-email">{{
@@ -128,9 +133,10 @@
128
133
  -->
129
134
  <StatusChip
130
135
  class="text-none"
131
- :status="item.statusRaw || item.status"
136
+ :status="item.viewStatus || item.statusRaw || item.status"
132
137
  :label="item.status"
133
138
  />
139
+ <div v-if="item.statusLine" class="mt-1 sp-sub">{{ item.statusLine }}</div>
134
140
  <!-- Was `text-caption text-medium-emphasis` - Roboto 12px at
135
141
  Vuetify's 60% opacity. The design's sub-line is `--muted`. -->
136
142
  <div v-if="item.rejectionReason" class="mt-1 sp-reject-reason">
@@ -157,6 +163,11 @@
157
163
  </v-btn>
158
164
  </template>
159
165
  <v-list density="compact" min-width="220">
166
+ <v-list-item
167
+ v-if="item.providerOrgId"
168
+ title="View provider"
169
+ @click="openProvider(item)"
170
+ />
160
171
  <v-list-item
161
172
  title="Cancel invitation"
162
173
  :disabled="!canCancelInvite(item)"
@@ -178,6 +189,21 @@
178
189
  />
179
190
  </v-list>
180
191
  </v-menu>
192
+ <!--
193
+ A provider on this site through an accepted invitation. Its row is
194
+ the engagement itself, not a stored service-providers record, so
195
+ the In-Active move (which acts on that record) does not apply.
196
+ -->
197
+ <v-btn
198
+ v-else-if="item.source === 'engagement'"
199
+ icon
200
+ variant="text"
201
+ density="comfortable"
202
+ aria-label="View provider"
203
+ @click="openProvider(item)"
204
+ >
205
+ <v-icon>mdi-information-outline</v-icon>
206
+ </v-btn>
181
207
  <v-menu v-else-if="item.source === 'provider'" location="bottom end">
182
208
  <template #activator="{ props: menuProps }">
183
209
  <v-btn
@@ -239,6 +265,26 @@
239
265
 
240
266
  Same members, same two columns, same loading and empty copy, same close.
241
267
  -->
268
+ <!-- The provider, as the organisation that invited it may see it. -->
269
+ <v-dialog v-model="providerDialog" max-width="480">
270
+ <v-card class="screen-modal">
271
+ <v-card-title>{{ providerRow?.companyName }}</v-card-title>
272
+ <v-card-text class="screen-modal__body">
273
+ <dl class="sp-details">
274
+ <template v-for="line in providerLines" :key="line[0]">
275
+ <dt>{{ line[0] }}</dt>
276
+ <dd>{{ line[1] }}</dd>
277
+ </template>
278
+ </dl>
279
+ </v-card-text>
280
+ <div class="screen-modal__footer">
281
+ <v-btn class="screen-btn-ghost" variant="outlined" @click="providerDialog = false">
282
+ Close
283
+ </v-btn>
284
+ </div>
285
+ </v-card>
286
+ </v-dialog>
287
+
242
288
  <v-dialog v-model="viewDialog" max-width="514">
243
289
  <v-card class="screen-modal">
244
290
  <v-card-title>Members ({{ memberDialogCount }})</v-card-title>
@@ -669,6 +715,12 @@ import useVerification from "../composables/useVerification";
669
715
  // import useRole from "../composables/useRole";
670
716
  import { errorConverter } from "../utils/data";
671
717
  import { pickRouteName } from "../utils/route-name";
718
+ import {
719
+ sentCompany,
720
+ sentInvitedLine,
721
+ sentStatusLine,
722
+ spDay,
723
+ } from "../utils/sp-inviter-row";
672
724
 
673
725
  type ListTab = "active" | "pending" | "inactive";
674
726
 
@@ -681,9 +733,21 @@ type TableRow = {
681
733
  type: string;
682
734
  members: string;
683
735
  status: string;
684
- source: "provider" | "invite";
736
+ /** provider: a stored row; engagement: on the site through an accepted
737
+ * invitation; invite: an invitation this organisation sent. */
738
+ source: "provider" | "engagement" | "invite";
685
739
  /** the stored status, for deciding which actions a row may offer */
686
740
  statusRaw?: string;
741
+ /** what the row reads as (a lapsed "pending" is "expired") - the chip tone */
742
+ viewStatus?: string;
743
+ statusLine?: string;
744
+ companyKnown?: boolean;
745
+ invitedLine?: string;
746
+ providerOrgId?: string;
747
+ contactEmail?: string;
748
+ contactPhone?: string;
749
+ answeredAt?: string | null;
750
+ onSite?: boolean;
687
751
  /** shown under a "Not approved" row, in Seven365's own words */
688
752
  rejectionReason?: string;
689
753
  siteName?: string;
@@ -774,7 +838,7 @@ const billingRouteName = pickRouteName(
774
838
  "service-provider-mgmt-billing"
775
839
  );
776
840
 
777
- const headers = [
841
+ const providerHeaders = [
778
842
  {
779
843
  title: "Company name",
780
844
  value: "companyName",
@@ -797,7 +861,8 @@ const headers = [
797
861
  maxWidth: "180px",
798
862
  },
799
863
  {
800
- title: "Members",
864
+ // The provider's people assigned to this site - not its whole headcount.
865
+ title: "Staff on site",
801
866
  value: "members",
802
867
  sortable: false,
803
868
  width: "88px",
@@ -819,6 +884,20 @@ const headers = [
819
884
  },
820
885
  ];
821
886
 
887
+ /** The Invitations tab: who it went to, who sent it and when, what happened. */
888
+ const inviteHeaders = [
889
+ { ...providerHeaders[0], title: "Company" },
890
+ { ...providerHeaders[1], title: "Invited email" },
891
+ { ...providerHeaders[2], title: "Service" },
892
+ { title: "Invited", value: "invited", sortable: false, minWidth: "150px" },
893
+ { ...providerHeaders[4], width: "200px" },
894
+ providerHeaders[5],
895
+ ];
896
+
897
+ const headers = computed(() =>
898
+ listTab.value === "pending" ? inviteHeaders : providerHeaders
899
+ );
900
+
822
901
  const { natureOfBusinessV3 } = useLocal();
823
902
  const { requiredRule, emailRule, debounce } = useUtils();
824
903
  const { getUserByEmail } = useUser();
@@ -1171,6 +1250,37 @@ function typeDisplay(type: string, nature?: string) {
1171
1250
  return hit?.title ?? type ?? "-";
1172
1251
  }
1173
1252
 
1253
+ const providerDialog = ref(false);
1254
+ const providerRow = ref<TableRow | null>(null);
1255
+
1256
+ function openProvider(row: TableRow) {
1257
+ providerRow.value = row;
1258
+ providerDialog.value = true;
1259
+ }
1260
+
1261
+ /** Only what the inviting organisation needs; nothing about the provider's
1262
+ * own staff or other clients. */
1263
+ const providerLines = computed<Array<[string, string]>>(() => {
1264
+ const row = providerRow.value;
1265
+ if (!row) return [];
1266
+ const lines: Array<[string, string]> = [
1267
+ ["Service", row.type],
1268
+ ["Email", row.contactEmail || row.email],
1269
+ ];
1270
+ if (row.contactPhone) lines.push(["Phone", row.contactPhone]);
1271
+ if (row.source === "invite") {
1272
+ lines.push(["Invited", row.invitedLine || "-"]);
1273
+ if (row.answeredAt) lines.push(["Accepted", spDay(row.answeredAt)]);
1274
+ lines.push([
1275
+ "On this site",
1276
+ row.onSite ? "Yes" : "No - removed since it accepted",
1277
+ ]);
1278
+ } else {
1279
+ lines.push(["Staff on this site", row.members]);
1280
+ }
1281
+ return lines.filter((line) => line[1]);
1282
+ });
1283
+
1174
1284
  function statusDisplay(raw: string, source: TableRow["source"]) {
1175
1285
  if (source === "invite") return "Pending";
1176
1286
  const s = (raw || "").toLowerCase();
@@ -1228,12 +1338,14 @@ function mapProviderRows(raw: Record<string, any>[]): TableRow[] {
1228
1338
  _id: String(row._id ?? ""),
1229
1339
  userId: String(row.user ?? ""),
1230
1340
  serviceProviderOrgId: String(row.serviceProviderOrgId ?? ""),
1231
- companyName: row.name ?? "-",
1341
+ companyName: row.name || "-",
1232
1342
  email: formatEmailCell(row.email),
1343
+ contactEmail: String(row.email ?? ""),
1344
+ contactPhone: String(row.contact ?? ""),
1233
1345
  type: typeDisplay(row.type ?? "", row.nature),
1234
1346
  members: formatMembersCell(row.members),
1235
1347
  status: statusDisplay(row.status ?? "active", "provider"),
1236
- source: "provider",
1348
+ source: row.source === "engagement" ? "engagement" : "provider",
1237
1349
  }));
1238
1350
  }
1239
1351
 
@@ -1247,24 +1359,35 @@ function inviteTypeLabel(t: string) {
1247
1359
  }
1248
1360
 
1249
1361
  function mapInviteRows(raw: Record<string, any>[]): TableRow[] {
1250
- return raw.map((row) => ({
1362
+ return raw.map((row) => {
1363
+ const company = sentCompany(row);
1364
+ return {
1251
1365
  _id: String(row._id ?? ""),
1252
1366
  userId: String(row.user ?? ""),
1253
- serviceProviderOrgId: String(row.metadata?.serviceProviderOrgId ?? ""),
1254
- companyName: row.metadata?.name || "-",
1367
+ serviceProviderOrgId: String(row.providerOrgId || row.metadata?.serviceProviderOrgId || ""),
1368
+ companyName: company.text,
1369
+ companyKnown: company.known,
1255
1370
  email: formatEmailCell(row.email),
1256
1371
  type: row.metadata?.app
1257
1372
  ? typeDisplay(row.metadata.app)
1258
1373
  : inviteTypeLabel(row.type ?? ""),
1259
- members: "-",
1260
- // Every invitation used to read "Pending" whatever had happened to it. It
1261
- // now says which of the seven states it is actually in, in words.
1262
- status: row.statusLabel || serviceProviderInviteLabel(row.status),
1374
+ members: "",
1375
+ status:
1376
+ row.statusLabel || serviceProviderInviteLabel(row.viewStatus || row.status),
1263
1377
  statusRaw: String(row.status ?? ""),
1378
+ viewStatus: String(row.viewStatus || row.status || ""),
1379
+ statusLine: sentStatusLine(row),
1380
+ invitedLine: sentInvitedLine(row),
1381
+ providerOrgId: String(row.providerOrgId ?? ""),
1382
+ contactEmail: String(row.contactEmail ?? ""),
1383
+ contactPhone: String(row.contactPhone ?? ""),
1384
+ answeredAt: row.answeredAt ?? null,
1385
+ onSite: Boolean(row.onSite),
1264
1386
  rejectionReason: row.rejectionReason ?? "",
1265
1387
  siteName: row.metadata?.siteName ?? "",
1266
1388
  source: "invite",
1267
- }));
1389
+ };
1390
+ });
1268
1391
  }
1269
1392
 
1270
1393
  async function loadList() {
@@ -1294,6 +1417,8 @@ async function loadList() {
1294
1417
  // cancellation is visible here instead of the row simply vanishing.
1295
1418
  const data = await getInvitations({
1296
1419
  org: props.orgId,
1420
+ // this site's invitations, not every site the organisation has
1421
+ siteId: props.siteId,
1297
1422
  status:
1298
1423
  "awaiting-approval,pending,complete,rejected,declined,cancelled,expired",
1299
1424
  page: page.value,
@@ -1313,6 +1438,9 @@ async function loadList() {
1313
1438
  search: searchText.value?.trim() || "",
1314
1439
  limit: pageSize,
1315
1440
  status: statusParam,
1441
+ // the active tab also lists providers on this site through an
1442
+ // accepted invitation
1443
+ ...(statusParam === "active" ? { include: "engagements" } : {}),
1316
1444
  });
1317
1445
  items.value = mapProviderRows(rowsOf(data));
1318
1446
  pages.value = data.pages ?? 0;
@@ -1569,6 +1697,32 @@ async function submitServiceProviderInvite() {
1569
1697
 
1570
1698
  /* The design's sub-line: `--muted` at 12px, the same figure batch I's
1571
1699
  `AttachmentsViewer` settled on. There is no `--fs-sub` token. */
1700
+ .sp-muted {
1701
+ color: var(--muted);
1702
+ }
1703
+
1704
+ .sp-sub {
1705
+ font-family: var(--font-sans);
1706
+ font-size: 12px;
1707
+ color: var(--muted);
1708
+ }
1709
+
1710
+ .sp-details {
1711
+ display: grid;
1712
+ grid-template-columns: max-content 1fr;
1713
+ gap: 8px 16px;
1714
+ margin: 0;
1715
+ }
1716
+
1717
+ .sp-details dt {
1718
+ color: var(--muted);
1719
+ }
1720
+
1721
+ .sp-details dd {
1722
+ margin: 0;
1723
+ overflow-wrap: anywhere;
1724
+ }
1725
+
1572
1726
  .sp-reject-reason,
1573
1727
  .sp-no-permission,
1574
1728
  .sp-members-note {
@@ -58,6 +58,8 @@ export default function useServiceProvider() {
58
58
  orgId = "",
59
59
  siteId = "",
60
60
  status = "",
61
+ /** "engagements": also providers engaged through an accepted invitation. */
62
+ include = "",
61
63
  } = {}) {
62
64
  return useNuxtApp().$api<Record<string, any>>("/api/service-providers", {
63
65
  method: "GET",
@@ -69,6 +71,7 @@ export default function useServiceProvider() {
69
71
  orgId,
70
72
  siteId,
71
73
  ...(status ? { status } : {}),
74
+ ...(include ? { include } : {}),
72
75
  },
73
76
  });
74
77
  }
@@ -18,6 +18,21 @@ export type TServiceProviderInvitation = {
18
18
  expireAt?: string;
19
19
  deletedAt?: string | null;
20
20
  metadata?: Record<string, any>;
21
+ /** A lapsed "pending" reads "expired"; `status` stays the stored value. */
22
+ viewStatus?: string;
23
+ /** The company that accepted it, or the new company's name (sign-up). */
24
+ companyName?: string;
25
+ providerOrgId?: string;
26
+ service?: string;
27
+ invitedByName?: string;
28
+ invitedAt?: string | null;
29
+ /** When it was accepted, declined, cancelled or expired. */
30
+ answeredAt?: string | null;
31
+ /** Shown only once accepted. */
32
+ contactEmail?: string;
33
+ contactPhone?: string;
34
+ /** Accepted and still engaged on the site. */
35
+ onSite?: boolean;
21
36
  history?: Array<{
22
37
  action: string;
23
38
  at: string;
@@ -73,7 +88,9 @@ export default function useServiceProviderInvitation() {
73
88
 
74
89
  function getInvitations({
75
90
  org = "",
91
+ siteId = "",
76
92
  status = "",
93
+ search = "",
77
94
  page = 1,
78
95
  limit = 20,
79
96
  } = {}): Promise<{
@@ -83,7 +100,14 @@ export default function useServiceProviderInvitation() {
83
100
  }> {
84
101
  return useNuxtApp().$api(base, {
85
102
  method: "GET",
86
- query: { org, status, page, limit },
103
+ query: {
104
+ org,
105
+ status,
106
+ page,
107
+ limit,
108
+ ...(siteId ? { siteId } : {}),
109
+ ...(search ? { search } : {}),
110
+ },
87
111
  });
88
112
  }
89
113
 
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.379",
5
+ "version": "4.35.1-staging.381",
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.",
@@ -24,33 +24,68 @@
24
24
  * Eleven web apps render this bell and only `iservice365-web-app-org` has an
25
25
  * order queue. Rather than make eleven apps configure a map, the name is
26
26
  * written down once here and the bell asks its own router whether the route
27
- * exists before pushing — so in the ten apps without the page the click stays
28
- * exactly what it was: mark as read, go nowhere.
27
+ * exists before pushing.
28
+ *
29
+ * EVERY KIND SINCE 2026-09-24 (owner: "the notification never routes me")
30
+ * Each row names what it is about (`params.kind`, else its `module`), and the
31
+ * tables below say which web apps have that page. The bell opens this app's
32
+ * own page when it has one and otherwise jumps to the app that does, by its
33
+ * `APP_*` URL, with the organisation and site in the path.
29
34
  */
30
35
 
31
36
  /** Only the fields a destination is decided from. */
32
37
  export type TTargetRow = {
33
38
  module?: string;
34
39
  screen?: string;
35
- params?: { id?: string; org?: string } | null;
40
+ title?: string;
41
+ appSlug?: string;
42
+ siteId?: string | null;
43
+ /**
44
+ * `kind` is the click-through target every sender sets since 2026-09-24
45
+ * (core `withNotificationKind`); `site` stands in for `siteId` on rows kept
46
+ * unscoped on purpose. Older rows have neither and are read from `module`.
47
+ */
48
+ params?: { id?: string; org?: string; kind?: string; site?: string } | null;
36
49
  };
37
50
 
38
51
  /** What the surrounding app knows that the stored row does not. */
39
52
  export type TTargetContext = {
40
53
  /** The organization in the current URL. Org routes are all nested under it. */
41
54
  organization?: string;
55
+ /** The site in the current URL, used when the row names none. */
56
+ site?: string;
42
57
  };
43
58
 
59
+ /** The web apps a click can land in, keyed like their `APP_*` runtime URLs. */
60
+ export type TAppKey =
61
+ | "org"
62
+ | "security"
63
+ | "property-management"
64
+ | "hygiene"
65
+ | "mechanical-electrical"
66
+ | "pest-control"
67
+ | "landscaping"
68
+ | "pool-maintenance";
69
+
70
+ /** One place the record can be opened: a path inside one web app. */
71
+ export type TCandidate = { app: TAppKey; path: string };
72
+
44
73
  export type TNotificationTarget = {
45
- name: string;
46
- params: Record<string, string>;
74
+ /** A route name in the current app, tried first (the two original targets). */
75
+ name?: string;
76
+ params?: Record<string, string>;
47
77
  query?: Record<string, string>;
48
78
  /**
49
79
  * Set when the page lives in another web app. The bell opens
50
80
  * `<that app's URL><path>` when its own router has no route by `name`.
51
81
  */
52
- app?: "org";
82
+ app?: TAppKey;
53
83
  path?: string;
84
+ /**
85
+ * Every page that shows the record, best first. The bell opens the first one
86
+ * its own router has; otherwise it jumps to the first whose app URL is set.
87
+ */
88
+ candidates?: TCandidate[];
54
89
  };
55
90
 
56
91
  /** Nuxt's generated names for `pages/org/[organization]/marketplace/orders/`. */
@@ -73,13 +108,138 @@ export const VENDOR_ORDER_MODULE = "marketplace-vendor-order";
73
108
  export const SP_INVITATION_SCREEN = "/service-provider-invitation";
74
109
  export const INVITATIONS_ROUTE = "org-organization-client-invitations";
75
110
 
111
+ /**
112
+ * What a row is about. `params.kind` when the sender set it; for older rows the
113
+ * `module`, except where the module is shared: `platform` (a new client, an
114
+ * accepted invitation, a robot) and `other` (both halves of a service-provider
115
+ * invitation) are told apart by the fixed titles their senders use.
116
+ */
117
+ export function notificationKind(item: TTargetRow | null | undefined): string {
118
+ const kind = String(item?.params?.kind ?? "").trim();
119
+ if (kind) return kind;
120
+ const module = String(item?.module ?? "");
121
+ const title = String(item?.title ?? "");
122
+ if (String(item?.screen ?? "") === SP_INVITATION_SCREEN) return "serviceProviderInvite";
123
+ if (module === "platform") {
124
+ if (/^robot /i.test(title)) return "robot";
125
+ if (/^new client/i.test(title)) return "client";
126
+ if (/^invitation accepted/i.test(title)) return "clientInvitation";
127
+ return "";
128
+ }
129
+ if (module === "other") {
130
+ return /(accepted|declined) your invitation$/i.test(title) ? "serviceProviderInviteAnswer" : "";
131
+ }
132
+ return module;
133
+ }
134
+
135
+ /**
136
+ * The web app a mobile-tagged row's work lives in. A work order sent to the
137
+ * iClean365 app is managed in the Hygiene web app, and so on; anything from the
138
+ * resident or iMA365 apps is the property manager's.
139
+ */
140
+ const APP_FOR_SLUG: Record<string, TAppKey> = {
141
+ "iservice365-hygiene-mobile-app": "hygiene",
142
+ "iservice365-m-and-e-mobile-app": "mechanical-electrical",
143
+ "iservice365-pest-control-mobile-app": "pest-control",
144
+ "iservice365-pool-maintenance-mobile-app": "pool-maintenance",
145
+ "iservice365-landscaping-mobile-app": "landscaping",
146
+ "iservice365-landscape-mobile-app": "landscaping",
147
+ };
148
+
149
+ const SERVICE_APPS: TAppKey[] = [
150
+ "property-management",
151
+ "security",
152
+ "hygiene",
153
+ "mechanical-electrical",
154
+ "pest-control",
155
+ "landscaping",
156
+ "pool-maintenance",
157
+ ];
158
+
159
+ /**
160
+ * Site pages, `/<org>/<site>/<page>` in the service web apps, and which apps
161
+ * have them. "any" = every service app has the page; the row's own app leads.
162
+ */
163
+ type TSitePage = { apps: TAppKey[] | "any"; page: (id: string) => string };
164
+ const withId = (list: string) => (id: string) => (id ? `${list}/${id}` : list);
165
+ const SITE_PAGES: Record<string, TSitePage[]> = {
166
+ workOrder: [{ apps: "any", page: withId("work-orders") }],
167
+ feedback: [{ apps: "any", page: withId("feedbacks") }],
168
+ bulletinBoard: [{ apps: "any", page: () => "bulletin-board" }],
169
+ inventory: [{ apps: "any", page: () => "inventory" }],
170
+ event: [{ apps: ["property-management"], page: () => "event-mgmt" }],
171
+ facilityBooking: [{ apps: ["property-management"], page: () => "facility-booking" }],
172
+ onlineForm: [{ apps: ["property-management"], page: () => "online-forms" }],
173
+ documentExpiry: [{ apps: ["property-management"], page: () => "document-mgmt" }],
174
+ emergencyContact: [{ apps: ["property-management"], page: () => "emergency-contacts" }],
175
+ incidentReport: [{ apps: ["security", "property-management"], page: withId("incident-reports") }],
176
+ visitors: [
177
+ { apps: ["security"], page: () => "visitor-management" },
178
+ { apps: ["property-management"], page: () => "visitor-mgmt" },
179
+ ],
180
+ virtualPatrol: [{ apps: ["security"], page: () => "virtual-patrol/logs" }],
181
+ cameraFault: [
182
+ { apps: ["security"], page: () => "virtual-patrol/cctv" },
183
+ { apps: ["property-management"], page: () => "cctv" },
184
+ ],
185
+ serviceProviderInviteAnswer: [
186
+ { apps: SERVICE_APPS.filter((a) => a !== "hygiene"), page: () => "service-providers" },
187
+ ],
188
+ };
189
+ SITE_PAGES.myVisitors = SITE_PAGES.visitors;
190
+
191
+ /** Every kind the web can open, for tests and for anyone asking "is this clickable?". */
192
+ export const WEB_TARGET_KINDS = [
193
+ ...Object.keys(SITE_PAGES),
194
+ "serviceProviderInvite",
195
+ VENDOR_ORDER_MODULE,
196
+ "robot",
197
+ "client",
198
+ "clientInvitation",
199
+ ];
200
+
201
+ function sitePageTarget(
202
+ kind: string,
203
+ item: TTargetRow,
204
+ organization: string,
205
+ site: string,
206
+ ): TNotificationTarget | null {
207
+ const pages = SITE_PAGES[kind];
208
+ if (!pages || !organization || !site) return null;
209
+ const id = encodeURIComponent(String(item.params?.id ?? "").trim());
210
+ const home = APP_FOR_SLUG[String(item.appSlug ?? "")] ?? "property-management";
211
+ const base = `/${encodeURIComponent(organization)}/${encodeURIComponent(site)}/`;
212
+ const candidates: TCandidate[] = [];
213
+ for (const { apps, page } of pages) {
214
+ const list = apps === "any" ? [home, ...SERVICE_APPS.filter((a) => a !== home)] : apps;
215
+ for (const app of list) candidates.push({ app, path: base + page(id) });
216
+ }
217
+ return { candidates };
218
+ }
219
+
220
+ /** Seven365 staff pages, in the organisation app. */
221
+ function staffTarget(kind: string, item: TTargetRow): TNotificationTarget | null {
222
+ const id = String(item.params?.id ?? "").trim();
223
+ if (kind === "robot") return { candidates: [{ app: "org", path: "/super-admin/robots" }] };
224
+ if (kind === "clientInvitation") {
225
+ return { candidates: [{ app: "org", path: "/super-admin/client-list" }] };
226
+ }
227
+ if (kind === "client") {
228
+ return id
229
+ ? { candidates: [{ app: "org", path: "/super-admin/client-details" }], query: { org: id } }
230
+ : { candidates: [{ app: "org", path: "/super-admin/client-list" }] };
231
+ }
232
+ return null;
233
+ }
234
+
76
235
  export function notificationTarget(
77
236
  item: TTargetRow | null | undefined,
78
237
  context: TTargetContext = {},
79
238
  ): TNotificationTarget | null {
80
239
  const organization = String(context.organization ?? "").trim();
240
+ const kind = notificationKind(item);
81
241
 
82
- if (String(item?.screen ?? "") === SP_INVITATION_SCREEN) {
242
+ if (kind === "serviceProviderInvite") {
83
243
  // The invited company's organisation when the row names it (the invitation
84
244
  // belongs there), otherwise the one on screen. The list on that page is
85
245
  // keyed on the signed-in account, so either shows the invitation.
@@ -96,7 +256,14 @@ export function notificationTarget(
96
256
  };
97
257
  }
98
258
 
99
- if (String(item?.module ?? "") !== VENDOR_ORDER_MODULE) return null;
259
+ if (!item) return null;
260
+ const staff = staffTarget(kind, item);
261
+ if (staff) return staff;
262
+
263
+ if (kind !== VENDOR_ORDER_MODULE) {
264
+ const site = String(item.siteId ?? item.params?.site ?? context.site ?? "").trim();
265
+ return sitePageTarget(kind, item, organization, site);
266
+ }
100
267
 
101
268
  // Every order route is nested under the organization. Without one there is no
102
269
  // URL to build, and guessing an organization for somebody who belongs to
@@ -104,12 +271,23 @@ export function notificationTarget(
104
271
  if (!organization) return null;
105
272
 
106
273
  const id = String(item?.params?.id ?? "").trim();
274
+ const orders = `/org/${encodeURIComponent(organization)}/marketplace/orders`;
107
275
 
108
276
  // No id — an older row, or one whose params were dropped — still has an
109
277
  // honest destination: the queue the order is sitting in.
110
- if (!id) return { name: ORDER_QUEUE_ROUTE, params: { organization } };
278
+ if (!id) {
279
+ return {
280
+ name: ORDER_QUEUE_ROUTE,
281
+ params: { organization },
282
+ candidates: [{ app: "org", path: orders }],
283
+ };
284
+ }
111
285
 
112
- return { name: ORDER_DETAIL_ROUTE, params: { organization, id } };
286
+ return {
287
+ name: ORDER_DETAIL_ROUTE,
288
+ params: { organization, id },
289
+ candidates: [{ app: "org", path: `${orders}/${encodeURIComponent(id)}` }],
290
+ };
113
291
  }
114
292
 
115
293
  /**
@@ -118,11 +296,49 @@ export function notificationTarget(
118
296
  */
119
297
  export function externalTargetUrl(
120
298
  target: TNotificationTarget | null | undefined,
121
- appUrls: { org?: string } = {},
299
+ appUrls: Partial<Record<TAppKey, string>> = {},
122
300
  ): string {
123
- if (!target?.app || !target.path) return "";
124
- const base = String(appUrls[target.app] ?? "").trim().replace(/\/+$/, "");
125
- if (!base) return "";
126
- const qs = new URLSearchParams(target.query ?? {}).toString();
127
- return `${base}${target.path}${qs ? `?${qs}` : ""}`;
301
+ const options: TCandidate[] = [
302
+ ...(target?.app && target.path ? [{ app: target.app, path: target.path }] : []),
303
+ ...(target?.candidates ?? []),
304
+ ];
305
+ const qs = new URLSearchParams(target?.query ?? {}).toString();
306
+ for (const { app, path } of options) {
307
+ const base = String(appUrls[app] ?? "").trim().replace(/\/+$/, "");
308
+ if (base) return `${base}${path}${qs ? `?${qs}` : ""}`;
309
+ }
310
+ return "";
311
+ }
312
+
313
+ /** What the bell does with a click: move inside this app, open another app, or nothing. */
314
+ export type TNavigation =
315
+ | {
316
+ type: "route";
317
+ to: { name?: string; params?: Record<string, string>; path?: string; query?: Record<string, string> };
318
+ }
319
+ | { type: "href"; href: string }
320
+ | null;
321
+
322
+ /**
323
+ * This app's own page first — by route name, then by path (the site is in the
324
+ * path, so opening it switches the site) — else the first app that has the
325
+ * page and whose URL is configured. The page itself still checks the person may
326
+ * see it: a link grants nothing.
327
+ */
328
+ export function chooseNavigation(
329
+ target: TNotificationTarget | null | undefined,
330
+ app: {
331
+ hasRoute: (name: string) => boolean;
332
+ hasPage: (path: string) => boolean;
333
+ appUrls?: Partial<Record<TAppKey, string>>;
334
+ },
335
+ ): TNavigation {
336
+ if (!target) return null;
337
+ if (target.name && app.hasRoute(target.name)) {
338
+ return { type: "route", to: { name: target.name, params: target.params, query: target.query } };
339
+ }
340
+ const local = target.candidates?.find((c) => app.hasPage(c.path));
341
+ if (local) return { type: "route", to: { path: local.path, query: target.query } };
342
+ const href = externalTargetUrl(target, app.appUrls);
343
+ return href ? { type: "href", href } : null;
128
344
  }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The inviting organisation's view of one service-provider invitation, in
3
+ * words. Pure, so it is tested without a browser.
4
+ *
5
+ * The company name comes from the server (`companyName`: the company that
6
+ * accepted, or the new company's name a sign-up invitation carried). While an
7
+ * invitation is unanswered the company is genuinely not known yet - the cell
8
+ * says so instead of drawing "-".
9
+ */
10
+
11
+ export type TSentInvitation = {
12
+ status?: string;
13
+ viewStatus?: string;
14
+ statusLabel?: string;
15
+ companyName?: string;
16
+ metadata?: Record<string, any>;
17
+ invitedByName?: string;
18
+ invitedAt?: string | null;
19
+ createdAt?: string | null;
20
+ answeredAt?: string | null;
21
+ onSite?: boolean;
22
+ };
23
+
24
+ const ANSWERED: Record<string, string> = {
25
+ complete: "Accepted",
26
+ declined: "Declined",
27
+ cancelled: "Cancelled",
28
+ rejected: "Not approved",
29
+ expired: "Expired",
30
+ };
31
+
32
+ export function spDay(value?: string | null): string {
33
+ if (!value) return "";
34
+ const d = new Date(value);
35
+ return Number.isNaN(d.getTime())
36
+ ? ""
37
+ : d.toLocaleDateString("en-GB", { day: "numeric", month: "short", year: "numeric" });
38
+ }
39
+
40
+ /** The company cell: the name, or why there is none yet. */
41
+ export function sentCompany(row: TSentInvitation): { text: string; known: boolean } {
42
+ const name = String(row.companyName || row.metadata?.name || "").trim();
43
+ if (name) return { text: name, known: true };
44
+ const status = row.viewStatus || row.status || "";
45
+ return {
46
+ text: ["pending", "awaiting-approval"].includes(status) ? "Not accepted yet" : "Not accepted",
47
+ known: false,
48
+ };
49
+ }
50
+
51
+ /** "Invited by Tommy on 24 Sep 2026". */
52
+ export function sentInvitedLine(row: TSentInvitation): string {
53
+ const who = String(row.invitedByName ?? "").trim();
54
+ const when = spDay(row.invitedAt ?? row.createdAt);
55
+ return [who ? `by ${who}` : "", when ? `on ${when}` : ""].filter(Boolean).join(" ");
56
+ }
57
+
58
+ /** The line under the status: when it was answered, and what it means now. */
59
+ export function sentStatusLine(row: TSentInvitation): string {
60
+ const status = row.viewStatus || row.status || "";
61
+ const when = spDay(row.answeredAt);
62
+ if (status === "complete" && row.onSite === false) {
63
+ return `Accepted${when ? ` on ${when}` : ""} · no longer on this site`;
64
+ }
65
+ if (ANSWERED[status]) return when ? `${ANSWERED[status]} on ${when}` : "";
66
+ if (status === "awaiting-approval") return "Seven365 checks it before it is sent";
67
+ if (status === "pending") return "Sent - waiting for their answer";
68
+ return "";
69
+ }