@7365admin1/layer-common 4.28.1-staging.356 → 4.28.1-staging.357
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.
|
@@ -134,6 +134,7 @@ import {
|
|
|
134
134
|
timeAgo,
|
|
135
135
|
type TInboxItem,
|
|
136
136
|
} from "../utils/notification-inbox";
|
|
137
|
+
import { notificationTarget } from "../utils/notification-target";
|
|
137
138
|
|
|
138
139
|
/**
|
|
139
140
|
* The top-bar notification feed for the web, in every signed-in app.
|
|
@@ -165,6 +166,8 @@ defineProps({
|
|
|
165
166
|
|
|
166
167
|
const { getAll, getUnreadCount, markAsRead, markAllAsRead } = useNotification();
|
|
167
168
|
const { currentUser } = useLocalAuth();
|
|
169
|
+
const route = useRoute();
|
|
170
|
+
const router = useRouter();
|
|
168
171
|
|
|
169
172
|
const open = ref(false);
|
|
170
173
|
const loading = ref(false);
|
|
@@ -269,16 +272,49 @@ function announce(fresh: TInboxItem[]) {
|
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Clicking a row does two separate things, and the second one is why the row is
|
|
277
|
+
* a button at all: mark it read, and go to what it is about.
|
|
278
|
+
*
|
|
279
|
+
* They are kept apart deliberately. Marking read is best-effort and reverts on
|
|
280
|
+
* failure; navigation must not wait on that round trip, and must still happen
|
|
281
|
+
* for a row that was ALREADY read — a person re-opening the bell to find the
|
|
282
|
+
* order they were told about is the ordinary case, and the old early-return on
|
|
283
|
+
* `hasRead` would have sent them nowhere.
|
|
284
|
+
*/
|
|
272
285
|
async function openNotification(item: Record<string, any>) {
|
|
286
|
+
markRead(item);
|
|
287
|
+
await goToSubject(item);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function markRead(item: Record<string, any>) {
|
|
273
291
|
if (item.hasRead) return;
|
|
274
292
|
// Marked locally first: waiting on a round trip to move the dot reads as a dead control.
|
|
275
293
|
item.hasRead = true;
|
|
276
294
|
unread.value = Math.max(0, unread.value - 1);
|
|
277
|
-
|
|
278
|
-
await markAsRead(String(item._id), userId.value);
|
|
279
|
-
} catch {
|
|
295
|
+
markAsRead(String(item._id), userId.value).catch(() => {
|
|
280
296
|
item.hasRead = false;
|
|
281
297
|
unread.value += 1;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* `hasRoute` is the whole reason an org-app route name may live in the shared
|
|
303
|
+
* layer: the ten apps that have no order queue simply do not match it, and the
|
|
304
|
+
* click there stays what it always was.
|
|
305
|
+
*/
|
|
306
|
+
async function goToSubject(item: Record<string, any>) {
|
|
307
|
+
const target = notificationTarget(item as any, {
|
|
308
|
+
organization: String(route.params?.organization ?? ""),
|
|
309
|
+
});
|
|
310
|
+
if (!target) return;
|
|
311
|
+
if (typeof router.hasRoute !== "function" || !router.hasRoute(target.name)) return;
|
|
312
|
+
|
|
313
|
+
open.value = false;
|
|
314
|
+
try {
|
|
315
|
+
await router.push(target);
|
|
316
|
+
} catch {
|
|
317
|
+
// A cancelled or duplicate navigation is not worth an error in the top bar.
|
|
282
318
|
}
|
|
283
319
|
}
|
|
284
320
|
|
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.28.1-staging.
|
|
5
|
+
"version": "4.28.1-staging.357",
|
|
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,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a notification takes you when you click it.
|
|
3
|
+
*
|
|
4
|
+
* Kept free of Vue and Nuxt so the decision is unit-tested directly
|
|
5
|
+
* (`utils/notification-target.test.ts`); `NotificationBell.vue` does nothing
|
|
6
|
+
* with the answer but hand it to the router.
|
|
7
|
+
*
|
|
8
|
+
* WHY THE BELL NEEDED THIS AT ALL
|
|
9
|
+
* The bell has drawn rows since it shipped and clicking one only ever marked it
|
|
10
|
+
* read. For an expiring document that is survivable — the row says what it says.
|
|
11
|
+
* For a marketplace order it is not: "A new marketplace order has reached your
|
|
12
|
+
* company" is a message whose entire point is the order, and a vendor who taps
|
|
13
|
+
* the push on their phone and then goes looking in the org app had nowhere to
|
|
14
|
+
* land.
|
|
15
|
+
*
|
|
16
|
+
* WHAT THE ROW ACTUALLY CARRIES
|
|
17
|
+
* `iservice365-API-core`'s marketplace senders store `module` as the display
|
|
18
|
+
* tag and the record's id in `params.id` — for the vendor rows that id is the
|
|
19
|
+
* SUB-order, which is the same id the vendor's order queue routes on. `screen`
|
|
20
|
+
* is deliberately empty on those rows (it is a mobile deep-link path, and no
|
|
21
|
+
* mobile screen exists), so the module is what we route on, not `screen`.
|
|
22
|
+
*
|
|
23
|
+
* WHY AN APP-SPECIFIC ROUTE NAME LIVES IN THE SHARED LAYER
|
|
24
|
+
* Eleven web apps render this bell and only `iservice365-web-app-org` has an
|
|
25
|
+
* order queue. Rather than make eleven apps configure a map, the name is
|
|
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.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** Only the fields a destination is decided from. */
|
|
32
|
+
export type TTargetRow = {
|
|
33
|
+
module?: string;
|
|
34
|
+
params?: { id?: string } | null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** What the surrounding app knows that the stored row does not. */
|
|
38
|
+
export type TTargetContext = {
|
|
39
|
+
/** The organization in the current URL. Org routes are all nested under it. */
|
|
40
|
+
organization?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type TNotificationTarget = {
|
|
44
|
+
name: string;
|
|
45
|
+
params: Record<string, string>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Nuxt's generated names for `pages/org/[organization]/marketplace/orders/`. */
|
|
49
|
+
export const ORDER_QUEUE_ROUTE = "org-organization-marketplace-orders";
|
|
50
|
+
export const ORDER_DETAIL_ROUTE = "org-organization-marketplace-orders-id";
|
|
51
|
+
|
|
52
|
+
/** The stored `module` tag on a row sent to a vendor's staff. */
|
|
53
|
+
export const VENDOR_ORDER_MODULE = "marketplace-vendor-order";
|
|
54
|
+
|
|
55
|
+
export function notificationTarget(
|
|
56
|
+
item: TTargetRow | null | undefined,
|
|
57
|
+
context: TTargetContext = {},
|
|
58
|
+
): TNotificationTarget | null {
|
|
59
|
+
const organization = String(context.organization ?? "").trim();
|
|
60
|
+
|
|
61
|
+
if (String(item?.module ?? "") !== VENDOR_ORDER_MODULE) return null;
|
|
62
|
+
|
|
63
|
+
// Every order route is nested under the organization. Without one there is no
|
|
64
|
+
// URL to build, and guessing an organization for somebody who belongs to
|
|
65
|
+
// several is worse than leaving the click as it was.
|
|
66
|
+
if (!organization) return null;
|
|
67
|
+
|
|
68
|
+
const id = String(item?.params?.id ?? "").trim();
|
|
69
|
+
|
|
70
|
+
// No id — an older row, or one whose params were dropped — still has an
|
|
71
|
+
// honest destination: the queue the order is sitting in.
|
|
72
|
+
if (!id) return { name: ORDER_QUEUE_ROUTE, params: { organization } };
|
|
73
|
+
|
|
74
|
+
return { name: ORDER_DETAIL_ROUTE, params: { organization, id } };
|
|
75
|
+
}
|