@burdenoff/microfe-notification 2026.1023.1 → 2026.1029.1
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.
- package/dist/components/NotificationBell.js +35 -34
- package/dist/components/NotificationBell.js.map +1 -1
- package/dist/components/NotificationCard.js +9 -9
- package/dist/graphql/global-client.js +43 -28
- package/dist/graphql/global-client.js.map +1 -1
- package/dist/hooks/useNotificationTopics.js +40 -38
- package/dist/hooks/useNotificationTopics.js.map +1 -1
- package/dist/hooks/useNotifications.js +140 -129
- package/dist/hooks/useNotifications.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/pages/CreateNotificationPage.js +5 -5
- package/dist/pages/NotificationCenterPage.js +5 -5
- package/dist/pages/NotificationPreferencesPage.js +43 -39
- package/dist/pages/NotificationPreferencesPage.js.map +1 -1
- package/dist/pages/NotificationTopicsPage.js +35 -31
- package/dist/pages/NotificationTopicsPage.js.map +1 -1
- package/dist/pages/TemplateEditorPage.js +5 -5
- package/package.json +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useNotification as e } from "../providers/NotificationProvider.js";
|
|
2
|
-
import {
|
|
3
|
-
import { useNotificationStore as
|
|
4
|
-
import { ArchiveNotificationDocument as
|
|
5
|
-
import { useCallback as
|
|
2
|
+
import { USER_NOTIFICATION_CONTEXT as t, getGlobalNotificationClient as n } from "../graphql/global-client.js";
|
|
3
|
+
import { useNotificationStore as r } from "../store/notificationStore.js";
|
|
4
|
+
import { ArchiveNotificationDocument as i, ArchiveNotificationsDocument as a, GetMyUnreadNotificationCountDocument as o, GetNotificationsDocument as s, MarkAllMyNotificationsAsReadDocument as c, MarkNotificationAsReadDocument as l, NotificationReceivedDocument as u, RecordNotificationActionDocument as d, UnarchiveNotificationDocument as f, UnreadCountUpdatedDocument as p } from "../generated/global-operations.js";
|
|
5
|
+
import { useCallback as m, useEffect as h, useMemo as g, useState as _ } from "react";
|
|
6
6
|
//#region src/hooks/useNotifications.ts
|
|
7
|
-
function
|
|
7
|
+
function v(e) {
|
|
8
8
|
return {
|
|
9
9
|
id: e.id,
|
|
10
|
-
type:
|
|
11
|
-
priority:
|
|
10
|
+
type: y(e.type),
|
|
11
|
+
priority: b(e.priority),
|
|
12
12
|
title: e.title,
|
|
13
13
|
body: e.message,
|
|
14
14
|
actionUrl: e.redirectUrl ?? void 0,
|
|
@@ -45,13 +45,13 @@ function _(e) {
|
|
|
45
45
|
timezone: e.scheduledNotification.timezone ?? void 0
|
|
46
46
|
} : void 0,
|
|
47
47
|
sentAt: e.sentAt ?? void 0,
|
|
48
|
-
status:
|
|
48
|
+
status: x(e.status),
|
|
49
49
|
readAt: e.readAt ?? void 0,
|
|
50
50
|
createdAt: e.createdAt,
|
|
51
51
|
channels: [{
|
|
52
52
|
id: e.id,
|
|
53
53
|
channel: e.channel,
|
|
54
|
-
status:
|
|
54
|
+
status: x(e.status),
|
|
55
55
|
sentAt: e.sentAt ?? void 0,
|
|
56
56
|
deliveredAt: e.deliveredAt ?? void 0,
|
|
57
57
|
failedAt: e.failedAt ?? void 0,
|
|
@@ -63,12 +63,12 @@ function _(e) {
|
|
|
63
63
|
id: e.topic.id,
|
|
64
64
|
name: e.topic.name,
|
|
65
65
|
slug: e.topic.slug,
|
|
66
|
-
type:
|
|
66
|
+
type: y(e.topic.type)
|
|
67
67
|
} : void 0,
|
|
68
68
|
topicId: e.topicId ?? void 0
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
function
|
|
71
|
+
function y(e) {
|
|
72
72
|
return {
|
|
73
73
|
SYSTEM: "SYSTEM",
|
|
74
74
|
TRANSACTIONAL: "TRANSACTIONAL",
|
|
@@ -76,7 +76,7 @@ function v(e) {
|
|
|
76
76
|
ALERT: "ALERT"
|
|
77
77
|
}[e] || "SYSTEM";
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function b(e) {
|
|
80
80
|
return {
|
|
81
81
|
LOW: "LOW",
|
|
82
82
|
MEDIUM: "NORMAL",
|
|
@@ -84,7 +84,7 @@ function y(e) {
|
|
|
84
84
|
URGENT: "URGENT"
|
|
85
85
|
}[e] || "NORMAL";
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function x(e) {
|
|
88
88
|
return {
|
|
89
89
|
DRAFT: "PENDING",
|
|
90
90
|
PENDING: "PENDING",
|
|
@@ -98,7 +98,7 @@ function b(e) {
|
|
|
98
98
|
EXPIRED: "ARCHIVED"
|
|
99
99
|
}[e] || "PENDING";
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function S(e) {
|
|
102
102
|
let t = {};
|
|
103
103
|
return e.type !== "ALL" && (t.type = {
|
|
104
104
|
SYSTEM: "SYSTEM",
|
|
@@ -114,7 +114,7 @@ function x(e) {
|
|
|
114
114
|
URGENT: "URGENT"
|
|
115
115
|
}[e.priority] || e.priority), e.isRead !== null && e.isRead !== void 0 && (t.isRead = e.isRead), e.topicId && (t.topicId = e.topicId), e.channel && e.channel !== "ALL" && (t.channel = e.channel), e.archived !== null && e.archived !== void 0 && (t.archived = e.archived), e.search && (t.search = e.search), e.dateRange.start && (t.startDate = e.dateRange.start.toISOString()), e.dateRange.end && (t.endDate = e.dateRange.end.toISOString()), Object.keys(t).length > 0 ? t : void 0;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function C(e, t) {
|
|
118
118
|
return t ? {
|
|
119
119
|
...e,
|
|
120
120
|
...t,
|
|
@@ -124,180 +124,191 @@ function S(e, t) {
|
|
|
124
124
|
}
|
|
125
125
|
} : e;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
let { authToken:
|
|
129
|
-
|
|
130
|
-
let e = window.setTimeout(() =>
|
|
127
|
+
function w(y = {}) {
|
|
128
|
+
let { authToken: b, apiGatewayUrl: x, currentUser: w, eventBus: T } = e(), { notificationFilter: E, updateNotificationFilter: D, resetNotificationFilter: O, unreadCount: k, setUnreadCount: A, setIsLoadingNotifications: j } = r(), [M, N] = _([]), [P, F] = _(null), [I, L] = _(!1), [R, z] = _(null), [B, V] = _(!1), [H, U] = _(0), [W, G] = _(0), K = g(() => C(E, y.baseFilter), [E, y.baseFilter]), [q, J] = _(K);
|
|
129
|
+
h(() => {
|
|
130
|
+
let e = window.setTimeout(() => J(K), 250);
|
|
131
131
|
return () => window.clearTimeout(e);
|
|
132
|
-
}, [
|
|
133
|
-
let
|
|
134
|
-
|
|
132
|
+
}, [K]);
|
|
133
|
+
let Y = m(() => n(x ?? void 0, b ?? void 0), [x, b]), X = m(async () => {
|
|
134
|
+
L(!0), j(!0), z(null);
|
|
135
135
|
try {
|
|
136
|
-
let e = await
|
|
137
|
-
|
|
136
|
+
let e = await Y().query({
|
|
137
|
+
context: t,
|
|
138
|
+
query: s,
|
|
138
139
|
variables: {
|
|
139
|
-
filter:
|
|
140
|
+
filter: S(q),
|
|
140
141
|
limit: 50,
|
|
141
142
|
offset: 0
|
|
142
143
|
},
|
|
143
144
|
fetchPolicy: "network-only"
|
|
144
145
|
});
|
|
145
|
-
e.data?.notifications && (
|
|
146
|
+
e.data?.notifications && (N(e.data.notifications.items.map(v)), U(e.data.notifications.total), V(e.data.notifications.hasMore), G(50));
|
|
146
147
|
} catch (e) {
|
|
147
148
|
let t = e instanceof Error ? e.message : "Failed to fetch notifications";
|
|
148
|
-
console.error("[useNotifications] Failed to fetch notifications:", e),
|
|
149
|
+
console.error("[useNotifications] Failed to fetch notifications:", e), z(t);
|
|
149
150
|
} finally {
|
|
150
|
-
|
|
151
|
+
L(!1), j(!1);
|
|
151
152
|
}
|
|
152
153
|
}, [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
]),
|
|
154
|
+
q,
|
|
155
|
+
Y,
|
|
156
|
+
j
|
|
157
|
+
]), Z = m(async () => {
|
|
157
158
|
try {
|
|
158
|
-
let e = await
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
let e = await Y().query({
|
|
160
|
+
context: t,
|
|
161
|
+
query: o,
|
|
162
|
+
variables: { filter: y.unreadFilter || { channel: "IN_APP" } },
|
|
161
163
|
fetchPolicy: "network-only"
|
|
162
164
|
});
|
|
163
|
-
e.data &&
|
|
165
|
+
e.data && A(e.data.myUnreadNotificationCount);
|
|
164
166
|
} catch (e) {
|
|
165
167
|
console.error("[useNotifications] Failed to fetch unread count:", e);
|
|
166
168
|
}
|
|
167
169
|
}, [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
]),
|
|
172
|
-
if (
|
|
173
|
-
let e = await
|
|
174
|
-
|
|
170
|
+
Y,
|
|
171
|
+
y.unreadFilter,
|
|
172
|
+
A
|
|
173
|
+
]), Q = m(async () => {
|
|
174
|
+
if (B) try {
|
|
175
|
+
let e = await Y().query({
|
|
176
|
+
context: t,
|
|
177
|
+
query: s,
|
|
175
178
|
variables: {
|
|
176
|
-
filter:
|
|
179
|
+
filter: S(q),
|
|
177
180
|
limit: 50,
|
|
178
|
-
offset:
|
|
181
|
+
offset: W
|
|
179
182
|
},
|
|
180
183
|
fetchPolicy: "network-only"
|
|
181
184
|
});
|
|
182
185
|
if (e.data?.notifications) {
|
|
183
|
-
let t = e.data.notifications.items.map(
|
|
184
|
-
|
|
186
|
+
let t = e.data.notifications.items.map(v);
|
|
187
|
+
N((e) => [...e, ...t]), V(e.data.notifications.hasMore), G((e) => e + 50);
|
|
185
188
|
}
|
|
186
189
|
} catch (e) {
|
|
187
190
|
let t = e instanceof Error ? e.message : "Failed to load more notifications";
|
|
188
|
-
console.error("[useNotifications] Failed to load more:", e),
|
|
191
|
+
console.error("[useNotifications] Failed to load more:", e), z(t);
|
|
189
192
|
}
|
|
190
193
|
}, [
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
]),
|
|
194
|
+
q,
|
|
195
|
+
Y,
|
|
196
|
+
B,
|
|
197
|
+
W
|
|
198
|
+
]), $ = m(async (e) => {
|
|
196
199
|
try {
|
|
197
|
-
await
|
|
198
|
-
|
|
200
|
+
await Y().mutate({
|
|
201
|
+
context: t,
|
|
202
|
+
mutation: l,
|
|
199
203
|
variables: { id: e }
|
|
200
|
-
}),
|
|
204
|
+
}), N((t) => t.map((t) => t.id === e ? {
|
|
201
205
|
...t,
|
|
202
206
|
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
203
|
-
} : t)),
|
|
207
|
+
} : t)), A(Math.max(0, k - 1));
|
|
204
208
|
} catch (e) {
|
|
205
|
-
console.error("[useNotifications] Failed to mark as read:", e),
|
|
209
|
+
console.error("[useNotifications] Failed to mark as read:", e), z("Failed to mark notification as read");
|
|
206
210
|
}
|
|
207
211
|
}, [
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
]),
|
|
212
|
+
Y,
|
|
213
|
+
A,
|
|
214
|
+
k
|
|
215
|
+
]), ee = m(async () => {
|
|
212
216
|
try {
|
|
213
|
-
await
|
|
217
|
+
await Y().mutate({
|
|
218
|
+
context: t,
|
|
219
|
+
mutation: c
|
|
220
|
+
}), N((e) => e.map((e) => ({
|
|
214
221
|
...e,
|
|
215
222
|
readAt: e.readAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
216
|
-
}))),
|
|
223
|
+
}))), A(0);
|
|
217
224
|
} catch (e) {
|
|
218
|
-
console.error("[useNotifications] Failed to mark all as read:", e),
|
|
225
|
+
console.error("[useNotifications] Failed to mark all as read:", e), z("Failed to mark all notifications as read");
|
|
219
226
|
}
|
|
220
|
-
}, [
|
|
227
|
+
}, [Y, A]), te = m(async (e) => {
|
|
221
228
|
try {
|
|
222
|
-
await
|
|
223
|
-
|
|
229
|
+
await Y().mutate({
|
|
230
|
+
context: t,
|
|
231
|
+
mutation: i,
|
|
224
232
|
variables: { id: e }
|
|
225
|
-
}),
|
|
233
|
+
}), N((t) => t.map((t) => t.id === e ? {
|
|
226
234
|
...t,
|
|
227
235
|
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
228
236
|
} : t));
|
|
229
237
|
} catch (e) {
|
|
230
|
-
console.error("[useNotifications] Failed to archive notification:", e),
|
|
238
|
+
console.error("[useNotifications] Failed to archive notification:", e), z("Failed to archive notification");
|
|
231
239
|
}
|
|
232
|
-
}, [
|
|
240
|
+
}, [Y]), ne = m(async (e) => {
|
|
233
241
|
try {
|
|
234
|
-
await
|
|
235
|
-
|
|
242
|
+
await Y().mutate({
|
|
243
|
+
context: t,
|
|
244
|
+
mutation: a,
|
|
236
245
|
variables: { notificationIds: e }
|
|
237
246
|
});
|
|
238
|
-
let
|
|
239
|
-
|
|
247
|
+
let n = new Set(e);
|
|
248
|
+
N((e) => e.map((e) => n.has(e.id) ? {
|
|
240
249
|
...e,
|
|
241
250
|
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
242
251
|
} : e));
|
|
243
252
|
} catch (e) {
|
|
244
|
-
console.error("[useNotifications] Failed to bulk archive:", e),
|
|
253
|
+
console.error("[useNotifications] Failed to bulk archive:", e), z("Failed to archive notifications");
|
|
245
254
|
}
|
|
246
|
-
}, [
|
|
255
|
+
}, [Y]), re = m(async (e) => {
|
|
247
256
|
try {
|
|
248
|
-
await
|
|
249
|
-
|
|
257
|
+
await Y().mutate({
|
|
258
|
+
context: t,
|
|
259
|
+
mutation: f,
|
|
250
260
|
variables: { id: e }
|
|
251
|
-
}),
|
|
261
|
+
}), N((t) => t.map((t) => t.id === e ? {
|
|
252
262
|
...t,
|
|
253
263
|
archivedAt: void 0
|
|
254
264
|
} : t));
|
|
255
265
|
} catch (e) {
|
|
256
|
-
console.error("[useNotifications] Failed to unarchive notification:", e),
|
|
266
|
+
console.error("[useNotifications] Failed to unarchive notification:", e), z("Failed to restore notification");
|
|
257
267
|
}
|
|
258
|
-
}, [
|
|
268
|
+
}, [Y]), ie = m(async (e, n) => {
|
|
259
269
|
try {
|
|
260
|
-
await
|
|
261
|
-
|
|
270
|
+
await Y().mutate({
|
|
271
|
+
context: t,
|
|
272
|
+
mutation: d,
|
|
262
273
|
variables: { input: {
|
|
263
274
|
notificationId: e,
|
|
264
|
-
actionId:
|
|
275
|
+
actionId: n
|
|
265
276
|
} }
|
|
266
|
-
}),
|
|
277
|
+
}), N((t) => t.map((t) => t.id === e ? {
|
|
267
278
|
...t,
|
|
268
279
|
clickedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
269
280
|
readAt: t.readAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
270
281
|
} : t));
|
|
271
282
|
} catch (e) {
|
|
272
|
-
console.error("[useNotifications] Failed to record notification action:", e),
|
|
283
|
+
console.error("[useNotifications] Failed to record notification action:", e), z("Failed to record notification action");
|
|
273
284
|
}
|
|
274
|
-
}, [
|
|
275
|
-
return
|
|
276
|
-
Y();
|
|
277
|
-
}, [Y]), m(() => {
|
|
285
|
+
}, [Y]);
|
|
286
|
+
return h(() => {
|
|
278
287
|
X();
|
|
279
|
-
}, [X]),
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
288
|
+
}, [X]), h(() => {
|
|
289
|
+
Z();
|
|
290
|
+
}, [Z]), h(() => {
|
|
291
|
+
if (!w?.id) return;
|
|
292
|
+
let e = Y(), t = e.subscribe({
|
|
293
|
+
query: u,
|
|
294
|
+
variables: { userId: w.id }
|
|
284
295
|
}).subscribe({
|
|
285
296
|
next: (e) => {
|
|
286
297
|
let t = e.data?.notificationReceived;
|
|
287
298
|
if (!t) return;
|
|
288
|
-
let n =
|
|
289
|
-
|
|
299
|
+
let n = v(t);
|
|
300
|
+
N((e) => [n, ...e.filter((e) => e.id !== n.id)]), T?.emit("notification:received", { notification: n });
|
|
290
301
|
},
|
|
291
302
|
error: (e) => {
|
|
292
303
|
console.error("[useNotifications] Notification subscription failed:", e);
|
|
293
304
|
}
|
|
294
305
|
}), n = e.subscribe({
|
|
295
|
-
query:
|
|
296
|
-
variables: { userId:
|
|
306
|
+
query: p,
|
|
307
|
+
variables: { userId: w.id }
|
|
297
308
|
}).subscribe({
|
|
298
309
|
next: (e) => {
|
|
299
310
|
let t = e.data?.unreadCountUpdated;
|
|
300
|
-
typeof t == "number" && (
|
|
311
|
+
typeof t == "number" && (A(t), T?.emit("notification:unread-count-updated", { unreadCount: t }));
|
|
301
312
|
},
|
|
302
313
|
error: (e) => {
|
|
303
314
|
console.error("[useNotifications] Unread count subscription failed:", e);
|
|
@@ -307,39 +318,39 @@ function C(v = {}) {
|
|
|
307
318
|
t.unsubscribe(), n.unsubscribe();
|
|
308
319
|
};
|
|
309
320
|
}, [
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
]),
|
|
321
|
+
w?.id,
|
|
322
|
+
T,
|
|
323
|
+
Y,
|
|
324
|
+
A
|
|
325
|
+
]), h(() => {
|
|
315
326
|
let e = () => {
|
|
316
|
-
document.visibilityState === "visible" && (
|
|
327
|
+
document.visibilityState === "visible" && (X(), Z());
|
|
317
328
|
};
|
|
318
329
|
return document.addEventListener("visibilitychange", e), () => document.removeEventListener("visibilitychange", e);
|
|
319
|
-
}, [
|
|
320
|
-
notifications:
|
|
321
|
-
allNotifications:
|
|
322
|
-
unreadCount:
|
|
323
|
-
selectedNotification:
|
|
324
|
-
notificationFilter:
|
|
325
|
-
isLoading:
|
|
326
|
-
error:
|
|
327
|
-
hasMore:
|
|
328
|
-
total:
|
|
329
|
-
markAsRead:
|
|
330
|
-
markAllAsRead:
|
|
331
|
-
archiveNotification:
|
|
332
|
-
bulkArchive:
|
|
333
|
-
unarchiveNotification:
|
|
334
|
-
recordAction:
|
|
335
|
-
setSelectedNotification:
|
|
336
|
-
updateFilter:
|
|
337
|
-
resetFilter:
|
|
338
|
-
refetch:
|
|
339
|
-
loadMore:
|
|
330
|
+
}, [X, Z]), {
|
|
331
|
+
notifications: g(() => M.filter((e) => e.deliveryStatus === "UNSUBSCRIBED" || e.status === "ARCHIVED" && !e.archivedAt ? !1 : K.archived === !0 ? !!e.archivedAt : K.archived === !1 ? !e.archivedAt : !0), [K.archived, M]),
|
|
332
|
+
allNotifications: M,
|
|
333
|
+
unreadCount: k,
|
|
334
|
+
selectedNotification: P,
|
|
335
|
+
notificationFilter: K,
|
|
336
|
+
isLoading: I,
|
|
337
|
+
error: R,
|
|
338
|
+
hasMore: B,
|
|
339
|
+
total: H,
|
|
340
|
+
markAsRead: $,
|
|
341
|
+
markAllAsRead: ee,
|
|
342
|
+
archiveNotification: te,
|
|
343
|
+
bulkArchive: ne,
|
|
344
|
+
unarchiveNotification: re,
|
|
345
|
+
recordAction: ie,
|
|
346
|
+
setSelectedNotification: F,
|
|
347
|
+
updateFilter: D,
|
|
348
|
+
resetFilter: O,
|
|
349
|
+
refetch: X,
|
|
350
|
+
loadMore: Q
|
|
340
351
|
};
|
|
341
352
|
}
|
|
342
353
|
//#endregion
|
|
343
|
-
export {
|
|
354
|
+
export { w as useNotifications };
|
|
344
355
|
|
|
345
356
|
//# sourceMappingURL=useNotifications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.js","names":[],"sources":["../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useCallback, useEffect, useMemo } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport { useNotificationStore } from '../store/notificationStore';\nimport type { Notification, NotificationFilter } from '../types';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationsQuery,\n GetMyUnreadNotificationCountQuery,\n NotificationFieldsFragment,\n NotificationReceivedSubscription,\n UnreadCountUpdatedSubscription,\n} from '../generated/global-operations';\n\n// ---------------------------------------------------------------------------\n// GraphQL Operations — using generated Document nodes from global-operations\n// ---------------------------------------------------------------------------\n\n/**\n * Backend Notification item type derived from the generated query\n */\ntype BackendNotification = NotificationFieldsFragment;\n\ninterface UseNotificationsOptions {\n baseFilter?: Partial<NotificationFilter>;\n unreadFilter?: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Mapping helpers — backend → MFE types\n// ---------------------------------------------------------------------------\n\nfunction mapBackendToMfeNotification(n: BackendNotification): Notification {\n return {\n id: n.id,\n type: mapNotificationType(n.type),\n priority: mapPriority(n.priority),\n title: n.title,\n body: n.message,\n actionUrl: n.redirectUrl ?? undefined,\n actions: (n.actions || []).map((action) => ({\n id: action.id,\n label: action.label,\n url: action.url,\n style: action.style ?? undefined,\n actionType: action.actionType ?? undefined,\n metadata: action.metadata ?? undefined,\n })),\n appName: n.appName ?? undefined,\n archivedAt: n.archivedAt ?? undefined,\n channel: n.channel as Notification['channel'],\n clickedAt: n.clickedAt ?? undefined,\n deliveredAt: n.deliveredAt ?? undefined,\n deliveryStatus: n.deliveryStatus ?? undefined,\n htmlBody: n.htmlMessage ?? undefined,\n media: (n.media || []).map((item) => ({\n url: item.url,\n label: item.label ?? undefined,\n kind: item.kind ?? undefined,\n contentType: item.contentType ?? undefined,\n thumbnailUrl: item.thumbnailUrl ?? undefined,\n })),\n openedAt: n.openedAt ?? undefined,\n recipientEmail: n.recipientEmail ?? undefined,\n recipientPhone: n.recipientPhone ?? undefined,\n scheduledFor: n.scheduledFor ?? undefined,\n scheduledNotification: n.scheduledNotification\n ? {\n id: n.scheduledNotification.id,\n scheduledFor: n.scheduledNotification.scheduledFor,\n status: n.scheduledNotification.status,\n timezone: n.scheduledNotification.timezone ?? undefined,\n }\n : undefined,\n sentAt: n.sentAt ?? undefined,\n status: mapStatus(n.status),\n readAt: n.readAt ?? undefined,\n createdAt: n.createdAt,\n channels: [\n {\n id: n.id,\n channel: n.channel as Notification['channel'],\n status: mapStatus(n.status),\n sentAt: n.sentAt ?? undefined,\n deliveredAt: n.deliveredAt ?? undefined,\n failedAt: n.failedAt ?? undefined,\n errorCode: n.errorCode ?? undefined,\n errorMessage: n.errorMessage ?? undefined,\n },\n ],\n metadata: n.metadata ?? undefined,\n topic: n.topic\n ? {\n id: n.topic.id,\n name: n.topic.name,\n slug: n.topic.slug,\n type: mapNotificationType(n.topic.type),\n }\n : undefined,\n topicId: n.topicId ?? undefined,\n };\n}\n\nfunction mapNotificationType(t: string) {\n const map: Record<string, Notification['type']> = {\n SYSTEM: 'SYSTEM',\n TRANSACTIONAL: 'TRANSACTIONAL',\n MARKETING: 'MARKETING',\n ALERT: 'ALERT',\n };\n return map[t] || 'SYSTEM';\n}\n\nfunction mapPriority(p: string) {\n const map: Record<string, Notification['priority']> = {\n LOW: 'LOW',\n MEDIUM: 'NORMAL',\n HIGH: 'HIGH',\n URGENT: 'URGENT',\n };\n return map[p] || 'NORMAL';\n}\n\nfunction mapStatus(s: string) {\n const map: Record<string, Notification['status']> = {\n DRAFT: 'PENDING',\n PENDING: 'PENDING',\n SCHEDULED: 'PENDING',\n TRIGGERED: 'SENT',\n SENT: 'SENT',\n DELIVERED: 'DELIVERED',\n READ: 'DELIVERED',\n FAILED: 'FAILED',\n CANCELLED: 'ARCHIVED',\n EXPIRED: 'ARCHIVED',\n };\n return map[s] || 'PENDING';\n}\n\n// ---------------------------------------------------------------------------\n// Build the backend filter from the MFE NotificationFilter shape\n// ---------------------------------------------------------------------------\n\nfunction buildBackendFilter(filter: NotificationFilter) {\n const backend: Record<string, unknown> = {};\n\n // Type filter — map MFE type names to backend enum\n if (filter.type !== 'ALL') {\n const typeMap: Record<string, string> = {\n SYSTEM: 'SYSTEM',\n ACTIVITY: 'TRANSACTIONAL',\n BILLING: 'TRANSACTIONAL',\n SECURITY: 'ALERT',\n SOCIAL: 'MARKETING',\n REMINDER: 'SYSTEM',\n };\n backend.type = typeMap[filter.type] || filter.type;\n }\n\n // Priority filter\n if (filter.priority !== 'ALL') {\n const prioMap: Record<string, string> = {\n LOW: 'LOW',\n NORMAL: 'MEDIUM',\n HIGH: 'HIGH',\n URGENT: 'URGENT',\n };\n backend.priority = prioMap[filter.priority] || filter.priority;\n }\n\n // Read/unread filter — coerce null to undefined\n if (filter.isRead !== null && filter.isRead !== undefined) {\n backend.isRead = filter.isRead;\n }\n\n if (filter.topicId) {\n backend.topicId = filter.topicId;\n }\n\n if (filter.channel && filter.channel !== 'ALL') {\n backend.channel = filter.channel;\n }\n\n if (filter.archived !== null && filter.archived !== undefined) {\n backend.archived = filter.archived;\n }\n\n if (filter.search) {\n backend.search = filter.search;\n }\n\n // Date range\n if (filter.dateRange.start) {\n backend.startDate = filter.dateRange.start.toISOString();\n }\n if (filter.dateRange.end) {\n backend.endDate = filter.dateRange.end.toISOString();\n }\n\n return Object.keys(backend).length > 0 ? backend : undefined;\n}\n\nfunction mergeNotificationFilter(\n filter: NotificationFilter,\n baseFilter?: Partial<NotificationFilter>\n): NotificationFilter {\n if (!baseFilter) return filter;\n\n return {\n ...filter,\n ...baseFilter,\n dateRange: {\n ...filter.dateRange,\n ...(baseFilter.dateRange || {}),\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Hook to manage notifications with real GraphQL backend integration.\n *\n * Uses the global Apollo client to query the notification service via the\n * public gateway (https://gw-global.local.burdenoff.com/global/graphql).\n *\n * @example\n * ```tsx\n * const { notifications, unreadCount, markAsRead } = useNotifications();\n * ```\n */\nexport function useNotifications(options: UseNotificationsOptions = {}) {\n const { authToken, apiGatewayUrl, currentUser, eventBus } = useNotification();\n const {\n notificationFilter,\n updateNotificationFilter,\n resetNotificationFilter,\n unreadCount,\n setUnreadCount: setStoreUnreadCount,\n setIsLoadingNotifications,\n } = useNotificationStore();\n\n const [notifications, setNotifications] = useState<Notification[]>([]);\n const [selectedNotification, setSelectedNotification] = useState<Notification | null>(null);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [total, setTotal] = useState(0);\n const [offset, setOffset] = useState(0);\n\n const LIMIT = 50;\n const effectiveFilter = useMemo(\n () => mergeNotificationFilter(notificationFilter, options.baseFilter),\n [notificationFilter, options.baseFilter]\n );\n const [debouncedFilter, setDebouncedFilter] = useState(effectiveFilter);\n\n useEffect(() => {\n const timeout = window.setTimeout(() => setDebouncedFilter(effectiveFilter), 250);\n return () => window.clearTimeout(timeout);\n }, [effectiveFilter]);\n\n // Client accessor — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // ---- Fetch notifications ------------------------------------------------\n\n const fetchNotifications = useCallback(async () => {\n setIsLoading(true);\n setIsLoadingNotifications(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationsQuery>({\n query: NotificationOps.GetNotificationsDocument,\n variables: {\n filter: buildBackendFilter(debouncedFilter),\n limit: LIMIT,\n offset: 0,\n },\n fetchPolicy: 'network-only',\n });\n\n if (result.data?.notifications) {\n const mapped = result.data.notifications.items.map(mapBackendToMfeNotification);\n setNotifications(mapped);\n setTotal(result.data.notifications.total);\n setHasMore(result.data.notifications.hasMore);\n setOffset(LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch notifications';\n console.error('[useNotifications] Failed to fetch notifications:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n setIsLoadingNotifications(false);\n }\n }, [debouncedFilter, getClient, setIsLoadingNotifications]);\n\n // ---- Fetch unread count -------------------------------------------------\n\n const fetchUnreadCount = useCallback(async () => {\n try {\n const client = getClient();\n const result = await client.query<GetMyUnreadNotificationCountQuery>({\n query: NotificationOps.GetMyUnreadNotificationCountDocument,\n variables: { filter: options.unreadFilter || { channel: 'IN_APP' } },\n fetchPolicy: 'network-only',\n });\n if (result.data) {\n setStoreUnreadCount(result.data.myUnreadNotificationCount);\n }\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to fetch unread count:', err);\n }\n }, [getClient, options.unreadFilter, setStoreUnreadCount]);\n\n // ---- Load more ----------------------------------------------------------\n\n const loadMore = useCallback(async () => {\n if (!hasMore) return;\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationsQuery>({\n query: NotificationOps.GetNotificationsDocument,\n variables: {\n filter: buildBackendFilter(debouncedFilter),\n limit: LIMIT,\n offset,\n },\n fetchPolicy: 'network-only',\n });\n\n if (result.data?.notifications) {\n const more = result.data.notifications.items.map(mapBackendToMfeNotification);\n setNotifications((prev) => [...prev, ...more]);\n setHasMore(result.data.notifications.hasMore);\n setOffset((prev) => prev + LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to load more notifications';\n console.error('[useNotifications] Failed to load more:', err);\n setError(message);\n }\n }, [debouncedFilter, getClient, hasMore, offset]);\n\n // ---- Mutations ----------------------------------------------------------\n\n const handleMarkAsRead = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.MarkNotificationAsReadDocument,\n variables: { id: notificationId },\n });\n // Optimistic: update local state\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId ? { ...n, readAt: new Date().toISOString() } : n\n )\n );\n setStoreUnreadCount(Math.max(0, unreadCount - 1));\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to mark as read:', err);\n setError('Failed to mark notification as read');\n }\n },\n [getClient, setStoreUnreadCount, unreadCount]\n );\n\n const handleMarkAllAsRead = useCallback(async () => {\n try {\n const client = getClient();\n await client.mutate({ mutation: NotificationOps.MarkAllMyNotificationsAsReadDocument });\n // Optimistic: update all local\n setNotifications((prev) =>\n prev.map((n) => ({ ...n, readAt: n.readAt || new Date().toISOString() }))\n );\n setStoreUnreadCount(0);\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to mark all as read:', err);\n setError('Failed to mark all notifications as read');\n }\n }, [getClient, setStoreUnreadCount]);\n\n const handleArchive = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.ArchiveNotificationDocument,\n variables: { id: notificationId },\n });\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId ? { ...n, archivedAt: new Date().toISOString() } : n\n )\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to archive notification:', err);\n setError('Failed to archive notification');\n }\n },\n [getClient]\n );\n\n const handleBulkArchive = useCallback(\n async (notificationIds: string[]) => {\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.ArchiveNotificationsDocument,\n variables: { notificationIds },\n });\n const idsSet = new Set(notificationIds);\n setNotifications((prev) =>\n prev.map((n) => (idsSet.has(n.id) ? { ...n, archivedAt: new Date().toISOString() } : n))\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to bulk archive:', err);\n setError('Failed to archive notifications');\n }\n },\n [getClient]\n );\n\n const handleUnarchive = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.UnarchiveNotificationDocument,\n variables: { id: notificationId },\n });\n\n setNotifications((prev) =>\n prev.map((n) => (n.id === notificationId ? { ...n, archivedAt: undefined } : n))\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to unarchive notification:', err);\n setError('Failed to restore notification');\n }\n },\n [getClient]\n );\n\n const handleRecordAction = useCallback(\n async (notificationId: string, actionId?: string) => {\n try {\n const client = getClient();\n await client.mutate({\n mutation: NotificationOps.RecordNotificationActionDocument,\n variables: { input: { notificationId, actionId } },\n });\n\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId\n ? {\n ...n,\n clickedAt: new Date().toISOString(),\n readAt: n.readAt || new Date().toISOString(),\n }\n : n\n )\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to record notification action:', err);\n setError('Failed to record notification action');\n }\n },\n [getClient]\n );\n\n // ---- Initial fetch on mount + when filter changes -----------------------\n\n useEffect(() => {\n fetchNotifications();\n }, [fetchNotifications]);\n\n useEffect(() => {\n fetchUnreadCount();\n }, [fetchUnreadCount]);\n\n // ---- Live notification subscriptions ------------------------------------\n\n useEffect(() => {\n if (!currentUser?.id) return undefined;\n\n const client = getClient();\n const notificationSubscription = client\n .subscribe<NotificationReceivedSubscription>({\n query: NotificationOps.NotificationReceivedDocument,\n variables: { userId: currentUser.id },\n })\n .subscribe({\n next: (result) => {\n const notification = result.data?.notificationReceived;\n if (!notification) return;\n const mapped = mapBackendToMfeNotification(notification);\n setNotifications((prev) => [mapped, ...prev.filter((item) => item.id !== mapped.id)]);\n eventBus?.emit('notification:received', { notification: mapped });\n },\n error: (err) => {\n console.error('[useNotifications] Notification subscription failed:', err);\n },\n });\n\n const unreadSubscription = client\n .subscribe<UnreadCountUpdatedSubscription>({\n query: NotificationOps.UnreadCountUpdatedDocument,\n variables: { userId: currentUser.id },\n })\n .subscribe({\n next: (result) => {\n const nextCount = result.data?.unreadCountUpdated;\n if (typeof nextCount === 'number') {\n setStoreUnreadCount(nextCount);\n eventBus?.emit('notification:unread-count-updated', { unreadCount: nextCount });\n }\n },\n error: (err) => {\n console.error('[useNotifications] Unread count subscription failed:', err);\n },\n });\n\n return () => {\n notificationSubscription.unsubscribe();\n unreadSubscription.unsubscribe();\n };\n }, [currentUser?.id, eventBus, getClient, setStoreUnreadCount]);\n\n useEffect(() => {\n const handleVisibilityChange = () => {\n if (document.visibilityState === 'visible') {\n fetchNotifications();\n fetchUnreadCount();\n }\n };\n\n document.addEventListener('visibilitychange', handleVisibilityChange);\n return () => document.removeEventListener('visibilitychange', handleVisibilityChange);\n }, [fetchNotifications, fetchUnreadCount]);\n\n const visibleNotifications = useMemo(\n () =>\n notifications.filter((notification) => {\n if (notification.deliveryStatus === 'UNSUBSCRIBED') {\n return false;\n }\n\n if (notification.status === 'ARCHIVED' && !notification.archivedAt) {\n return false;\n }\n\n if (effectiveFilter.archived === true) {\n return Boolean(notification.archivedAt);\n }\n\n if (effectiveFilter.archived === false) {\n return !notification.archivedAt;\n }\n\n return true;\n }),\n [effectiveFilter.archived, notifications]\n );\n\n return {\n notifications: visibleNotifications,\n allNotifications: notifications,\n unreadCount,\n selectedNotification,\n notificationFilter: effectiveFilter,\n isLoading,\n error,\n hasMore,\n total,\n markAsRead: handleMarkAsRead,\n markAllAsRead: handleMarkAllAsRead,\n archiveNotification: handleArchive,\n bulkArchive: handleBulkArchive,\n unarchiveNotification: handleUnarchive,\n recordAction: handleRecordAction,\n setSelectedNotification,\n updateFilter: updateNotificationFilter,\n resetFilter: resetNotificationFilter,\n refetch: fetchNotifications,\n loadMore,\n };\n}\n"],"mappings":";;;;;;AAgCA,SAAS,EAA4B,GAAsC;AACzE,QAAO;EACL,IAAI,EAAE;EACN,MAAM,EAAoB,EAAE,KAAK;EACjC,UAAU,EAAY,EAAE,SAAS;EACjC,OAAO,EAAE;EACT,MAAM,EAAE;EACR,WAAW,EAAE,eAAe,KAAA;EAC5B,UAAU,EAAE,WAAW,EAAE,EAAE,KAAK,OAAY;GAC1C,IAAI,EAAO;GACX,OAAO,EAAO;GACd,KAAK,EAAO;GACZ,OAAO,EAAO,SAAS,KAAA;GACvB,YAAY,EAAO,cAAc,KAAA;GACjC,UAAU,EAAO,YAAY,KAAA;GAC9B,EAAE;EACH,SAAS,EAAE,WAAW,KAAA;EACtB,YAAY,EAAE,cAAc,KAAA;EAC5B,SAAS,EAAE;EACX,WAAW,EAAE,aAAa,KAAA;EAC1B,aAAa,EAAE,eAAe,KAAA;EAC9B,gBAAgB,EAAE,kBAAkB,KAAA;EACpC,UAAU,EAAE,eAAe,KAAA;EAC3B,QAAQ,EAAE,SAAS,EAAE,EAAE,KAAK,OAAU;GACpC,KAAK,EAAK;GACV,OAAO,EAAK,SAAS,KAAA;GACrB,MAAM,EAAK,QAAQ,KAAA;GACnB,aAAa,EAAK,eAAe,KAAA;GACjC,cAAc,EAAK,gBAAgB,KAAA;GACpC,EAAE;EACH,UAAU,EAAE,YAAY,KAAA;EACxB,gBAAgB,EAAE,kBAAkB,KAAA;EACpC,gBAAgB,EAAE,kBAAkB,KAAA;EACpC,cAAc,EAAE,gBAAgB,KAAA;EAChC,uBAAuB,EAAE,wBACrB;GACE,IAAI,EAAE,sBAAsB;GAC5B,cAAc,EAAE,sBAAsB;GACtC,QAAQ,EAAE,sBAAsB;GAChC,UAAU,EAAE,sBAAsB,YAAY,KAAA;GAC/C,GACD,KAAA;EACJ,QAAQ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EAAU;EAAW;EAAoB,CAAC,EAE/D,QAAgB;EACd,IAAM,UAA+B;AACnC,GAAI,SAAS,oBAAoB,cAC/B,GAAoB,EACpB,GAAkB;;AAKtB,SADA,SAAS,iBAAiB,oBAAoB,EAAuB,QACxD,SAAS,oBAAoB,oBAAoB,EAAuB;IACpF,CAAC,GAAoB,EAAiB,CAAC,EA0BnC;EACL,eAzB2B,QAEzB,EAAc,QAAQ,MAChB,EAAa,mBAAmB,kBAIhC,EAAa,WAAW,cAAc,CAAC,EAAa,aAC/C,KAGL,EAAgB,aAAa,KACxB,EAAQ,EAAa,aAG1B,EAAgB,aAAa,KACxB,CAAC,EAAa,aAGhB,GACP,EACJ,CAAC,EAAgB,UAAU,EAAc,CAC1C;EAIC,kBAAkB;EAClB;EACA;EACA,oBAAoB;EACpB;EACA;EACA;EACA;EACA,YAAY;EACZ,eAAe;EACf,qBAAqB;EACrB,aAAa;EACb,uBAAuB;EACvB,cAAc;EACd;EACA,cAAc;EACd,aAAa;EACb,SAAS;EACT;EACD"}
|
|
1
|
+
{"version":3,"file":"useNotifications.js","names":[],"sources":["../../src/hooks/useNotifications.ts"],"sourcesContent":["import { useState, useCallback, useEffect, useMemo } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient, USER_NOTIFICATION_CONTEXT } from '../graphql/global-client';\nimport { useNotificationStore } from '../store/notificationStore';\nimport type { Notification, NotificationFilter } from '../types';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n GetNotificationsQuery,\n GetMyUnreadNotificationCountQuery,\n NotificationFieldsFragment,\n NotificationReceivedSubscription,\n UnreadCountUpdatedSubscription,\n} from '../generated/global-operations';\n\n// ---------------------------------------------------------------------------\n// GraphQL Operations — using generated Document nodes from global-operations\n// ---------------------------------------------------------------------------\n\n/**\n * Backend Notification item type derived from the generated query\n */\ntype BackendNotification = NotificationFieldsFragment;\n\ninterface UseNotificationsOptions {\n baseFilter?: Partial<NotificationFilter>;\n unreadFilter?: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Mapping helpers — backend → MFE types\n// ---------------------------------------------------------------------------\n\nfunction mapBackendToMfeNotification(n: BackendNotification): Notification {\n return {\n id: n.id,\n type: mapNotificationType(n.type),\n priority: mapPriority(n.priority),\n title: n.title,\n body: n.message,\n actionUrl: n.redirectUrl ?? undefined,\n actions: (n.actions || []).map((action) => ({\n id: action.id,\n label: action.label,\n url: action.url,\n style: action.style ?? undefined,\n actionType: action.actionType ?? undefined,\n metadata: action.metadata ?? undefined,\n })),\n appName: n.appName ?? undefined,\n archivedAt: n.archivedAt ?? undefined,\n channel: n.channel as Notification['channel'],\n clickedAt: n.clickedAt ?? undefined,\n deliveredAt: n.deliveredAt ?? undefined,\n deliveryStatus: n.deliveryStatus ?? undefined,\n htmlBody: n.htmlMessage ?? undefined,\n media: (n.media || []).map((item) => ({\n url: item.url,\n label: item.label ?? undefined,\n kind: item.kind ?? undefined,\n contentType: item.contentType ?? undefined,\n thumbnailUrl: item.thumbnailUrl ?? undefined,\n })),\n openedAt: n.openedAt ?? undefined,\n recipientEmail: n.recipientEmail ?? undefined,\n recipientPhone: n.recipientPhone ?? undefined,\n scheduledFor: n.scheduledFor ?? undefined,\n scheduledNotification: n.scheduledNotification\n ? {\n id: n.scheduledNotification.id,\n scheduledFor: n.scheduledNotification.scheduledFor,\n status: n.scheduledNotification.status,\n timezone: n.scheduledNotification.timezone ?? undefined,\n }\n : undefined,\n sentAt: n.sentAt ?? undefined,\n status: mapStatus(n.status),\n readAt: n.readAt ?? undefined,\n createdAt: n.createdAt,\n channels: [\n {\n id: n.id,\n channel: n.channel as Notification['channel'],\n status: mapStatus(n.status),\n sentAt: n.sentAt ?? undefined,\n deliveredAt: n.deliveredAt ?? undefined,\n failedAt: n.failedAt ?? undefined,\n errorCode: n.errorCode ?? undefined,\n errorMessage: n.errorMessage ?? undefined,\n },\n ],\n metadata: n.metadata ?? undefined,\n topic: n.topic\n ? {\n id: n.topic.id,\n name: n.topic.name,\n slug: n.topic.slug,\n type: mapNotificationType(n.topic.type),\n }\n : undefined,\n topicId: n.topicId ?? undefined,\n };\n}\n\nfunction mapNotificationType(t: string) {\n const map: Record<string, Notification['type']> = {\n SYSTEM: 'SYSTEM',\n TRANSACTIONAL: 'TRANSACTIONAL',\n MARKETING: 'MARKETING',\n ALERT: 'ALERT',\n };\n return map[t] || 'SYSTEM';\n}\n\nfunction mapPriority(p: string) {\n const map: Record<string, Notification['priority']> = {\n LOW: 'LOW',\n MEDIUM: 'NORMAL',\n HIGH: 'HIGH',\n URGENT: 'URGENT',\n };\n return map[p] || 'NORMAL';\n}\n\nfunction mapStatus(s: string) {\n const map: Record<string, Notification['status']> = {\n DRAFT: 'PENDING',\n PENDING: 'PENDING',\n SCHEDULED: 'PENDING',\n TRIGGERED: 'SENT',\n SENT: 'SENT',\n DELIVERED: 'DELIVERED',\n READ: 'DELIVERED',\n FAILED: 'FAILED',\n CANCELLED: 'ARCHIVED',\n EXPIRED: 'ARCHIVED',\n };\n return map[s] || 'PENDING';\n}\n\n// ---------------------------------------------------------------------------\n// Build the backend filter from the MFE NotificationFilter shape\n// ---------------------------------------------------------------------------\n\nfunction buildBackendFilter(filter: NotificationFilter) {\n const backend: Record<string, unknown> = {};\n\n // Type filter — map MFE type names to backend enum\n if (filter.type !== 'ALL') {\n const typeMap: Record<string, string> = {\n SYSTEM: 'SYSTEM',\n ACTIVITY: 'TRANSACTIONAL',\n BILLING: 'TRANSACTIONAL',\n SECURITY: 'ALERT',\n SOCIAL: 'MARKETING',\n REMINDER: 'SYSTEM',\n };\n backend.type = typeMap[filter.type] || filter.type;\n }\n\n // Priority filter\n if (filter.priority !== 'ALL') {\n const prioMap: Record<string, string> = {\n LOW: 'LOW',\n NORMAL: 'MEDIUM',\n HIGH: 'HIGH',\n URGENT: 'URGENT',\n };\n backend.priority = prioMap[filter.priority] || filter.priority;\n }\n\n // Read/unread filter — coerce null to undefined\n if (filter.isRead !== null && filter.isRead !== undefined) {\n backend.isRead = filter.isRead;\n }\n\n if (filter.topicId) {\n backend.topicId = filter.topicId;\n }\n\n if (filter.channel && filter.channel !== 'ALL') {\n backend.channel = filter.channel;\n }\n\n if (filter.archived !== null && filter.archived !== undefined) {\n backend.archived = filter.archived;\n }\n\n if (filter.search) {\n backend.search = filter.search;\n }\n\n // Date range\n if (filter.dateRange.start) {\n backend.startDate = filter.dateRange.start.toISOString();\n }\n if (filter.dateRange.end) {\n backend.endDate = filter.dateRange.end.toISOString();\n }\n\n return Object.keys(backend).length > 0 ? backend : undefined;\n}\n\nfunction mergeNotificationFilter(\n filter: NotificationFilter,\n baseFilter?: Partial<NotificationFilter>\n): NotificationFilter {\n if (!baseFilter) return filter;\n\n return {\n ...filter,\n ...baseFilter,\n dateRange: {\n ...filter.dateRange,\n ...(baseFilter.dateRange || {}),\n },\n };\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Hook to manage notifications with real GraphQL backend integration.\n *\n * Uses the global Apollo client to query the notification service via the\n * public gateway (https://gw-global.local.burdenoff.com/global/graphql).\n *\n * @example\n * ```tsx\n * const { notifications, unreadCount, markAsRead } = useNotifications();\n * ```\n */\nexport function useNotifications(options: UseNotificationsOptions = {}) {\n const { authToken, apiGatewayUrl, currentUser, eventBus } = useNotification();\n const {\n notificationFilter,\n updateNotificationFilter,\n resetNotificationFilter,\n unreadCount,\n setUnreadCount: setStoreUnreadCount,\n setIsLoadingNotifications,\n } = useNotificationStore();\n\n const [notifications, setNotifications] = useState<Notification[]>([]);\n const [selectedNotification, setSelectedNotification] = useState<Notification | null>(null);\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [hasMore, setHasMore] = useState(false);\n const [total, setTotal] = useState(0);\n const [offset, setOffset] = useState(0);\n\n const LIMIT = 50;\n const effectiveFilter = useMemo(\n () => mergeNotificationFilter(notificationFilter, options.baseFilter),\n [notificationFilter, options.baseFilter]\n );\n const [debouncedFilter, setDebouncedFilter] = useState(effectiveFilter);\n\n useEffect(() => {\n const timeout = window.setTimeout(() => setDebouncedFilter(effectiveFilter), 250);\n return () => window.clearTimeout(timeout);\n }, [effectiveFilter]);\n\n // Client accessor — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n // ---- Fetch notifications ------------------------------------------------\n\n const fetchNotifications = useCallback(async () => {\n setIsLoading(true);\n setIsLoadingNotifications(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationsQuery>({\n context: USER_NOTIFICATION_CONTEXT,\n query: NotificationOps.GetNotificationsDocument,\n variables: {\n filter: buildBackendFilter(debouncedFilter),\n limit: LIMIT,\n offset: 0,\n },\n fetchPolicy: 'network-only',\n });\n\n if (result.data?.notifications) {\n const mapped = result.data.notifications.items.map(mapBackendToMfeNotification);\n setNotifications(mapped);\n setTotal(result.data.notifications.total);\n setHasMore(result.data.notifications.hasMore);\n setOffset(LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to fetch notifications';\n console.error('[useNotifications] Failed to fetch notifications:', err);\n setError(message);\n } finally {\n setIsLoading(false);\n setIsLoadingNotifications(false);\n }\n }, [debouncedFilter, getClient, setIsLoadingNotifications]);\n\n // ---- Fetch unread count -------------------------------------------------\n\n const fetchUnreadCount = useCallback(async () => {\n try {\n const client = getClient();\n const result = await client.query<GetMyUnreadNotificationCountQuery>({\n context: USER_NOTIFICATION_CONTEXT,\n query: NotificationOps.GetMyUnreadNotificationCountDocument,\n variables: { filter: options.unreadFilter || { channel: 'IN_APP' } },\n fetchPolicy: 'network-only',\n });\n if (result.data) {\n setStoreUnreadCount(result.data.myUnreadNotificationCount);\n }\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to fetch unread count:', err);\n }\n }, [getClient, options.unreadFilter, setStoreUnreadCount]);\n\n // ---- Load more ----------------------------------------------------------\n\n const loadMore = useCallback(async () => {\n if (!hasMore) return;\n\n try {\n const client = getClient();\n const result = await client.query<GetNotificationsQuery>({\n context: USER_NOTIFICATION_CONTEXT,\n query: NotificationOps.GetNotificationsDocument,\n variables: {\n filter: buildBackendFilter(debouncedFilter),\n limit: LIMIT,\n offset,\n },\n fetchPolicy: 'network-only',\n });\n\n if (result.data?.notifications) {\n const more = result.data.notifications.items.map(mapBackendToMfeNotification);\n setNotifications((prev) => [...prev, ...more]);\n setHasMore(result.data.notifications.hasMore);\n setOffset((prev) => prev + LIMIT);\n }\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to load more notifications';\n console.error('[useNotifications] Failed to load more:', err);\n setError(message);\n }\n }, [debouncedFilter, getClient, hasMore, offset]);\n\n // ---- Mutations ----------------------------------------------------------\n\n const handleMarkAsRead = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.MarkNotificationAsReadDocument,\n variables: { id: notificationId },\n });\n // Optimistic: update local state\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId ? { ...n, readAt: new Date().toISOString() } : n\n )\n );\n setStoreUnreadCount(Math.max(0, unreadCount - 1));\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to mark as read:', err);\n setError('Failed to mark notification as read');\n }\n },\n [getClient, setStoreUnreadCount, unreadCount]\n );\n\n const handleMarkAllAsRead = useCallback(async () => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.MarkAllMyNotificationsAsReadDocument,\n });\n // Optimistic: update all local\n setNotifications((prev) =>\n prev.map((n) => ({ ...n, readAt: n.readAt || new Date().toISOString() }))\n );\n setStoreUnreadCount(0);\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to mark all as read:', err);\n setError('Failed to mark all notifications as read');\n }\n }, [getClient, setStoreUnreadCount]);\n\n const handleArchive = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.ArchiveNotificationDocument,\n variables: { id: notificationId },\n });\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId ? { ...n, archivedAt: new Date().toISOString() } : n\n )\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to archive notification:', err);\n setError('Failed to archive notification');\n }\n },\n [getClient]\n );\n\n const handleBulkArchive = useCallback(\n async (notificationIds: string[]) => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.ArchiveNotificationsDocument,\n variables: { notificationIds },\n });\n const idsSet = new Set(notificationIds);\n setNotifications((prev) =>\n prev.map((n) => (idsSet.has(n.id) ? { ...n, archivedAt: new Date().toISOString() } : n))\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to bulk archive:', err);\n setError('Failed to archive notifications');\n }\n },\n [getClient]\n );\n\n const handleUnarchive = useCallback(\n async (notificationId: string) => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.UnarchiveNotificationDocument,\n variables: { id: notificationId },\n });\n\n setNotifications((prev) =>\n prev.map((n) => (n.id === notificationId ? { ...n, archivedAt: undefined } : n))\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to unarchive notification:', err);\n setError('Failed to restore notification');\n }\n },\n [getClient]\n );\n\n const handleRecordAction = useCallback(\n async (notificationId: string, actionId?: string) => {\n try {\n const client = getClient();\n await client.mutate({\n context: USER_NOTIFICATION_CONTEXT,\n mutation: NotificationOps.RecordNotificationActionDocument,\n variables: { input: { notificationId, actionId } },\n });\n\n setNotifications((prev) =>\n prev.map((n) =>\n n.id === notificationId\n ? {\n ...n,\n clickedAt: new Date().toISOString(),\n readAt: n.readAt || new Date().toISOString(),\n }\n : n\n )\n );\n } catch (err: unknown) {\n console.error('[useNotifications] Failed to record notification action:', err);\n setError('Failed to record notification action');\n }\n },\n [getClient]\n );\n\n // ---- Initial fetch on mount + when filter changes -----------------------\n\n useEffect(() => {\n fetchNotifications();\n }, [fetchNotifications]);\n\n useEffect(() => {\n fetchUnreadCount();\n }, [fetchUnreadCount]);\n\n // ---- Live notification subscriptions ------------------------------------\n\n useEffect(() => {\n if (!currentUser?.id) return undefined;\n\n const client = getClient();\n const notificationSubscription = client\n .subscribe<NotificationReceivedSubscription>({\n query: NotificationOps.NotificationReceivedDocument,\n variables: { userId: currentUser.id },\n })\n .subscribe({\n next: (result) => {\n const notification = result.data?.notificationReceived;\n if (!notification) return;\n const mapped = mapBackendToMfeNotification(notification);\n setNotifications((prev) => [mapped, ...prev.filter((item) => item.id !== mapped.id)]);\n eventBus?.emit('notification:received', { notification: mapped });\n },\n error: (err) => {\n console.error('[useNotifications] Notification subscription failed:', err);\n },\n });\n\n const unreadSubscription = client\n .subscribe<UnreadCountUpdatedSubscription>({\n query: NotificationOps.UnreadCountUpdatedDocument,\n variables: { userId: currentUser.id },\n })\n .subscribe({\n next: (result) => {\n const nextCount = result.data?.unreadCountUpdated;\n if (typeof nextCount === 'number') {\n setStoreUnreadCount(nextCount);\n eventBus?.emit('notification:unread-count-updated', { unreadCount: nextCount });\n }\n },\n error: (err) => {\n console.error('[useNotifications] Unread count subscription failed:', err);\n },\n });\n\n return () => {\n notificationSubscription.unsubscribe();\n unreadSubscription.unsubscribe();\n };\n }, [currentUser?.id, eventBus, getClient, setStoreUnreadCount]);\n\n useEffect(() => {\n const handleVisibilityChange = () => {\n if (document.visibilityState === 'visible') {\n fetchNotifications();\n fetchUnreadCount();\n }\n };\n\n document.addEventListener('visibilitychange', handleVisibilityChange);\n return () => document.removeEventListener('visibilitychange', handleVisibilityChange);\n }, [fetchNotifications, fetchUnreadCount]);\n\n const visibleNotifications = useMemo(\n () =>\n notifications.filter((notification) => {\n if (notification.deliveryStatus === 'UNSUBSCRIBED') {\n return false;\n }\n\n if (notification.status === 'ARCHIVED' && !notification.archivedAt) {\n return false;\n }\n\n if (effectiveFilter.archived === true) {\n return Boolean(notification.archivedAt);\n }\n\n if (effectiveFilter.archived === false) {\n return !notification.archivedAt;\n }\n\n return true;\n }),\n [effectiveFilter.archived, notifications]\n );\n\n return {\n notifications: visibleNotifications,\n allNotifications: notifications,\n unreadCount,\n selectedNotification,\n notificationFilter: effectiveFilter,\n isLoading,\n error,\n hasMore,\n total,\n markAsRead: handleMarkAsRead,\n markAllAsRead: handleMarkAllAsRead,\n archiveNotification: handleArchive,\n bulkArchive: handleBulkArchive,\n unarchiveNotification: handleUnarchive,\n recordAction: handleRecordAction,\n setSelectedNotification,\n updateFilter: updateNotificationFilter,\n resetFilter: resetNotificationFilter,\n refetch: fetchNotifications,\n loadMore,\n };\n}\n"],"mappings":";;;;;;AAgCA,SAAS,EAA4B,GAAsC;AACzE,QAAO;EACL,IAAI,EAAE;EACN,MAAM,EAAoB,EAAE,KAAK;EACjC,UAAU,EAAY,EAAE,SAAS;EACjC,OAAO,EAAE;EACT,MAAM,EAAE;EACR,WAAW,EAAE,eAAe,KAAA;EAC5B,UAAU,EAAE,WAAW,EAAE,EAAE,KAAK,OAAY;GAC1C,IAAI,EAAO;GACX,OAAO,EAAO;GACd,KAAK,EAAO;GACZ,OAAO,EAAO,SAAS,KAAA;GACvB,YAAY,EAAO,cAAc,KAAA;GACjC,UAAU,EAAO,YAAY,KAAA;GAC9B,EAAE;EACH,SAAS,EAAE,WAAW,KAAA;EACtB,YAAY,EAAE,cAAc,KAAA;EAC5B,SAAS,EAAE;EACX,WAAW,EAAE,aAAa,KAAA;EAC1B,aAAa,EAAE,eAAe,KAAA;EAC9B,gBAAgB,EAAE,kBAAkB,KAAA;EACpC,UAAU,EAAE,eAAe,KAAA;EAC3B,QAAQ,EAAE,SAAS,EAAE,EAAE,KAAK,OAAU;GACpC,KAAK,EAAK;GACV,OAAO,EAAK,SAAS,KAAA;GACrB,MAAM,EAAK,QAAQ,KAAA;GACnB,aAAa,EAAK,eAAe,KAAA;GAC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;AACd,YAAQ,MAAM,wDAAwD,EAAI;;GAE7E,CAAC,EAEE,IAAqB,EACxB,UAA0C;GACzC,OAAO;GACP,WAAW,EAAE,QAAQ,EAAY,IAAI;GACtC,CAAC,CACD,UAAU;GACT,OAAO,MAAW;IAChB,IAAM,IAAY,EAAO,MAAM;AAC/B,IAAI,OAAO,KAAc,aACvB,EAAoB,EAAU,EAC9B,GAAU,KAAK,qCAAqC,EAAE,aAAa,GAAW,CAAC;;GAGnF,QAAQ,MAAQ;AACd,YAAQ,MAAM,wDAAwD,EAAI;;GAE7E,CAAC;AAEJ,eAAa;AAEX,GADA,EAAyB,aAAa,EACtC,EAAmB,aAAa;;IAEjC;EAAC,GAAa;EAAI;EAAU;EAAW;EAAoB,CAAC,EAE/D,QAAgB;EACd,IAAM,UAA+B;AACnC,GAAI,SAAS,oBAAoB,cAC/B,GAAoB,EACpB,GAAkB;;AAKtB,SADA,SAAS,iBAAiB,oBAAoB,EAAuB,QACxD,SAAS,oBAAoB,oBAAoB,EAAuB;IACpF,CAAC,GAAoB,EAAiB,CAAC,EA0BnC;EACL,eAzB2B,QAEzB,EAAc,QAAQ,MAChB,EAAa,mBAAmB,kBAIhC,EAAa,WAAW,cAAc,CAAC,EAAa,aAC/C,KAGL,EAAgB,aAAa,KACxB,EAAQ,EAAa,aAG1B,EAAgB,aAAa,KACxB,CAAC,EAAa,aAGhB,GACP,EACJ,CAAC,EAAgB,UAAU,EAAc,CAC1C;EAIC,kBAAkB;EAClB;EACA;EACA,oBAAoB;EACpB;EACA;EACA;EACA;EACA,YAAY;EACZ,eAAe;EACf,qBAAqB;EACrB,aAAa;EACb,uBAAuB;EACvB,cAAc;EACd;EACA,cAAc;EACd,aAAa;EACb,SAAS;EACT;EACD"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useNotification as e } from "./providers/NotificationProvider.js";
|
|
2
2
|
import { useNotificationStore as t } from "./store/notificationStore.js";
|
|
3
3
|
import { useNotifications as n } from "./hooks/useNotifications.js";
|
|
4
|
-
import "./hooks/index.js";
|
|
5
4
|
import { filterNotifications as r, formatRelativeTime as i, getNotificationTypeIcon as a, getNotificationTypeLabel as o, getPriorityColor as s, getPriorityIcon as c, groupNotificationsByDate as l, sortNotificationsByDate as u, substituteTemplateVariables as d, truncateText as f, validateTemplateVariables as p } from "./utils/index.js";
|
|
5
|
+
import "./hooks/index.js";
|
|
6
6
|
import { NotificationCard as m } from "./components/NotificationCard.js";
|
|
7
7
|
import { NotificationRoot as h } from "./NotificationRoot.js";
|
|
8
8
|
import { UserNotificationRoot as g } from "./UserNotificationRoot.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useNotificationAnalytics as e } from "../hooks/useNotificationAnalytics.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { isPermissionError as t } from "../utils/index.js";
|
|
3
|
+
import { useNotificationTopics as n } from "../hooks/useNotificationTopics.js";
|
|
4
|
+
import { useTr as r } from "../shared/hooks/useTr.js";
|
|
5
5
|
import { nativeImpact as ee, nativeNotify as i } from "../utils/nativeBridge.js";
|
|
6
6
|
import { NOTIFICATION_PERMISSIONS as te } from "../constants/permissions.js";
|
|
7
7
|
import { useSendNotification as ne } from "../hooks/useSendNotification.js";
|
|
@@ -176,7 +176,7 @@ var Oe = [
|
|
|
176
176
|
}
|
|
177
177
|
];
|
|
178
178
|
function Ne() {
|
|
179
|
-
let ge = xe(), l =
|
|
179
|
+
let ge = xe(), l = r(), { hasPermission: ve, isLoading: Ne, refreshPermissions: Pe } = se(), { showToast: Fe } = oe(), { sendNotification: Ie, sendBatch: Le, sendWithTemplate: Re, isSending: p, error: ze, lastResult: Be, clearError: Ve, clearResult: He } = ne(), { templates: m, isLoading: Ue } = re(), { trackNotificationSent: We } = e(), { searchUsers: h, fetchAllUsers: Ge, results: g, isLoading: Ke, error: _ } = ie(), { topics: qe } = n({ isActive: !0 }), [v, Je] = o("compose"), [y, Ye] = o("EMAIL"), [b, Xe] = o("MARKETING"), [x, Ze] = o("MEDIUM"), [S, Qe] = o([]), [C, w] = o("manual"), [T, E] = o([]), [D, O] = o(!1), [k, $e] = o(""), [A, et] = o(""), [j, tt] = o(""), [M, nt] = o(""), [N, rt] = o(""), [it, at] = o(!1), [P, ot] = o(""), [st, F] = o([{
|
|
180
180
|
url: "",
|
|
181
181
|
label: "",
|
|
182
182
|
kind: "image"
|
|
@@ -354,7 +354,7 @@ function Ne() {
|
|
|
354
354
|
}))?.status && (n(1, 0), Y(!0), i("success"));
|
|
355
355
|
}
|
|
356
356
|
} catch (e) {
|
|
357
|
-
if (i("error"),
|
|
357
|
+
if (i("error"), t(e)) {
|
|
358
358
|
Ve(), Fe(l("notifications.permissionDeniedOnSend", "You don't have permission to send that notification. Refreshing access…"), "warning"), Pe().catch((e) => console.warn("[permissions] refresh failed after send denial:", e));
|
|
359
359
|
return;
|
|
360
360
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useNotification as e } from "../providers/NotificationProvider.js";
|
|
2
2
|
import { useNotifications as t } from "../hooks/useNotifications.js";
|
|
3
|
-
import {
|
|
3
|
+
import { filterNotifications as n, groupNotificationsByDate as r } from "../utils/index.js";
|
|
4
|
+
import { useNotificationTopics as i } from "../hooks/useNotificationTopics.js";
|
|
4
5
|
import "../hooks/index.js";
|
|
5
|
-
import { useTr as
|
|
6
|
-
import { filterNotifications as i, groupNotificationsByDate as a } from "../utils/index.js";
|
|
6
|
+
import { useTr as a } from "../shared/hooks/useTr.js";
|
|
7
7
|
import { NotificationCard as o } from "../components/NotificationCard.js";
|
|
8
8
|
import { NOTIFICATION_PERMISSIONS as s } from "../constants/permissions.js";
|
|
9
9
|
import { useMemo as c } from "react";
|
|
@@ -60,10 +60,10 @@ var w = {
|
|
|
60
60
|
}
|
|
61
61
|
];
|
|
62
62
|
function O() {
|
|
63
|
-
let O =
|
|
63
|
+
let O = a(), { hasPermission: k, isLoading: A } = l(), { currentUser: j } = e(), { notifications: M, unreadCount: N, notificationFilter: P, markAsRead: F, markAllAsRead: I, archiveNotification: L, recordAction: R, updateFilter: z, resetFilter: B } = t({
|
|
64
64
|
baseFilter: w,
|
|
65
65
|
unreadFilter: T
|
|
66
|
-
}), { topics: V } =
|
|
66
|
+
}), { topics: V } = i({ isActive: !0 }), H = c(() => n(M, P), [M, P]), U = c(() => r(H, O), [H, O]);
|
|
67
67
|
return A ? /* @__PURE__ */ m("div", {
|
|
68
68
|
className: "flex h-64 items-center justify-center",
|
|
69
69
|
children: /* @__PURE__ */ m("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
|