@burdenoff/microfe-notification 2026.518.2 → 2026.521.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/AdminNotificationRoutes.d.ts.map +1 -1
- package/dist/AdminNotificationRoutes.js +50 -46
- package/dist/AdminNotificationRoutes.js.map +1 -1
- package/dist/UserNotificationRoutes.d.ts.map +1 -1
- package/dist/UserNotificationRoutes.js +28 -24
- package/dist/UserNotificationRoutes.js.map +1 -1
- package/dist/components/FeatureDisabledPage.d.ts +7 -0
- package/dist/components/FeatureDisabledPage.d.ts.map +1 -0
- package/dist/components/FeatureDisabledPage.js +32 -0
- package/dist/components/FeatureDisabledPage.js.map +1 -0
- package/dist/components/NotificationBell.d.ts.map +1 -1
- package/dist/components/NotificationBell.js +43 -22
- package/dist/components/NotificationBell.js.map +1 -1
- package/dist/components/NotificationCard.d.ts +2 -1
- package/dist/components/NotificationCard.d.ts.map +1 -1
- package/dist/components/NotificationCard.js +64 -63
- package/dist/components/NotificationCard.js.map +1 -1
- package/dist/components/NotificationPanel.d.ts.map +1 -1
- package/dist/components/NotificationPanel.js +2 -1
- package/dist/components/NotificationPanel.js.map +1 -1
- package/dist/graphql/global-client.js +1 -1
- package/dist/graphql/global-client.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useNotificationAdmin.d.ts.map +1 -1
- package/dist/hooks/useNotificationAdmin.js +67 -64
- package/dist/hooks/useNotificationAdmin.js.map +1 -1
- package/dist/hooks/useNotificationAnalytics.d.ts +67 -0
- package/dist/hooks/useNotificationAnalytics.d.ts.map +1 -0
- package/dist/hooks/useNotificationAnalytics.js +64 -0
- package/dist/hooks/useNotificationAnalytics.js.map +1 -0
- package/dist/hooks/useNotificationPreferences.js +1 -1
- package/dist/hooks/useNotificationPreferences.js.map +1 -1
- package/dist/hooks/useNotificationTemplates.js +3 -3
- package/dist/hooks/useNotificationTemplates.js.map +1 -1
- package/dist/hooks/useNotificationTopics.js +1 -1
- package/dist/hooks/useNotificationTopics.js.map +1 -1
- package/dist/hooks/useNotifications.d.ts.map +1 -1
- package/dist/hooks/useNotifications.js +47 -40
- package/dist/hooks/useNotifications.js.map +1 -1
- package/dist/pages/CreateNotificationPage.d.ts.map +1 -1
- package/dist/pages/CreateNotificationPage.js +407 -391
- package/dist/pages/CreateNotificationPage.js.map +1 -1
- package/dist/pages/NotificationCenterPage.d.ts.map +1 -1
- package/dist/pages/NotificationCenterPage.js +80 -81
- package/dist/pages/NotificationCenterPage.js.map +1 -1
- package/dist/pages/NotificationHistoryAdminPage.d.ts.map +1 -1
- package/dist/pages/NotificationHistoryAdminPage.js +2 -1
- package/dist/pages/NotificationHistoryAdminPage.js.map +1 -1
- package/dist/pages/NotificationHistoryPage.d.ts.map +1 -1
- package/dist/pages/NotificationHistoryPage.js +2 -1
- package/dist/pages/NotificationHistoryPage.js.map +1 -1
- package/dist/pages/NotificationPreferencesPage.d.ts.map +1 -1
- package/dist/pages/NotificationPreferencesPage.js +140 -95
- package/dist/pages/NotificationPreferencesPage.js.map +1 -1
- package/dist/pages/TemplateEditorPage.d.ts.map +1 -1
- package/dist/pages/TemplateEditorPage.js +326 -313
- package/dist/pages/TemplateEditorPage.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { useNotification as e } from "../providers/NotificationProvider.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useNotificationAnalytics as t } from "../hooks/useNotificationAnalytics.js";
|
|
3
|
+
import { useNotificationPreferences as n } from "../hooks/useNotificationPreferences.js";
|
|
4
|
+
import { useNotificationTopics as r } from "../hooks/useNotificationTopics.js";
|
|
4
5
|
import "../hooks/index.js";
|
|
5
|
-
import { useTr as
|
|
6
|
-
import { nativeImpact as
|
|
7
|
-
import { NOTIFICATION_PERMISSIONS as
|
|
8
|
-
import { useMemo as
|
|
9
|
-
import { BellRing as
|
|
10
|
-
import { usePermissions as
|
|
11
|
-
import { jsx as
|
|
6
|
+
import { useTr as i } from "../shared/hooks/useTr.js";
|
|
7
|
+
import { nativeImpact as a, nativeNotify as o } from "../utils/nativeBridge.js";
|
|
8
|
+
import { NOTIFICATION_PERMISSIONS as s } from "../constants/permissions.js";
|
|
9
|
+
import { useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
10
|
+
import { BellRing as f, Search as p, ToggleLeft as m, ToggleRight as h } from "lucide-react";
|
|
11
|
+
import { usePermissions as g } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
12
|
+
import { jsx as _, jsxs as v } from "react/jsx-runtime";
|
|
12
13
|
//#region src/pages/NotificationPreferencesPage.tsx
|
|
13
|
-
var
|
|
14
|
+
var y = [
|
|
14
15
|
{
|
|
15
16
|
value: "IN_APP",
|
|
16
17
|
labelKey: "notifications.channelInApp",
|
|
@@ -41,7 +42,7 @@ var g = [
|
|
|
41
42
|
labelKey: "notifications.channelSlack",
|
|
42
43
|
label: "Slack"
|
|
43
44
|
}
|
|
44
|
-
],
|
|
45
|
+
], b = [
|
|
45
46
|
{
|
|
46
47
|
value: "TRANSACTIONAL",
|
|
47
48
|
labelKey: "notifications.typeTransactional",
|
|
@@ -63,180 +64,224 @@ var g = [
|
|
|
63
64
|
label: "Marketing"
|
|
64
65
|
}
|
|
65
66
|
];
|
|
66
|
-
function
|
|
67
|
+
function x(e) {
|
|
67
68
|
return e.scope === "CHANNEL" ? `CHANNEL:${e.channel || ""}` : e.scope === "TYPE" ? `TYPE:${e.type || ""}` : e.scope === "TOPIC" ? `TOPIC:${e.topicId || ""}` : "GLOBAL";
|
|
68
69
|
}
|
|
69
|
-
function
|
|
70
|
-
let
|
|
70
|
+
function S() {
|
|
71
|
+
let S = i(), { hasPermission: C, isLoading: w } = g(), { currentUser: T } = e(), { topics: E, isLoading: D } = r({
|
|
71
72
|
type: "MARKETING",
|
|
72
73
|
isActive: !0
|
|
73
|
-
}), { preferencesByKey:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
}), { preferencesByKey: O, isLoading: k, setPreference: A, deletePreference: j } = n(), { trackPreferenceUpdated: M } = t(), [N, P] = d(""), [F, I] = d(null), [L, R] = d(null), z = u(null), B = D || k;
|
|
75
|
+
c(() => () => {
|
|
76
|
+
z.current && clearTimeout(z.current);
|
|
77
|
+
}, []);
|
|
78
|
+
let V = (e) => {
|
|
79
|
+
z.current && clearTimeout(z.current), R(e), z.current = setTimeout(() => {
|
|
80
|
+
R((t) => t?.key === e.key ? null : t), z.current = null;
|
|
81
|
+
}, 2500);
|
|
82
|
+
}, H = l(() => {
|
|
83
|
+
if (!N.trim()) return E;
|
|
84
|
+
let e = N.toLowerCase();
|
|
85
|
+
return E.filter((t) => t.name.toLowerCase().includes(e) || t.slug.toLowerCase().includes(e) || t.description?.toLowerCase().includes(e));
|
|
86
|
+
}, [N, E]), U = async (e) => {
|
|
87
|
+
let t = x(e), n = O.get(t), r = !(n?.enabled ?? !0);
|
|
88
|
+
I(t), a("medium");
|
|
80
89
|
try {
|
|
81
|
-
await
|
|
90
|
+
await A({
|
|
82
91
|
...e,
|
|
83
|
-
enabled:
|
|
92
|
+
enabled: r,
|
|
84
93
|
frequency: n?.frequency || "IMMEDIATE"
|
|
85
|
-
}),
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
}), M({
|
|
95
|
+
action: "set",
|
|
96
|
+
scope: e.scope,
|
|
97
|
+
channel: e.channel,
|
|
98
|
+
type: e.type,
|
|
99
|
+
enabled: r
|
|
100
|
+
}), V({
|
|
101
|
+
key: t,
|
|
102
|
+
type: "success",
|
|
103
|
+
message: S("notifications.preferenceSaved", "Preference saved.")
|
|
104
|
+
}), o("success");
|
|
105
|
+
} catch {
|
|
106
|
+
V({
|
|
107
|
+
key: t,
|
|
108
|
+
type: "error",
|
|
109
|
+
message: S("notifications.preferenceSaveFailed", "Could not save preference.")
|
|
110
|
+
}), o("error");
|
|
88
111
|
} finally {
|
|
89
|
-
|
|
112
|
+
I(null);
|
|
90
113
|
}
|
|
91
|
-
},
|
|
92
|
-
let t =
|
|
114
|
+
}, W = async (e) => {
|
|
115
|
+
let t = O.get(e);
|
|
93
116
|
if (t) {
|
|
94
|
-
|
|
117
|
+
I(e);
|
|
95
118
|
try {
|
|
96
|
-
await
|
|
119
|
+
await j(t.id), M({
|
|
120
|
+
action: "reset",
|
|
121
|
+
scope: t.scope,
|
|
122
|
+
channel: t.channel,
|
|
123
|
+
type: t.type
|
|
124
|
+
}), V({
|
|
125
|
+
key: e,
|
|
126
|
+
type: "success",
|
|
127
|
+
message: S("notifications.preferenceReset", "Preference reset.")
|
|
128
|
+
});
|
|
129
|
+
} catch {
|
|
130
|
+
V({
|
|
131
|
+
key: e,
|
|
132
|
+
type: "error",
|
|
133
|
+
message: S("notifications.preferenceResetFailed", "Could not reset preference.")
|
|
134
|
+
});
|
|
97
135
|
} finally {
|
|
98
|
-
|
|
136
|
+
I(null);
|
|
99
137
|
}
|
|
100
138
|
}
|
|
101
|
-
},
|
|
102
|
-
let t =
|
|
103
|
-
return /* @__PURE__ */
|
|
139
|
+
}, G = (e) => {
|
|
140
|
+
let t = O.get(e.key), n = t?.enabled ?? !0, r = F === e.key, i = L?.key === e.key ? L : null;
|
|
141
|
+
return /* @__PURE__ */ v("div", {
|
|
104
142
|
className: "rounded-lg border border-default bg-surface p-4 shadow-sm",
|
|
105
|
-
children: /* @__PURE__ */
|
|
143
|
+
children: [/* @__PURE__ */ v("div", {
|
|
106
144
|
className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
|
|
107
|
-
children: [/* @__PURE__ */
|
|
145
|
+
children: [/* @__PURE__ */ v("div", {
|
|
108
146
|
className: "space-y-1",
|
|
109
|
-
children: [/* @__PURE__ */
|
|
147
|
+
children: [/* @__PURE__ */ v("div", {
|
|
110
148
|
className: "flex items-center gap-2",
|
|
111
149
|
children: [
|
|
112
|
-
/* @__PURE__ */
|
|
150
|
+
/* @__PURE__ */ _(f, {
|
|
113
151
|
size: 16,
|
|
114
152
|
className: "text-accent-primary"
|
|
115
153
|
}),
|
|
116
|
-
/* @__PURE__ */
|
|
154
|
+
/* @__PURE__ */ _("h2", {
|
|
117
155
|
className: "text-sm font-semibold text-primary",
|
|
118
156
|
children: e.title
|
|
119
157
|
}),
|
|
120
|
-
t && /* @__PURE__ */
|
|
158
|
+
t && /* @__PURE__ */ _("span", {
|
|
121
159
|
className: "rounded-full bg-muted px-2 py-0.5 text-xs text-secondary",
|
|
122
160
|
children: t.frequency.replace("_", " ").toLowerCase()
|
|
123
161
|
})
|
|
124
162
|
]
|
|
125
|
-
}), /* @__PURE__ */
|
|
163
|
+
}), /* @__PURE__ */ _("p", {
|
|
126
164
|
className: "text-sm text-secondary",
|
|
127
165
|
children: e.description
|
|
128
166
|
})]
|
|
129
|
-
}), /* @__PURE__ */
|
|
167
|
+
}), /* @__PURE__ */ v("div", {
|
|
130
168
|
className: "flex items-center gap-2",
|
|
131
|
-
children: [t && /* @__PURE__ */
|
|
169
|
+
children: [t && /* @__PURE__ */ _("button", {
|
|
132
170
|
type: "button",
|
|
133
171
|
disabled: r,
|
|
134
|
-
onClick: () =>
|
|
172
|
+
onClick: () => W(e.key),
|
|
135
173
|
className: "rounded-md border border-default px-3 py-2 text-sm text-secondary hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50",
|
|
136
|
-
children:
|
|
137
|
-
}), /* @__PURE__ */
|
|
174
|
+
children: S("notifications.reset", "Reset")
|
|
175
|
+
}), /* @__PURE__ */ v("button", {
|
|
138
176
|
type: "button",
|
|
139
177
|
"aria-pressed": n,
|
|
140
178
|
disabled: r,
|
|
141
|
-
onClick: () =>
|
|
179
|
+
onClick: () => U({
|
|
142
180
|
scope: e.scope,
|
|
143
181
|
channel: e.channel,
|
|
144
182
|
type: e.type,
|
|
145
183
|
topicId: e.topicId
|
|
146
184
|
}),
|
|
147
185
|
className: `inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm font-medium transition-colors ${n ? "border-accent-primary bg-action-primary-bg text-text-inverse hover:opacity-90" : "border-default bg-muted text-secondary hover:bg-muted/80"} disabled:cursor-not-allowed disabled:opacity-50`,
|
|
148
|
-
children: [
|
|
186
|
+
children: [_(n ? h : m, { size: 18 }), r ? S("notifications.saving", "Saving...") : n ? S("notifications.enabled", "Enabled") : S("notifications.disabled", "Disabled")]
|
|
149
187
|
})]
|
|
150
188
|
})]
|
|
151
|
-
})
|
|
189
|
+
}), /* @__PURE__ */ _("div", {
|
|
190
|
+
className: "mt-3 min-h-5",
|
|
191
|
+
"aria-live": "polite",
|
|
192
|
+
children: i && /* @__PURE__ */ _("p", {
|
|
193
|
+
className: `text-xs ${i.type === "success" ? "text-success" : "text-error"}`,
|
|
194
|
+
children: i.message
|
|
195
|
+
})
|
|
196
|
+
})]
|
|
152
197
|
}, e.key);
|
|
153
198
|
};
|
|
154
|
-
return
|
|
199
|
+
return w ? /* @__PURE__ */ _("div", {
|
|
155
200
|
className: "flex h-64 items-center justify-center",
|
|
156
|
-
children: /* @__PURE__ */
|
|
157
|
-
}) : !
|
|
201
|
+
children: /* @__PURE__ */ _("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
|
|
202
|
+
}) : !C(s.NOTIFICATION_LIST) && !T?.id ? /* @__PURE__ */ _("div", {
|
|
158
203
|
className: "p-8 text-center text-text-secondary",
|
|
159
|
-
children:
|
|
160
|
-
}) : /* @__PURE__ */
|
|
204
|
+
children: S("notifications.noPermissionPreferences", "You don't have permission to manage notification preferences.")
|
|
205
|
+
}) : /* @__PURE__ */ v("div", {
|
|
161
206
|
className: "space-y-6 p-4 sm:p-6",
|
|
162
207
|
children: [
|
|
163
|
-
/* @__PURE__ */
|
|
208
|
+
/* @__PURE__ */ v("div", { children: [/* @__PURE__ */ _("h1", {
|
|
164
209
|
className: "text-2xl font-bold text-primary",
|
|
165
|
-
children:
|
|
166
|
-
}), /* @__PURE__ */
|
|
210
|
+
children: S("notifications.preferencesTitle", "Notification Preferences")
|
|
211
|
+
}), /* @__PURE__ */ _("p", {
|
|
167
212
|
className: "mt-1 text-sm text-secondary",
|
|
168
|
-
children:
|
|
213
|
+
children: S("notifications.preferencesSubtitle", "Control global, channel, type, and topic-level notification delivery.")
|
|
169
214
|
})] }),
|
|
170
|
-
/* @__PURE__ */
|
|
215
|
+
/* @__PURE__ */ v("section", {
|
|
171
216
|
className: "space-y-3",
|
|
172
|
-
children: [/* @__PURE__ */
|
|
217
|
+
children: [/* @__PURE__ */ _("h2", {
|
|
173
218
|
className: "text-sm font-semibold uppercase tracking-wide text-tertiary",
|
|
174
|
-
children:
|
|
175
|
-
}),
|
|
219
|
+
children: S("notifications.globalPreferences", "Global")
|
|
220
|
+
}), G({
|
|
176
221
|
key: "GLOBAL",
|
|
177
222
|
scope: "GLOBAL",
|
|
178
|
-
title:
|
|
179
|
-
description:
|
|
223
|
+
title: S("notifications.allNotifications", "All notifications"),
|
|
224
|
+
description: S("notifications.allNotificationsDescription", "Master preference for notification delivery across all channels and types.")
|
|
180
225
|
})]
|
|
181
226
|
}),
|
|
182
|
-
/* @__PURE__ */
|
|
227
|
+
/* @__PURE__ */ v("section", {
|
|
183
228
|
className: "space-y-3",
|
|
184
|
-
children: [/* @__PURE__ */
|
|
229
|
+
children: [/* @__PURE__ */ _("h2", {
|
|
185
230
|
className: "text-sm font-semibold uppercase tracking-wide text-tertiary",
|
|
186
|
-
children:
|
|
187
|
-
}), /* @__PURE__ */
|
|
231
|
+
children: S("notifications.channelPreferences", "Channels")
|
|
232
|
+
}), /* @__PURE__ */ _("div", {
|
|
188
233
|
className: "grid gap-3 lg:grid-cols-2",
|
|
189
|
-
children:
|
|
234
|
+
children: y.map((e) => G({
|
|
190
235
|
key: `CHANNEL:${e.value}`,
|
|
191
236
|
scope: "CHANNEL",
|
|
192
237
|
channel: e.value,
|
|
193
|
-
title:
|
|
194
|
-
description:
|
|
238
|
+
title: S(e.labelKey, e.label),
|
|
239
|
+
description: S("notifications.channelPreferenceDescription", "Control delivery for this channel.")
|
|
195
240
|
}))
|
|
196
241
|
})]
|
|
197
242
|
}),
|
|
198
|
-
/* @__PURE__ */
|
|
243
|
+
/* @__PURE__ */ v("section", {
|
|
199
244
|
className: "space-y-3",
|
|
200
|
-
children: [/* @__PURE__ */
|
|
245
|
+
children: [/* @__PURE__ */ _("h2", {
|
|
201
246
|
className: "text-sm font-semibold uppercase tracking-wide text-tertiary",
|
|
202
|
-
children:
|
|
203
|
-
}), /* @__PURE__ */
|
|
247
|
+
children: S("notifications.typePreferences", "Notification Types")
|
|
248
|
+
}), /* @__PURE__ */ _("div", {
|
|
204
249
|
className: "grid gap-3 lg:grid-cols-2",
|
|
205
|
-
children:
|
|
250
|
+
children: b.map((e) => G({
|
|
206
251
|
key: `TYPE:${e.value}`,
|
|
207
252
|
scope: "TYPE",
|
|
208
253
|
type: e.value,
|
|
209
|
-
title:
|
|
210
|
-
description:
|
|
254
|
+
title: S(e.labelKey, e.label),
|
|
255
|
+
description: S("notifications.typePreferenceDescription", "Control delivery for this notification type.")
|
|
211
256
|
}))
|
|
212
257
|
})]
|
|
213
258
|
}),
|
|
214
|
-
/* @__PURE__ */
|
|
259
|
+
/* @__PURE__ */ v("div", {
|
|
215
260
|
className: "relative max-w-xl",
|
|
216
|
-
children: [/* @__PURE__ */
|
|
261
|
+
children: [/* @__PURE__ */ _(p, {
|
|
217
262
|
size: 16,
|
|
218
263
|
className: "absolute left-3 top-1/2 -translate-y-1/2 text-tertiary"
|
|
219
|
-
}), /* @__PURE__ */
|
|
264
|
+
}), /* @__PURE__ */ _("input", {
|
|
220
265
|
type: "text",
|
|
221
|
-
value:
|
|
222
|
-
onChange: (e) =>
|
|
223
|
-
"aria-label":
|
|
224
|
-
placeholder:
|
|
266
|
+
value: N,
|
|
267
|
+
onChange: (e) => P(e.target.value),
|
|
268
|
+
"aria-label": S("notifications.searchTopics", "Search topics..."),
|
|
269
|
+
placeholder: S("notifications.searchTopics", "Search topics..."),
|
|
225
270
|
className: "w-full rounded-lg border border-default bg-surface py-2 pl-9 pr-4 text-sm text-primary focus:outline-none focus:ring-2 focus:ring-accent"
|
|
226
271
|
})]
|
|
227
272
|
}),
|
|
228
|
-
/* @__PURE__ */
|
|
273
|
+
/* @__PURE__ */ v("section", {
|
|
229
274
|
className: "space-y-3",
|
|
230
|
-
children: [/* @__PURE__ */
|
|
275
|
+
children: [/* @__PURE__ */ _("h2", {
|
|
231
276
|
className: "text-sm font-semibold uppercase tracking-wide text-tertiary",
|
|
232
|
-
children:
|
|
233
|
-
}),
|
|
277
|
+
children: S("notifications.topicPreferences", "Topics")
|
|
278
|
+
}), B ? /* @__PURE__ */ _("div", {
|
|
234
279
|
className: "rounded-lg border border-default bg-surface p-6 text-sm text-secondary",
|
|
235
|
-
children:
|
|
236
|
-
}) :
|
|
280
|
+
children: S("notifications.loadingPreferences", "Loading preferences...")
|
|
281
|
+
}) : H.length === 0 ? /* @__PURE__ */ _("div", {
|
|
237
282
|
className: "rounded-lg border border-default bg-surface p-6 text-sm text-secondary",
|
|
238
|
-
children:
|
|
239
|
-
}) :
|
|
283
|
+
children: S("notifications.noTopicsFound", "No promotional topics available right now.")
|
|
284
|
+
}) : H.map((e) => G({
|
|
240
285
|
key: `TOPIC:${e.id}`,
|
|
241
286
|
scope: "TOPIC",
|
|
242
287
|
topicId: e.id,
|
|
@@ -248,6 +293,6 @@ function y() {
|
|
|
248
293
|
});
|
|
249
294
|
}
|
|
250
295
|
//#endregion
|
|
251
|
-
export {
|
|
296
|
+
export { S as NotificationPreferencesPage };
|
|
252
297
|
|
|
253
298
|
//# sourceMappingURL=NotificationPreferencesPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationPreferencesPage.js","names":[],"sources":["../../src/pages/NotificationPreferencesPage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { BellRing, Search, ToggleLeft, ToggleRight } from 'lucide-react';\nimport { usePermissions } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { useNotificationPreferences, useNotificationTopics } from '../hooks';\nimport { NOTIFICATION_PERMISSIONS } from '../constants/permissions';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { useTr } from '../shared/hooks/useTr';\nimport type { NotificationChannel, NotificationPreferenceScope, NotificationType } from '../types';\nimport { nativeImpact, nativeNotify } from '../utils/nativeBridge';\n\nconst CHANNEL_OPTIONS: Array<{ value: NotificationChannel; labelKey: string; label: string }> = [\n { value: 'IN_APP', labelKey: 'notifications.channelInApp', label: 'In-app' },\n { value: 'EMAIL', labelKey: 'notifications.channelEmail', label: 'Email' },\n { value: 'PUSH', labelKey: 'notifications.channelPush', label: 'Push' },\n { value: 'SMS', labelKey: 'notifications.channelSms', label: 'SMS' },\n { value: 'WHATSAPP', labelKey: 'notifications.channelWhatsapp', label: 'WhatsApp' },\n { value: 'SLACK', labelKey: 'notifications.channelSlack', label: 'Slack' },\n];\n\nconst TYPE_OPTIONS: Array<{ value: NotificationType; labelKey: string; label: string }> = [\n { value: 'TRANSACTIONAL', labelKey: 'notifications.typeTransactional', label: 'Transactional' },\n { value: 'SYSTEM', labelKey: 'notifications.typeSystem', label: 'System' },\n { value: 'ALERT', labelKey: 'notifications.typeAlert', label: 'Alerts' },\n { value: 'MARKETING', labelKey: 'notifications.typeMarketing', label: 'Marketing' },\n];\n\nfunction preferenceKey(input: {\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n}) {\n if (input.scope === 'CHANNEL') return `CHANNEL:${input.channel || ''}`;\n if (input.scope === 'TYPE') return `TYPE:${input.type || ''}`;\n if (input.scope === 'TOPIC') return `TOPIC:${input.topicId || ''}`;\n return 'GLOBAL';\n}\n\nexport function NotificationPreferencesPage() {\n const tr = useTr();\n const { hasPermission, isLoading: permissionsLoading } = usePermissions();\n const { currentUser } = useNotification();\n const { topics, isLoading: topicsLoading } = useNotificationTopics({\n type: 'MARKETING',\n isActive: true,\n });\n const {\n preferencesByKey,\n isLoading: preferencesLoading,\n setPreference,\n deletePreference,\n } = useNotificationPreferences();\n const [search, setSearch] = useState('');\n const [savingKey, setSavingKey] = useState<string | null>(null);\n\n const isLoading = topicsLoading || preferencesLoading;\n\n const filteredTopics = useMemo(() => {\n if (!search.trim()) {\n return topics;\n }\n\n const query = search.toLowerCase();\n return topics.filter(\n (topic) =>\n topic.name.toLowerCase().includes(query) ||\n topic.slug.toLowerCase().includes(query) ||\n topic.description?.toLowerCase().includes(query)\n );\n }, [search, topics]);\n\n const togglePreference = async (input: {\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n }) => {\n const key = preferenceKey(input);\n const existing = preferencesByKey.get(key);\n setSavingKey(key);\n nativeImpact('medium');\n try {\n await setPreference({\n ...input,\n enabled: !(existing?.enabled ?? true),\n frequency: existing?.frequency || 'IMMEDIATE',\n });\n void nativeNotify('success');\n } catch (err) {\n void nativeNotify('error');\n throw err;\n } finally {\n setSavingKey(null);\n }\n };\n\n const resetPreference = async (key: string) => {\n const existing = preferencesByKey.get(key);\n if (!existing) return;\n setSavingKey(key);\n try {\n await deletePreference(existing.id);\n } finally {\n setSavingKey(null);\n }\n };\n\n const renderPreferenceRow = (input: {\n key: string;\n title: string;\n description: string;\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n }) => {\n const existing = preferencesByKey.get(input.key);\n const isEnabled = existing?.enabled ?? true;\n const isSaving = savingKey === input.key;\n\n return (\n <div key={input.key} className=\"rounded-lg border border-default bg-surface p-4 shadow-sm\">\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"space-y-1\">\n <div className=\"flex items-center gap-2\">\n <BellRing size={16} className=\"text-accent-primary\" />\n <h2 className=\"text-sm font-semibold text-primary\">{input.title}</h2>\n {existing && (\n <span className=\"rounded-full bg-muted px-2 py-0.5 text-xs text-secondary\">\n {existing.frequency.replace('_', ' ').toLowerCase()}\n </span>\n )}\n </div>\n <p className=\"text-sm text-secondary\">{input.description}</p>\n </div>\n\n <div className=\"flex items-center gap-2\">\n {existing && (\n <button\n type=\"button\"\n disabled={isSaving}\n onClick={() => resetPreference(input.key)}\n className=\"rounded-md border border-default px-3 py-2 text-sm text-secondary hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50\"\n >\n {tr('notifications.reset', 'Reset')}\n </button>\n )}\n <button\n type=\"button\"\n aria-pressed={isEnabled}\n disabled={isSaving}\n onClick={() =>\n togglePreference({\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n })\n }\n className={`inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm font-medium transition-colors ${\n isEnabled\n ? 'border-accent-primary bg-action-primary-bg text-text-inverse hover:opacity-90'\n : 'border-default bg-muted text-secondary hover:bg-muted/80'\n } disabled:cursor-not-allowed disabled:opacity-50`}\n >\n {isEnabled ? <ToggleRight size={18} /> : <ToggleLeft size={18} />}\n {isEnabled\n ? tr('notifications.enabled', 'Enabled')\n : tr('notifications.disabled', 'Disabled')}\n </button>\n </div>\n </div>\n </div>\n );\n };\n\n if (permissionsLoading) {\n return (\n <div className=\"flex h-64 items-center justify-center\">\n <div className=\"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent\" />\n </div>\n );\n }\n\n if (!hasPermission(NOTIFICATION_PERMISSIONS.NOTIFICATION_LIST) && !currentUser?.id) {\n return (\n <div className=\"p-8 text-center text-text-secondary\">\n {tr(\n 'notifications.noPermissionPreferences',\n \"You don't have permission to manage notification preferences.\"\n )}\n </div>\n );\n }\n\n return (\n <div className=\"space-y-6 p-4 sm:p-6\">\n <div>\n <h1 className=\"text-2xl font-bold text-primary\">\n {tr('notifications.preferencesTitle', 'Notification Preferences')}\n </h1>\n <p className=\"mt-1 text-sm text-secondary\">\n {tr(\n 'notifications.preferencesSubtitle',\n 'Control global, channel, type, and topic-level notification delivery.'\n )}\n </p>\n </div>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.globalPreferences', 'Global')}\n </h2>\n {renderPreferenceRow({\n key: 'GLOBAL',\n scope: 'GLOBAL',\n title: tr('notifications.allNotifications', 'All notifications'),\n description: tr(\n 'notifications.allNotificationsDescription',\n 'Master preference for notification delivery across all channels and types.'\n ),\n })}\n </section>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.channelPreferences', 'Channels')}\n </h2>\n <div className=\"grid gap-3 lg:grid-cols-2\">\n {CHANNEL_OPTIONS.map((channel) =>\n renderPreferenceRow({\n key: `CHANNEL:${channel.value}`,\n scope: 'CHANNEL',\n channel: channel.value,\n title: tr(channel.labelKey, channel.label),\n description: tr(\n 'notifications.channelPreferenceDescription',\n 'Control delivery for this channel.'\n ),\n })\n )}\n </div>\n </section>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.typePreferences', 'Notification Types')}\n </h2>\n <div className=\"grid gap-3 lg:grid-cols-2\">\n {TYPE_OPTIONS.map((type) =>\n renderPreferenceRow({\n key: `TYPE:${type.value}`,\n scope: 'TYPE',\n type: type.value,\n title: tr(type.labelKey, type.label),\n description: tr(\n 'notifications.typePreferenceDescription',\n 'Control delivery for this notification type.'\n ),\n })\n )}\n </div>\n </section>\n\n <div className=\"relative max-w-xl\">\n <Search size={16} className=\"absolute left-3 top-1/2 -translate-y-1/2 text-tertiary\" />\n <input\n type=\"text\"\n value={search}\n onChange={(event) => setSearch(event.target.value)}\n aria-label={tr('notifications.searchTopics', 'Search topics...')}\n placeholder={tr('notifications.searchTopics', 'Search topics...')}\n className=\"w-full rounded-lg border border-default bg-surface py-2 pl-9 pr-4 text-sm text-primary focus:outline-none focus:ring-2 focus:ring-accent\"\n />\n </div>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.topicPreferences', 'Topics')}\n </h2>\n {isLoading ? (\n <div className=\"rounded-lg border border-default bg-surface p-6 text-sm text-secondary\">\n {tr('notifications.loadingPreferences', 'Loading preferences...')}\n </div>\n ) : filteredTopics.length === 0 ? (\n <div className=\"rounded-lg border border-default bg-surface p-6 text-sm text-secondary\">\n {tr('notifications.noTopicsFound', 'No promotional topics available right now.')}\n </div>\n ) : (\n filteredTopics.map((topic) =>\n renderPreferenceRow({\n key: `TOPIC:${topic.id}`,\n scope: 'TOPIC',\n topicId: topic.id,\n title: topic.name,\n description: topic.description || topic.slug,\n })\n )\n )}\n </section>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAUA,IAAM,IAA0F;CAC9F;EAAE,OAAO;EAAU,UAAU;EAA8B,OAAO;EAAU;CAC5E;EAAE,OAAO;EAAS,UAAU;EAA8B,OAAO;EAAS;CAC1E;EAAE,OAAO;EAAQ,UAAU;EAA6B,OAAO;EAAQ;CACvE;EAAE,OAAO;EAAO,UAAU;EAA4B,OAAO;EAAO;CACpE;EAAE,OAAO;EAAY,UAAU;EAAiC,OAAO;EAAY;CACnF;EAAE,OAAO;EAAS,UAAU;EAA8B,OAAO;EAAS;CAC3E,EAEK,IAAoF;CACxF;EAAE,OAAO;EAAiB,UAAU;EAAmC,OAAO;EAAiB;CAC/F;EAAE,OAAO;EAAU,UAAU;EAA4B,OAAO;EAAU;CAC1E;EAAE,OAAO;EAAS,UAAU;EAA2B,OAAO;EAAU;CACxE;EAAE,OAAO;EAAa,UAAU;EAA+B,OAAO;EAAa;CACpF;AAED,SAAS,EAAc,GAKpB;AAID,QAHI,EAAM,UAAU,YAAkB,WAAW,EAAM,WAAW,OAC9D,EAAM,UAAU,SAAe,QAAQ,EAAM,QAAQ,OACrD,EAAM,UAAU,UAAgB,SAAS,EAAM,WAAW,OACvD;;AAGT,SAAgB,IAA8B;CAC5C,I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jE,WAAU;KACV,CAAA,CACE;;GAEN,kBAAC,WAAD;IAAS,WAAU;cAAnB,CACE,kBAAC,MAAD;KAAI,WAAU;eACX,EAAG,kCAAkC,SAAS;KAC5C,CAAA,EACJ,IACC,kBAAC,OAAD;KAAK,WAAU;eACZ,EAAG,oCAAoC,yBAAyB;KAC7D,CAAA,GACJ,EAAe,WAAW,IAC5B,kBAAC,OAAD;KAAK,WAAU;eACZ,EAAG,+BAA+B,6CAA6C;KAC5E,CAAA,GAEN,EAAe,KAAK,MAClB,EAAoB;KAClB,KAAK,SAAS,EAAM;KACpB,OAAO;KACP,SAAS,EAAM;KACf,OAAO,EAAM;KACb,aAAa,EAAM,eAAe,EAAM;KACzC,CAAC,CACH,CAEK;;GACN"}
|
|
1
|
+
{"version":3,"file":"NotificationPreferencesPage.js","names":[],"sources":["../../src/pages/NotificationPreferencesPage.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { BellRing, Search, ToggleLeft, ToggleRight } from 'lucide-react';\nimport { usePermissions } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { useNotificationPreferences, useNotificationTopics } from '../hooks';\nimport { useNotificationAnalytics } from '../hooks/useNotificationAnalytics';\nimport { NOTIFICATION_PERMISSIONS } from '../constants/permissions';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { useTr } from '../shared/hooks/useTr';\nimport type { NotificationChannel, NotificationPreferenceScope, NotificationType } from '../types';\nimport { nativeImpact, nativeNotify } from '../utils/nativeBridge';\n\nconst CHANNEL_OPTIONS: Array<{ value: NotificationChannel; labelKey: string; label: string }> = [\n { value: 'IN_APP', labelKey: 'notifications.channelInApp', label: 'In-app' },\n { value: 'EMAIL', labelKey: 'notifications.channelEmail', label: 'Email' },\n { value: 'PUSH', labelKey: 'notifications.channelPush', label: 'Push' },\n { value: 'SMS', labelKey: 'notifications.channelSms', label: 'SMS' },\n { value: 'WHATSAPP', labelKey: 'notifications.channelWhatsapp', label: 'WhatsApp' },\n { value: 'SLACK', labelKey: 'notifications.channelSlack', label: 'Slack' },\n];\n\nconst TYPE_OPTIONS: Array<{ value: NotificationType; labelKey: string; label: string }> = [\n { value: 'TRANSACTIONAL', labelKey: 'notifications.typeTransactional', label: 'Transactional' },\n { value: 'SYSTEM', labelKey: 'notifications.typeSystem', label: 'System' },\n { value: 'ALERT', labelKey: 'notifications.typeAlert', label: 'Alerts' },\n { value: 'MARKETING', labelKey: 'notifications.typeMarketing', label: 'Marketing' },\n];\n\nfunction preferenceKey(input: {\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n}) {\n if (input.scope === 'CHANNEL') return `CHANNEL:${input.channel || ''}`;\n if (input.scope === 'TYPE') return `TYPE:${input.type || ''}`;\n if (input.scope === 'TOPIC') return `TOPIC:${input.topicId || ''}`;\n return 'GLOBAL';\n}\n\nexport function NotificationPreferencesPage() {\n const tr = useTr();\n const { hasPermission, isLoading: permissionsLoading } = usePermissions();\n const { currentUser } = useNotification();\n const { topics, isLoading: topicsLoading } = useNotificationTopics({\n type: 'MARKETING',\n isActive: true,\n });\n const {\n preferencesByKey,\n isLoading: preferencesLoading,\n setPreference,\n deletePreference,\n } = useNotificationPreferences();\n const { trackPreferenceUpdated } = useNotificationAnalytics();\n const [search, setSearch] = useState('');\n const [savingKey, setSavingKey] = useState<string | null>(null);\n const [saveFeedback, setSaveFeedback] = useState<{\n key: string;\n type: 'success' | 'error';\n message: string;\n } | null>(null);\n const feedbackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n const isLoading = topicsLoading || preferencesLoading;\n\n useEffect(() => {\n return () => {\n if (feedbackTimerRef.current) {\n clearTimeout(feedbackTimerRef.current);\n }\n };\n }, []);\n\n const showSaveFeedback = (feedback: {\n key: string;\n type: 'success' | 'error';\n message: string;\n }) => {\n if (feedbackTimerRef.current) {\n clearTimeout(feedbackTimerRef.current);\n }\n\n setSaveFeedback(feedback);\n feedbackTimerRef.current = setTimeout(() => {\n setSaveFeedback((current) => (current?.key === feedback.key ? null : current));\n feedbackTimerRef.current = null;\n }, 2500);\n };\n\n const filteredTopics = useMemo(() => {\n if (!search.trim()) {\n return topics;\n }\n\n const query = search.toLowerCase();\n return topics.filter(\n (topic) =>\n topic.name.toLowerCase().includes(query) ||\n topic.slug.toLowerCase().includes(query) ||\n topic.description?.toLowerCase().includes(query)\n );\n }, [search, topics]);\n\n const togglePreference = async (input: {\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n }) => {\n const key = preferenceKey(input);\n const existing = preferencesByKey.get(key);\n const nextEnabled = !(existing?.enabled ?? true);\n setSavingKey(key);\n nativeImpact('medium');\n try {\n await setPreference({\n ...input,\n enabled: nextEnabled,\n frequency: existing?.frequency || 'IMMEDIATE',\n });\n trackPreferenceUpdated({\n action: 'set',\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n enabled: nextEnabled,\n });\n showSaveFeedback({\n key,\n type: 'success',\n message: tr('notifications.preferenceSaved', 'Preference saved.'),\n });\n void nativeNotify('success');\n } catch {\n showSaveFeedback({\n key,\n type: 'error',\n message: tr('notifications.preferenceSaveFailed', 'Could not save preference.'),\n });\n void nativeNotify('error');\n } finally {\n setSavingKey(null);\n }\n };\n\n const resetPreference = async (key: string) => {\n const existing = preferencesByKey.get(key);\n if (!existing) return;\n setSavingKey(key);\n try {\n await deletePreference(existing.id);\n trackPreferenceUpdated({\n action: 'reset',\n scope: existing.scope,\n channel: existing.channel,\n type: existing.type,\n });\n showSaveFeedback({\n key,\n type: 'success',\n message: tr('notifications.preferenceReset', 'Preference reset.'),\n });\n } catch {\n showSaveFeedback({\n key,\n type: 'error',\n message: tr('notifications.preferenceResetFailed', 'Could not reset preference.'),\n });\n } finally {\n setSavingKey(null);\n }\n };\n\n const renderPreferenceRow = (input: {\n key: string;\n title: string;\n description: string;\n scope: NotificationPreferenceScope;\n channel?: NotificationChannel;\n type?: NotificationType;\n topicId?: string;\n }) => {\n const existing = preferencesByKey.get(input.key);\n const isEnabled = existing?.enabled ?? true;\n const isSaving = savingKey === input.key;\n const feedback = saveFeedback?.key === input.key ? saveFeedback : null;\n\n return (\n <div key={input.key} className=\"rounded-lg border border-default bg-surface p-4 shadow-sm\">\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n <div className=\"space-y-1\">\n <div className=\"flex items-center gap-2\">\n <BellRing size={16} className=\"text-accent-primary\" />\n <h2 className=\"text-sm font-semibold text-primary\">{input.title}</h2>\n {existing && (\n <span className=\"rounded-full bg-muted px-2 py-0.5 text-xs text-secondary\">\n {existing.frequency.replace('_', ' ').toLowerCase()}\n </span>\n )}\n </div>\n <p className=\"text-sm text-secondary\">{input.description}</p>\n </div>\n\n <div className=\"flex items-center gap-2\">\n {existing && (\n <button\n type=\"button\"\n disabled={isSaving}\n onClick={() => resetPreference(input.key)}\n className=\"rounded-md border border-default px-3 py-2 text-sm text-secondary hover:bg-muted disabled:cursor-not-allowed disabled:opacity-50\"\n >\n {tr('notifications.reset', 'Reset')}\n </button>\n )}\n <button\n type=\"button\"\n aria-pressed={isEnabled}\n disabled={isSaving}\n onClick={() =>\n togglePreference({\n scope: input.scope,\n channel: input.channel,\n type: input.type,\n topicId: input.topicId,\n })\n }\n className={`inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm font-medium transition-colors ${\n isEnabled\n ? 'border-accent-primary bg-action-primary-bg text-text-inverse hover:opacity-90'\n : 'border-default bg-muted text-secondary hover:bg-muted/80'\n } disabled:cursor-not-allowed disabled:opacity-50`}\n >\n {isEnabled ? <ToggleRight size={18} /> : <ToggleLeft size={18} />}\n {isSaving\n ? tr('notifications.saving', 'Saving...')\n : isEnabled\n ? tr('notifications.enabled', 'Enabled')\n : tr('notifications.disabled', 'Disabled')}\n </button>\n </div>\n </div>\n <div className=\"mt-3 min-h-5\" aria-live=\"polite\">\n {feedback && (\n <p className={`text-xs ${feedback.type === 'success' ? 'text-success' : 'text-error'}`}>\n {feedback.message}\n </p>\n )}\n </div>\n </div>\n );\n };\n\n if (permissionsLoading) {\n return (\n <div className=\"flex h-64 items-center justify-center\">\n <div className=\"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent\" />\n </div>\n );\n }\n\n if (!hasPermission(NOTIFICATION_PERMISSIONS.NOTIFICATION_LIST) && !currentUser?.id) {\n return (\n <div className=\"p-8 text-center text-text-secondary\">\n {tr(\n 'notifications.noPermissionPreferences',\n \"You don't have permission to manage notification preferences.\"\n )}\n </div>\n );\n }\n\n return (\n <div className=\"space-y-6 p-4 sm:p-6\">\n <div>\n <h1 className=\"text-2xl font-bold text-primary\">\n {tr('notifications.preferencesTitle', 'Notification Preferences')}\n </h1>\n <p className=\"mt-1 text-sm text-secondary\">\n {tr(\n 'notifications.preferencesSubtitle',\n 'Control global, channel, type, and topic-level notification delivery.'\n )}\n </p>\n </div>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.globalPreferences', 'Global')}\n </h2>\n {renderPreferenceRow({\n key: 'GLOBAL',\n scope: 'GLOBAL',\n title: tr('notifications.allNotifications', 'All notifications'),\n description: tr(\n 'notifications.allNotificationsDescription',\n 'Master preference for notification delivery across all channels and types.'\n ),\n })}\n </section>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.channelPreferences', 'Channels')}\n </h2>\n <div className=\"grid gap-3 lg:grid-cols-2\">\n {CHANNEL_OPTIONS.map((channel) =>\n renderPreferenceRow({\n key: `CHANNEL:${channel.value}`,\n scope: 'CHANNEL',\n channel: channel.value,\n title: tr(channel.labelKey, channel.label),\n description: tr(\n 'notifications.channelPreferenceDescription',\n 'Control delivery for this channel.'\n ),\n })\n )}\n </div>\n </section>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.typePreferences', 'Notification Types')}\n </h2>\n <div className=\"grid gap-3 lg:grid-cols-2\">\n {TYPE_OPTIONS.map((type) =>\n renderPreferenceRow({\n key: `TYPE:${type.value}`,\n scope: 'TYPE',\n type: type.value,\n title: tr(type.labelKey, type.label),\n description: tr(\n 'notifications.typePreferenceDescription',\n 'Control delivery for this notification type.'\n ),\n })\n )}\n </div>\n </section>\n\n <div className=\"relative max-w-xl\">\n <Search size={16} className=\"absolute left-3 top-1/2 -translate-y-1/2 text-tertiary\" />\n <input\n type=\"text\"\n value={search}\n onChange={(event) => setSearch(event.target.value)}\n aria-label={tr('notifications.searchTopics', 'Search topics...')}\n placeholder={tr('notifications.searchTopics', 'Search topics...')}\n className=\"w-full rounded-lg border border-default bg-surface py-2 pl-9 pr-4 text-sm text-primary focus:outline-none focus:ring-2 focus:ring-accent\"\n />\n </div>\n\n <section className=\"space-y-3\">\n <h2 className=\"text-sm font-semibold uppercase tracking-wide text-tertiary\">\n {tr('notifications.topicPreferences', 'Topics')}\n </h2>\n {isLoading ? (\n <div className=\"rounded-lg border border-default bg-surface p-6 text-sm text-secondary\">\n {tr('notifications.loadingPreferences', 'Loading preferences...')}\n </div>\n ) : filteredTopics.length === 0 ? (\n <div className=\"rounded-lg border border-default bg-surface p-6 text-sm text-secondary\">\n {tr('notifications.noTopicsFound', 'No promotional topics available right now.')}\n </div>\n ) : (\n filteredTopics.map((topic) =>\n renderPreferenceRow({\n key: `TOPIC:${topic.id}`,\n scope: 'TOPIC',\n topicId: topic.id,\n title: topic.name,\n description: topic.description || topic.slug,\n })\n )\n )}\n </section>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,IAAM,IAA0F;CAC9F;EAAE,OAAO;EAAU,UAAU;EAA8B,OAAO;EAAU;CAC5E;EAAE,OAAO;EAAS,UAAU;EAA8B,OAAO;EAAS;CAC1E;EAAE,OAAO;EAAQ,UAAU;EAA6B,OAAO;EAAQ;CACvE;EAAE,OAAO;EAAO,UAAU;EAA4B,OAAO;EAAO;CACpE;EAAE,OAAO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MAClB,OAAO;MACP,MAAM,EAAK;MACX,OAAO,EAAG,EAAK,UAAU,EAAK,MAAM;MACpC,aAAa,EACX,2CACA,+CACD;MACF,CAAC,CACH;KACG,CAAA,CACE;;GAEV,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,GAAD;KAAQ,MAAM;KAAI,WAAU;KAA2D,CAAA,EACvF,kBAAC,SAAD;KACE,MAAK;KACL,OAAO;KACP,WAAW,MAAU,EAAU,EAAM,OAAO,MAAM;KAClD,cAAY,EAAG,8BAA8B,mBAAmB;KAChE,aAAa,EAAG,8BAA8B,mBAAmB;KACjE,WAAU;KACV,CAAA,CACE;;GAEN,kBAAC,WAAD;IAAS,WAAU;cAAnB,CACE,kBAAC,MAAD;KAAI,WAAU;eACX,EAAG,kCAAkC,SAAS;KAC5C,CAAA,EACJ,IACC,kBAAC,OAAD;KAAK,WAAU;eACZ,EAAG,oCAAoC,yBAAyB;KAC7D,CAAA,GACJ,EAAe,WAAW,IAC5B,kBAAC,OAAD;KAAK,WAAU;eACZ,EAAG,+BAA+B,6CAA6C;KAC5E,CAAA,GAEN,EAAe,KAAK,MAClB,EAAoB;KAClB,KAAK,SAAS,EAAM;KACpB,OAAO;KACP,SAAS,EAAM;KACf,OAAO,EAAM;KACb,aAAa,EAAM,eAAe,EAAM;KACzC,CAAC,CACH,CAEK;;GACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEditorPage.d.ts","sourceRoot":"","sources":["../../src/pages/TemplateEditorPage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TemplateEditorPage.d.ts","sourceRoot":"","sources":["../../src/pages/TemplateEditorPage.tsx"],"names":[],"mappings":"AAmKA;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,4CAi1BjC"}
|