@burdenoff/microfe-notification 2026.424.101

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.
Files changed (161) hide show
  1. package/README.md +376 -0
  2. package/dist/AdminNotificationRoot.d.ts +35 -0
  3. package/dist/AdminNotificationRoot.d.ts.map +1 -0
  4. package/dist/AdminNotificationRoot.js +81 -0
  5. package/dist/AdminNotificationRoot.js.map +1 -0
  6. package/dist/AdminNotificationRoutes.d.ts +2 -0
  7. package/dist/AdminNotificationRoutes.d.ts.map +1 -0
  8. package/dist/AdminNotificationRoutes.js +108 -0
  9. package/dist/AdminNotificationRoutes.js.map +1 -0
  10. package/dist/NotificationRoot.d.ts +31 -0
  11. package/dist/NotificationRoot.d.ts.map +1 -0
  12. package/dist/NotificationRoot.js +81 -0
  13. package/dist/NotificationRoot.js.map +1 -0
  14. package/dist/NotificationRoutes.d.ts +17 -0
  15. package/dist/NotificationRoutes.d.ts.map +1 -0
  16. package/dist/NotificationRoutes.js +67 -0
  17. package/dist/NotificationRoutes.js.map +1 -0
  18. package/dist/UserNotificationRoot.d.ts +34 -0
  19. package/dist/UserNotificationRoot.d.ts.map +1 -0
  20. package/dist/UserNotificationRoot.js +64 -0
  21. package/dist/UserNotificationRoot.js.map +1 -0
  22. package/dist/UserNotificationRoutes.d.ts +15 -0
  23. package/dist/UserNotificationRoutes.d.ts.map +1 -0
  24. package/dist/UserNotificationRoutes.js +52 -0
  25. package/dist/UserNotificationRoutes.js.map +1 -0
  26. package/dist/__tests__/setup.d.ts +2 -0
  27. package/dist/__tests__/setup.d.ts.map +1 -0
  28. package/dist/components/NotificationBell.d.ts +14 -0
  29. package/dist/components/NotificationBell.d.ts.map +1 -0
  30. package/dist/components/NotificationBell.js +47 -0
  31. package/dist/components/NotificationBell.js.map +1 -0
  32. package/dist/components/NotificationCard.d.ts +19 -0
  33. package/dist/components/NotificationCard.d.ts.map +1 -0
  34. package/dist/components/NotificationCard.js +112 -0
  35. package/dist/components/NotificationCard.js.map +1 -0
  36. package/dist/components/NotificationPanel.d.ts +11 -0
  37. package/dist/components/NotificationPanel.d.ts.map +1 -0
  38. package/dist/components/NotificationPanel.js +100 -0
  39. package/dist/components/NotificationPanel.js.map +1 -0
  40. package/dist/components/RecipientSelector.d.ts +34 -0
  41. package/dist/components/RecipientSelector.d.ts.map +1 -0
  42. package/dist/components/RecipientSelector.js +212 -0
  43. package/dist/components/RecipientSelector.js.map +1 -0
  44. package/dist/components/TemplatePreview.d.ts +22 -0
  45. package/dist/components/TemplatePreview.d.ts.map +1 -0
  46. package/dist/components/TemplatePreview.js +425 -0
  47. package/dist/components/TemplatePreview.js.map +1 -0
  48. package/dist/components/VariableInserter.d.ts +12 -0
  49. package/dist/components/VariableInserter.d.ts.map +1 -0
  50. package/dist/components/index.d.ts +4 -0
  51. package/dist/components/index.d.ts.map +1 -0
  52. package/dist/components/index.js +3 -0
  53. package/dist/constants/permissions.d.ts +24 -0
  54. package/dist/constants/permissions.d.ts.map +1 -0
  55. package/dist/constants/permissions.js +17 -0
  56. package/dist/constants/permissions.js.map +1 -0
  57. package/dist/dev/main.d.ts +2 -0
  58. package/dist/dev/main.d.ts.map +1 -0
  59. package/dist/generated/global-operations.d.ts +1408 -0
  60. package/dist/generated/global-operations.d.ts.map +1 -0
  61. package/dist/generated/global-operations.js +514 -0
  62. package/dist/generated/global-operations.js.map +1 -0
  63. package/dist/generated/global-types.d.ts +20773 -0
  64. package/dist/generated/global-types.d.ts.map +1 -0
  65. package/dist/generated/wspace-operations.d.ts +2 -0
  66. package/dist/generated/wspace-operations.d.ts.map +1 -0
  67. package/dist/generated/wspace-types.d.ts +53363 -0
  68. package/dist/generated/wspace-types.d.ts.map +1 -0
  69. package/dist/graphql/global-client.d.ts +19 -0
  70. package/dist/graphql/global-client.d.ts.map +1 -0
  71. package/dist/graphql/global-client.js +57 -0
  72. package/dist/graphql/global-client.js.map +1 -0
  73. package/dist/hooks/index.d.ts +6 -0
  74. package/dist/hooks/index.d.ts.map +1 -0
  75. package/dist/hooks/index.js +5 -0
  76. package/dist/hooks/useNotificationAdmin.d.ts +51 -0
  77. package/dist/hooks/useNotificationAdmin.d.ts.map +1 -0
  78. package/dist/hooks/useNotificationAdmin.js +203 -0
  79. package/dist/hooks/useNotificationAdmin.js.map +1 -0
  80. package/dist/hooks/useNotificationTemplates.d.ts +136 -0
  81. package/dist/hooks/useNotificationTemplates.d.ts.map +1 -0
  82. package/dist/hooks/useNotificationTemplates.js +168 -0
  83. package/dist/hooks/useNotificationTemplates.js.map +1 -0
  84. package/dist/hooks/useNotificationTopics.d.ts +36 -0
  85. package/dist/hooks/useNotificationTopics.d.ts.map +1 -0
  86. package/dist/hooks/useNotificationTopics.js +127 -0
  87. package/dist/hooks/useNotificationTopics.js.map +1 -0
  88. package/dist/hooks/useNotifications.d.ts +36 -0
  89. package/dist/hooks/useNotifications.d.ts.map +1 -0
  90. package/dist/hooks/useNotifications.js +289 -0
  91. package/dist/hooks/useNotifications.js.map +1 -0
  92. package/dist/hooks/useSendNotification.d.ts +159 -0
  93. package/dist/hooks/useSendNotification.d.ts.map +1 -0
  94. package/dist/hooks/useSendNotification.js +123 -0
  95. package/dist/hooks/useSendNotification.js.map +1 -0
  96. package/dist/hooks/useUserSearch.d.ts +27 -0
  97. package/dist/hooks/useUserSearch.d.ts.map +1 -0
  98. package/dist/hooks/useUserSearch.js +76 -0
  99. package/dist/hooks/useUserSearch.js.map +1 -0
  100. package/dist/index.d.ts +37 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +13 -0
  103. package/dist/pages/CreateNotificationPage.d.ts +6 -0
  104. package/dist/pages/CreateNotificationPage.d.ts.map +1 -0
  105. package/dist/pages/CreateNotificationPage.js +1366 -0
  106. package/dist/pages/CreateNotificationPage.js.map +1 -0
  107. package/dist/pages/NotificationCenterPage.d.ts +7 -0
  108. package/dist/pages/NotificationCenterPage.d.ts.map +1 -0
  109. package/dist/pages/NotificationCenterPage.js +203 -0
  110. package/dist/pages/NotificationCenterPage.js.map +1 -0
  111. package/dist/pages/NotificationHistoryAdminPage.d.ts +3 -0
  112. package/dist/pages/NotificationHistoryAdminPage.d.ts.map +1 -0
  113. package/dist/pages/NotificationHistoryAdminPage.js +484 -0
  114. package/dist/pages/NotificationHistoryAdminPage.js.map +1 -0
  115. package/dist/pages/NotificationHistoryPage.d.ts +3 -0
  116. package/dist/pages/NotificationHistoryPage.d.ts.map +1 -0
  117. package/dist/pages/NotificationHistoryPage.js +136 -0
  118. package/dist/pages/NotificationHistoryPage.js.map +1 -0
  119. package/dist/pages/NotificationLandingPage.d.ts +11 -0
  120. package/dist/pages/NotificationLandingPage.d.ts.map +1 -0
  121. package/dist/pages/NotificationLandingPage.js +85 -0
  122. package/dist/pages/NotificationLandingPage.js.map +1 -0
  123. package/dist/pages/NotificationPreferencesPage.d.ts +2 -0
  124. package/dist/pages/NotificationPreferencesPage.d.ts.map +1 -0
  125. package/dist/pages/NotificationPreferencesPage.js +108 -0
  126. package/dist/pages/NotificationPreferencesPage.js.map +1 -0
  127. package/dist/pages/NotificationTemplatesPage.d.ts +8 -0
  128. package/dist/pages/NotificationTemplatesPage.d.ts.map +1 -0
  129. package/dist/pages/NotificationTemplatesPage.js +310 -0
  130. package/dist/pages/NotificationTemplatesPage.js.map +1 -0
  131. package/dist/pages/NotificationTopicsPage.d.ts +2 -0
  132. package/dist/pages/NotificationTopicsPage.d.ts.map +1 -0
  133. package/dist/pages/NotificationTopicsPage.js +254 -0
  134. package/dist/pages/NotificationTopicsPage.js.map +1 -0
  135. package/dist/pages/TemplateEditorPage.d.ts +13 -0
  136. package/dist/pages/TemplateEditorPage.d.ts.map +1 -0
  137. package/dist/pages/TemplateEditorPage.js +790 -0
  138. package/dist/pages/TemplateEditorPage.js.map +1 -0
  139. package/dist/providers/NotificationProvider.d.ts +19 -0
  140. package/dist/providers/NotificationProvider.d.ts.map +1 -0
  141. package/dist/providers/NotificationProvider.js +35 -0
  142. package/dist/providers/NotificationProvider.js.map +1 -0
  143. package/dist/shared/hooks/useTr.d.ts +14 -0
  144. package/dist/shared/hooks/useTr.d.ts.map +1 -0
  145. package/dist/shared/hooks/useTr.js +14 -0
  146. package/dist/shared/hooks/useTr.js.map +1 -0
  147. package/dist/store/notificationStore.d.ts +32 -0
  148. package/dist/store/notificationStore.d.ts.map +1 -0
  149. package/dist/store/notificationStore.js +124 -0
  150. package/dist/store/notificationStore.js.map +1 -0
  151. package/dist/types/index.d.ts +215 -0
  152. package/dist/types/index.d.ts.map +1 -0
  153. package/dist/utils/index.d.ts +68 -0
  154. package/dist/utils/index.d.ts.map +1 -0
  155. package/dist/utils/index.js +122 -0
  156. package/dist/utils/index.js.map +1 -0
  157. package/dist/utils/notificationHistoryExport.d.ts +13 -0
  158. package/dist/utils/notificationHistoryExport.d.ts.map +1 -0
  159. package/dist/utils/notificationHistoryExport.js +29 -0
  160. package/dist/utils/notificationHistoryExport.js.map +1 -0
  161. package/package.json +115 -0
@@ -0,0 +1,310 @@
1
+ import { useTr as e } from "../shared/hooks/useTr.js";
2
+ import { NOTIFICATION_PERMISSIONS as t } from "../constants/permissions.js";
3
+ import { useNotificationTemplates as n } from "../hooks/useNotificationTemplates.js";
4
+ import { useMemo as r, useState as i } from "react";
5
+ import { AlertCircle as a, FileText as o, Loader2 as s, Plus as c, RefreshCw as l, Search as u, Trash2 as d } from "lucide-react";
6
+ import { useNavigate as f } from "react-router-dom";
7
+ import { usePermissions as p } from "@burdenoff/fe-libs/shared/providers/shell";
8
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
9
+ import { useI18n as g } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
10
+ //#region src/pages/NotificationTemplatesPage.tsx
11
+ var _ = {
12
+ TRANSACTIONAL: "text-status-info-text bg-status-info-bg-subtle border-status-info-bg-subtle",
13
+ MARKETING: "text-accent-purple bg-accent-purple-subtle border-accent-purple-subtle",
14
+ SYSTEM: "text-status-warning-text bg-status-warning-bg-subtle border-status-warning-bg-subtle",
15
+ ALERT: "text-status-error-text bg-status-error-bg-subtle border-status-error-bg-subtle"
16
+ }, v = {
17
+ TRANSACTIONAL: "Transactional",
18
+ MARKETING: "Marketing",
19
+ SYSTEM: "System",
20
+ ALERT: "Alert"
21
+ };
22
+ function y(e, t) {
23
+ return new Date(e).toLocaleDateString(t || "en-US", {
24
+ month: "short",
25
+ day: "numeric",
26
+ year: "numeric"
27
+ });
28
+ }
29
+ function b() {
30
+ let b = f(), x = e(), { locale: S } = g(), { hasPermission: C, isLoading: w } = p(), { templates: T, isLoading: E, isDeleting: D, error: O, total: k, hasMore: A, filter: j, refetch: M, loadMore: N, deleteTemplate: P, updateFilter: F } = n(), [I, L] = i(null), [R, z] = i(null), [B, V] = i(/* @__PURE__ */ new Set()), H = r(() => T.filter((e) => B.has(e.id)), [B, T]), U = T.length > 0 && T.every((e) => B.has(e.id)), W = T.some((e) => B.has(e.id)) && !U, G = C(t.TEMPLATE_CREATE), K = C(t.TEMPLATE_DELETE), q = async (e, t) => {
31
+ if (e.stopPropagation(), confirm(x("notifTemplates.confirmDelete", `Delete template "${t.name}"? This cannot be undone.`))) {
32
+ L(t.id), z(null);
33
+ try {
34
+ await P(t.id);
35
+ } catch (e) {
36
+ z(e instanceof Error ? e.message : x("notifTemplates.deleteFailed", "Failed to delete template"));
37
+ } finally {
38
+ L(null);
39
+ }
40
+ }
41
+ }, J = async () => {
42
+ H.length !== 0 && window.confirm(x("notifTemplates.confirmBulkDelete", `Delete ${H.length} selected template${H.length === 1 ? "" : "s"}? This cannot be undone.`)) && (z(null), await Promise.allSettled(H.map((e) => P(e.id))), V(/* @__PURE__ */ new Set()));
43
+ }, Y = (e, t) => {
44
+ V((n) => {
45
+ let r = new Set(n);
46
+ return t ? r.add(e) : r.delete(e), r;
47
+ });
48
+ }, X = (e) => {
49
+ V((t) => {
50
+ let n = new Set(t);
51
+ return T.forEach((t) => {
52
+ e ? n.add(t.id) : n.delete(t.id);
53
+ }), n;
54
+ });
55
+ };
56
+ return w ? /* @__PURE__ */ m("div", {
57
+ className: "flex h-64 items-center justify-center",
58
+ children: /* @__PURE__ */ m("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
59
+ }) : C(t.TEMPLATE_LIST) || G || K || C(t.TEMPLATE_UPDATE) ? E && T.length === 0 ? /* @__PURE__ */ h("div", {
60
+ className: "flex flex-col items-center justify-center h-64 gap-3",
61
+ children: [/* @__PURE__ */ m(s, {
62
+ size: 28,
63
+ className: "animate-spin text-accent-primary"
64
+ }), /* @__PURE__ */ m("p", {
65
+ className: "text-sm text-secondary",
66
+ children: x("notifTemplates.loading", "Loading templates...")
67
+ })]
68
+ }) : O && T.length === 0 ? /* @__PURE__ */ h("div", {
69
+ className: "flex flex-col items-center justify-center h-64 gap-4",
70
+ children: [
71
+ /* @__PURE__ */ m(a, {
72
+ size: 28,
73
+ className: "text-error"
74
+ }),
75
+ /* @__PURE__ */ m("p", {
76
+ className: "text-sm text-error",
77
+ children: O
78
+ }),
79
+ /* @__PURE__ */ h("button", {
80
+ onClick: M,
81
+ className: "flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-accent-primary/90 rounded-lg transition-all duration-150",
82
+ children: [/* @__PURE__ */ m(l, { size: 14 }), x("notifTemplates.retry", "Retry")]
83
+ })
84
+ ]
85
+ }) : /* @__PURE__ */ h("div", {
86
+ className: "space-y-4 sm:space-y-6 p-3 sm:p-6 animate-in fade-in duration-300",
87
+ children: [
88
+ /* @__PURE__ */ h("div", {
89
+ className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",
90
+ children: [/* @__PURE__ */ h("div", { children: [/* @__PURE__ */ m("h1", {
91
+ className: "text-xl sm:text-2xl font-bold text-primary",
92
+ children: x("notifTemplates.title", "Notification Templates")
93
+ }), /* @__PURE__ */ h("p", {
94
+ className: "text-sm text-secondary mt-1",
95
+ children: [
96
+ k,
97
+ " ",
98
+ x("notifTemplates.templateCount", "template"),
99
+ k === 1 ? "" : "s",
100
+ " ",
101
+ x("notifTemplates.total", "total")
102
+ ]
103
+ })] }), G && /* @__PURE__ */ h("button", {
104
+ onClick: () => b("new"),
105
+ className: "flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-accent-primary/90 rounded-lg transition-all duration-150 hover:shadow-md",
106
+ children: [/* @__PURE__ */ m(c, { size: 16 }), x("notifTemplates.createTemplate", "Create Template")]
107
+ })]
108
+ }),
109
+ /* @__PURE__ */ h("div", {
110
+ className: "flex flex-col gap-3 sm:flex-row sm:items-center",
111
+ children: [/* @__PURE__ */ h("div", {
112
+ className: "relative flex-1",
113
+ children: [/* @__PURE__ */ m(u, {
114
+ size: 16,
115
+ className: "absolute left-3 top-1/2 -translate-y-1/2 text-tertiary"
116
+ }), /* @__PURE__ */ m("input", {
117
+ type: "text",
118
+ value: j.search || "",
119
+ onChange: (e) => F({ search: e.target.value }),
120
+ placeholder: x("notifTemplates.searchPlaceholder", "Search templates..."),
121
+ className: "w-full pl-9 pr-4 py-2 text-sm text-primary bg-surface border border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent transition-shadow duration-150"
122
+ })]
123
+ }), /* @__PURE__ */ h("select", {
124
+ value: j.type || "",
125
+ onChange: (e) => F({ type: e.target.value || void 0 }),
126
+ className: "px-3 py-2 text-sm text-primary bg-surface border border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent transition-shadow duration-150",
127
+ children: [
128
+ /* @__PURE__ */ m("option", {
129
+ value: "",
130
+ children: x("notifTemplates.allTypes", "All Types")
131
+ }),
132
+ /* @__PURE__ */ m("option", {
133
+ value: "TRANSACTIONAL",
134
+ children: x("notifTemplates.typeTransactional", "Transactional")
135
+ }),
136
+ /* @__PURE__ */ m("option", {
137
+ value: "MARKETING",
138
+ children: x("notifTemplates.typeMarketing", "Marketing")
139
+ }),
140
+ /* @__PURE__ */ m("option", {
141
+ value: "SYSTEM",
142
+ children: x("notifTemplates.typeSystem", "System")
143
+ }),
144
+ /* @__PURE__ */ m("option", {
145
+ value: "ALERT",
146
+ children: x("notifTemplates.typeAlert", "Alert")
147
+ })
148
+ ]
149
+ })]
150
+ }),
151
+ T.length > 0 && /* @__PURE__ */ h("div", {
152
+ className: "flex flex-col gap-3 rounded-lg border border-default bg-surface p-4 sm:flex-row sm:items-center sm:justify-between",
153
+ children: [/* @__PURE__ */ h("label", {
154
+ className: "flex items-center gap-2 text-sm text-primary",
155
+ children: [/* @__PURE__ */ m("input", {
156
+ type: "checkbox",
157
+ checked: U,
158
+ ref: (e) => {
159
+ e && (e.indeterminate = W && !U);
160
+ },
161
+ onChange: (e) => X(e.target.checked),
162
+ "aria-label": x("notifTemplates.selectAllVisibleAria", "Select all notification templates"),
163
+ className: "h-4 w-4 rounded border-default text-accent-primary"
164
+ }), /* @__PURE__ */ m("span", { children: x("notifTemplates.selectAllVisible", "Select all visible") })]
165
+ }), /* @__PURE__ */ h("div", {
166
+ className: "flex items-center gap-2",
167
+ children: [
168
+ /* @__PURE__ */ h("span", {
169
+ className: "text-sm text-secondary",
170
+ children: [
171
+ B.size,
172
+ " ",
173
+ x("notifTemplates.selected", "selected")
174
+ ]
175
+ }),
176
+ B.size > 0 && /* @__PURE__ */ m("button", {
177
+ onClick: () => V(/* @__PURE__ */ new Set()),
178
+ className: "text-sm text-secondary hover:text-primary",
179
+ children: x("notifTemplates.clearSelection", "Clear selection")
180
+ }),
181
+ K && /* @__PURE__ */ h("button", {
182
+ onClick: J,
183
+ disabled: H.length === 0 || D,
184
+ className: "flex items-center gap-2 px-3 py-2 text-sm font-medium text-error border border-error/30 hover:bg-error/10 rounded-lg transition-all duration-150 disabled:opacity-50",
185
+ children: [
186
+ /* @__PURE__ */ m(d, { size: 14 }),
187
+ x("notifTemplates.deleteSelected", "Delete Selected"),
188
+ H.length > 0 ? ` (${H.length})` : ""
189
+ ]
190
+ })
191
+ ]
192
+ })]
193
+ }),
194
+ R && /* @__PURE__ */ h("div", {
195
+ className: "flex items-center gap-3 p-3 bg-error/10 border border-error/30 rounded-lg",
196
+ children: [/* @__PURE__ */ m(a, {
197
+ size: 16,
198
+ className: "text-error shrink-0"
199
+ }), /* @__PURE__ */ m("p", {
200
+ className: "text-sm text-error",
201
+ children: R
202
+ })]
203
+ }),
204
+ T.length === 0 && !E && /* @__PURE__ */ h("div", {
205
+ className: "flex flex-col items-center justify-center h-48 gap-3",
206
+ children: [/* @__PURE__ */ m(o, {
207
+ size: 32,
208
+ className: "text-tertiary"
209
+ }), /* @__PURE__ */ m("p", {
210
+ className: "text-sm text-secondary",
211
+ children: j.search || j.type ? x("notifTemplates.noMatchingTemplates", "No templates match your filters") : x("notifTemplates.noTemplatesYet", "No templates yet. Create your first one!")
212
+ })]
213
+ }),
214
+ /* @__PURE__ */ m("div", {
215
+ className: "grid gap-4 sm:grid-cols-2 lg:grid-cols-3",
216
+ children: T.map((e) => /* @__PURE__ */ h("div", {
217
+ onClick: () => b(e.slug),
218
+ className: `group relative p-4 bg-surface border rounded-lg cursor-pointer transition-all duration-200 hover:bg-muted hover:shadow-md hover:-translate-y-0.5 ${B.has(e.id) ? "border-accent-primary/50 ring-1 ring-accent-primary/20" : "border-default"}`,
219
+ children: [
220
+ /* @__PURE__ */ h("div", {
221
+ className: "flex items-start justify-between mb-3",
222
+ children: [/* @__PURE__ */ h("div", {
223
+ className: "flex items-center gap-2",
224
+ children: [/* @__PURE__ */ m("input", {
225
+ type: "checkbox",
226
+ checked: B.has(e.id),
227
+ onChange: (t) => {
228
+ t.stopPropagation(), Y(e.id, t.target.checked);
229
+ },
230
+ onClick: (e) => e.stopPropagation(),
231
+ "aria-label": x("notifTemplates.selectTemplateAria", "Select template {{name}}").replace("{{name}}", e.name),
232
+ className: "h-4 w-4 rounded border-default text-accent-primary"
233
+ }), /* @__PURE__ */ m(o, {
234
+ size: 20,
235
+ className: "text-accent-primary"
236
+ })]
237
+ }), /* @__PURE__ */ h("div", {
238
+ className: "flex items-center gap-2",
239
+ children: [/* @__PURE__ */ m("span", {
240
+ className: `px-2 py-0.5 text-[10px] font-semibold rounded-full border ${_[e.type] || "text-tertiary bg-muted border-default"}`,
241
+ children: x(`notifTemplates.type.${e.type}`, v[e.type] || e.type)
242
+ }), K && /* @__PURE__ */ m("button", {
243
+ onClick: (t) => q(t, e),
244
+ disabled: D && I === e.id,
245
+ className: "opacity-0 group-hover:opacity-100 p-1 text-tertiary hover:text-error rounded transition-all duration-150",
246
+ title: x("notifTemplates.deleteTemplate", "Delete template"),
247
+ children: D && I === e.id ? /* @__PURE__ */ m(s, {
248
+ size: 14,
249
+ className: "animate-spin"
250
+ }) : /* @__PURE__ */ m(d, { size: 14 })
251
+ })]
252
+ })]
253
+ }),
254
+ /* @__PURE__ */ m("h3", {
255
+ className: "text-sm font-semibold text-primary mb-1 truncate",
256
+ children: e.name
257
+ }),
258
+ e.description && /* @__PURE__ */ m("p", {
259
+ className: "text-xs text-secondary mb-2 line-clamp-2",
260
+ children: e.description
261
+ }),
262
+ /* @__PURE__ */ h("div", {
263
+ className: "flex items-center gap-2 text-[11px] text-tertiary mt-auto pt-2 border-t border-default/50",
264
+ children: [
265
+ /* @__PURE__ */ m("code", {
266
+ className: "px-1.5 py-0.5 bg-muted rounded text-[10px]",
267
+ children: e.slug
268
+ }),
269
+ /* @__PURE__ */ m("span", { children: "•" }),
270
+ /* @__PURE__ */ m("span", { children: e.locale || "en" }),
271
+ /* @__PURE__ */ m("span", { children: "•" }),
272
+ /* @__PURE__ */ m("span", {
273
+ className: e.enabled ? "text-success" : "text-tertiary",
274
+ children: e.enabled ? x("notifTemplates.enabled", "Enabled") : x("notifTemplates.disabled", "Disabled")
275
+ })
276
+ ]
277
+ }),
278
+ /* @__PURE__ */ h("p", {
279
+ className: "text-[10px] text-tertiary mt-1.5",
280
+ children: [
281
+ x("notifTemplates.updated", "Updated"),
282
+ " ",
283
+ y(e.updatedAt, S)
284
+ ]
285
+ })
286
+ ]
287
+ }, e.id))
288
+ }),
289
+ A && /* @__PURE__ */ m("div", {
290
+ className: "flex justify-center pt-2",
291
+ children: /* @__PURE__ */ h("button", {
292
+ onClick: N,
293
+ disabled: E,
294
+ className: "flex items-center gap-2 px-4 py-2 text-sm text-secondary hover:text-primary border border-default rounded-lg transition-all duration-150 hover:shadow-sm",
295
+ children: [E ? /* @__PURE__ */ m(s, {
296
+ size: 14,
297
+ className: "animate-spin"
298
+ }) : null, x("notifTemplates.loadMore", "Load More")]
299
+ })
300
+ })
301
+ ]
302
+ }) : /* @__PURE__ */ m("div", {
303
+ className: "p-8 text-center text-text-secondary",
304
+ children: x("notifTemplates.noPermissionView", "You don't have permission to view notification templates.")
305
+ });
306
+ }
307
+ //#endregion
308
+ export { b as NotificationTemplatesPage };
309
+
310
+ //# sourceMappingURL=NotificationTemplatesPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationTemplatesPage.js","names":[],"sources":["../../src/pages/NotificationTemplatesPage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { FileText, Plus, Search, Trash2, Loader2, AlertCircle, RefreshCw } from 'lucide-react';\nimport { useNavigate } from 'react-router-dom';\nimport { usePermissions } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { useNotificationTemplates } from '../hooks/useNotificationTemplates';\nimport type { BackendNotificationTemplate } from '../hooks/useNotificationTemplates';\nimport type { NotificationType } from '../types';\nimport { NOTIFICATION_PERMISSIONS } from '../constants/permissions';\nimport { useTr } from '../shared/hooks/useTr';\n\n// ── Helpers ────────────────────────────────────────────────────────────\n\nconst TYPE_COLORS: Record<NotificationType, string> = {\n TRANSACTIONAL: 'text-status-info-text bg-status-info-bg-subtle border-status-info-bg-subtle',\n MARKETING: 'text-accent-purple bg-accent-purple-subtle border-accent-purple-subtle',\n SYSTEM: 'text-status-warning-text bg-status-warning-bg-subtle border-status-warning-bg-subtle',\n ALERT: 'text-status-error-text bg-status-error-bg-subtle border-status-error-bg-subtle',\n};\n\nconst TYPE_LABELS: Record<NotificationType, string> = {\n TRANSACTIONAL: 'Transactional',\n MARKETING: 'Marketing',\n SYSTEM: 'System',\n ALERT: 'Alert',\n};\n\nfunction formatDate(iso: string, locale?: string) {\n return new Date(iso).toLocaleDateString(locale || 'en-US', {\n month: 'short',\n day: 'numeric',\n year: 'numeric',\n });\n}\n\n// ── Component ──────────────────────────────────────────────────────────\n\n/**\n * Notification Templates Page (Admin)\n *\n * Lists all notification templates from the real backend.\n * Supports search, type filtering, delete, and navigation to editor.\n */\nexport function NotificationTemplatesPage() {\n const navigate = useNavigate();\n const tr = useTr();\n const { locale } = useI18n();\n const { hasPermission, isLoading: permissionsLoading } = usePermissions();\n const {\n templates,\n isLoading,\n isDeleting,\n error,\n total,\n hasMore,\n filter,\n refetch,\n loadMore,\n deleteTemplate,\n updateFilter,\n } = useNotificationTemplates();\n\n const [deletingId, setDeletingId] = useState<string | null>(null);\n const [deleteError, setDeleteError] = useState<string | null>(null);\n const [selectedTemplateIds, setSelectedTemplateIds] = useState<Set<string>>(new Set());\n\n const selectedTemplates = useMemo(\n () => templates.filter((template) => selectedTemplateIds.has(template.id)),\n [selectedTemplateIds, templates]\n );\n\n const allVisibleSelected =\n templates.length > 0 && templates.every((template) => selectedTemplateIds.has(template.id));\n const partiallySelected =\n templates.some((template) => selectedTemplateIds.has(template.id)) && !allVisibleSelected;\n\n const canCreateTemplate = hasPermission(NOTIFICATION_PERMISSIONS.TEMPLATE_CREATE);\n const canDeleteTemplate = hasPermission(NOTIFICATION_PERMISSIONS.TEMPLATE_DELETE);\n\n const handleDelete = async (e: React.MouseEvent, template: BackendNotificationTemplate) => {\n e.stopPropagation();\n if (\n !confirm(\n tr(\n 'notifTemplates.confirmDelete',\n `Delete template \"${template.name}\"? This cannot be undone.`\n )\n )\n )\n return;\n\n setDeletingId(template.id);\n setDeleteError(null);\n try {\n await deleteTemplate(template.id);\n } catch (err: unknown) {\n setDeleteError(\n err instanceof Error\n ? err.message\n : tr('notifTemplates.deleteFailed', 'Failed to delete template')\n );\n } finally {\n setDeletingId(null);\n }\n };\n\n const handleBulkDelete = async () => {\n if (selectedTemplates.length === 0) return;\n const confirmed = window.confirm(\n tr(\n 'notifTemplates.confirmBulkDelete',\n `Delete ${selectedTemplates.length} selected template${selectedTemplates.length === 1 ? '' : 's'}? This cannot be undone.`\n )\n );\n if (!confirmed) return;\n\n setDeleteError(null);\n await Promise.allSettled(selectedTemplates.map((template) => deleteTemplate(template.id)));\n setSelectedTemplateIds(new Set());\n };\n\n const toggleTemplateSelection = (templateId: string, checked: boolean) => {\n setSelectedTemplateIds((prev) => {\n const next = new Set(prev);\n if (checked) {\n next.add(templateId);\n } else {\n next.delete(templateId);\n }\n return next;\n });\n };\n\n const toggleAllTemplates = (checked: boolean) => {\n setSelectedTemplateIds((prev) => {\n const next = new Set(prev);\n templates.forEach((template) => {\n if (checked) {\n next.add(template.id);\n } else {\n next.delete(template.id);\n }\n });\n return next;\n });\n };\n\n // ── Permission guards ────────────────────────────────────────────────\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 // TEMPLATE_LIST admits read-only admins; the page already hides/disables write actions for them.\n const canViewTemplates =\n hasPermission(NOTIFICATION_PERMISSIONS.TEMPLATE_LIST) ||\n canCreateTemplate ||\n canDeleteTemplate ||\n hasPermission(NOTIFICATION_PERMISSIONS.TEMPLATE_UPDATE);\n\n if (!canViewTemplates) {\n return (\n <div className=\"p-8 text-center text-text-secondary\">\n {tr(\n 'notifTemplates.noPermissionView',\n \"You don't have permission to view notification templates.\"\n )}\n </div>\n );\n }\n\n // ── Loading state ────────────────────────────────────────────────────\n if (isLoading && templates.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center h-64 gap-3\">\n <Loader2 size={28} className=\"animate-spin text-accent-primary\" />\n <p className=\"text-sm text-secondary\">\n {tr('notifTemplates.loading', 'Loading templates...')}\n </p>\n </div>\n );\n }\n\n // ── Error state ──────────────────────────────────────────────────────\n if (error && templates.length === 0) {\n return (\n <div className=\"flex flex-col items-center justify-center h-64 gap-4\">\n <AlertCircle size={28} className=\"text-error\" />\n <p className=\"text-sm text-error\">{error}</p>\n <button\n onClick={refetch}\n className=\"flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-accent-primary/90 rounded-lg transition-all duration-150\"\n >\n <RefreshCw size={14} />\n {tr('notifTemplates.retry', 'Retry')}\n </button>\n </div>\n );\n }\n\n return (\n <div className=\"space-y-4 sm:space-y-6 p-3 sm:p-6 animate-in fade-in duration-300\">\n {/* Header */}\n <div className=\"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between\">\n <div>\n <h1 className=\"text-xl sm:text-2xl font-bold text-primary\">\n {tr('notifTemplates.title', 'Notification Templates')}\n </h1>\n <p className=\"text-sm text-secondary mt-1\">\n {total} {tr('notifTemplates.templateCount', 'template')}\n {total !== 1 ? 's' : ''} {tr('notifTemplates.total', 'total')}\n </p>\n </div>\n\n {canCreateTemplate && (\n <button\n onClick={() => navigate('new')}\n className=\"flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-accent-primary hover:bg-accent-primary/90 rounded-lg transition-all duration-150 hover:shadow-md\"\n >\n <Plus size={16} />\n {tr('notifTemplates.createTemplate', 'Create Template')}\n </button>\n )}\n </div>\n\n {/* Search + Type filter row */}\n <div className=\"flex flex-col gap-3 sm:flex-row sm:items-center\">\n {/* Search */}\n <div className=\"relative flex-1\">\n <Search size={16} className=\"absolute left-3 top-1/2 -translate-y-1/2 text-tertiary\" />\n <input\n type=\"text\"\n value={filter.search || ''}\n onChange={(e) => updateFilter({ search: e.target.value })}\n placeholder={tr('notifTemplates.searchPlaceholder', 'Search templates...')}\n className=\"w-full pl-9 pr-4 py-2 text-sm text-primary bg-surface border border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent transition-shadow duration-150\"\n />\n </div>\n\n {/* Type filter */}\n <select\n value={filter.type || ''}\n onChange={(e) =>\n updateFilter({ type: (e.target.value || undefined) as NotificationType | undefined })\n }\n className=\"px-3 py-2 text-sm text-primary bg-surface border border-default rounded-lg focus:outline-none focus:ring-2 focus:ring-accent transition-shadow duration-150\"\n >\n <option value=\"\">{tr('notifTemplates.allTypes', 'All Types')}</option>\n <option value=\"TRANSACTIONAL\">\n {tr('notifTemplates.typeTransactional', 'Transactional')}\n </option>\n <option value=\"MARKETING\">{tr('notifTemplates.typeMarketing', 'Marketing')}</option>\n <option value=\"SYSTEM\">{tr('notifTemplates.typeSystem', 'System')}</option>\n <option value=\"ALERT\">{tr('notifTemplates.typeAlert', 'Alert')}</option>\n </select>\n </div>\n\n {templates.length > 0 && (\n <div className=\"flex flex-col gap-3 rounded-lg border border-default bg-surface p-4 sm:flex-row sm:items-center sm:justify-between\">\n <label className=\"flex items-center gap-2 text-sm text-primary\">\n <input\n type=\"checkbox\"\n checked={allVisibleSelected}\n ref={(input) => {\n if (input) {\n input.indeterminate = partiallySelected && !allVisibleSelected;\n }\n }}\n onChange={(event) => toggleAllTemplates(event.target.checked)}\n aria-label={tr(\n 'notifTemplates.selectAllVisibleAria',\n 'Select all notification templates'\n )}\n className=\"h-4 w-4 rounded border-default text-accent-primary\"\n />\n <span>{tr('notifTemplates.selectAllVisible', 'Select all visible')}</span>\n </label>\n\n <div className=\"flex items-center gap-2\">\n <span className=\"text-sm text-secondary\">\n {selectedTemplateIds.size} {tr('notifTemplates.selected', 'selected')}\n </span>\n {selectedTemplateIds.size > 0 && (\n <button\n onClick={() => setSelectedTemplateIds(new Set())}\n className=\"text-sm text-secondary hover:text-primary\"\n >\n {tr('notifTemplates.clearSelection', 'Clear selection')}\n </button>\n )}\n {canDeleteTemplate && (\n <button\n onClick={handleBulkDelete}\n disabled={selectedTemplates.length === 0 || isDeleting}\n className=\"flex items-center gap-2 px-3 py-2 text-sm font-medium text-error border border-error/30 hover:bg-error/10 rounded-lg transition-all duration-150 disabled:opacity-50\"\n >\n <Trash2 size={14} />\n {tr('notifTemplates.deleteSelected', 'Delete Selected')}\n {selectedTemplates.length > 0 ? ` (${selectedTemplates.length})` : ''}\n </button>\n )}\n </div>\n </div>\n )}\n\n {/* Delete error banner */}\n {deleteError && (\n <div className=\"flex items-center gap-3 p-3 bg-error/10 border border-error/30 rounded-lg\">\n <AlertCircle size={16} className=\"text-error shrink-0\" />\n <p className=\"text-sm text-error\">{deleteError}</p>\n </div>\n )}\n\n {/* Empty state */}\n {templates.length === 0 && !isLoading && (\n <div className=\"flex flex-col items-center justify-center h-48 gap-3\">\n <FileText size={32} className=\"text-tertiary\" />\n <p className=\"text-sm text-secondary\">\n {filter.search || filter.type\n ? tr('notifTemplates.noMatchingTemplates', 'No templates match your filters')\n : tr('notifTemplates.noTemplatesYet', 'No templates yet. Create your first one!')}\n </p>\n </div>\n )}\n\n {/* Templates grid */}\n <div className=\"grid gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n {templates.map((template) => (\n <div\n key={template.id}\n onClick={() => navigate(template.slug)}\n className={`group relative p-4 bg-surface border rounded-lg cursor-pointer transition-all duration-200 hover:bg-muted hover:shadow-md hover:-translate-y-0.5 ${selectedTemplateIds.has(template.id) ? 'border-accent-primary/50 ring-1 ring-accent-primary/20' : 'border-default'}`}\n >\n {/* Top row: icon + type badge + delete */}\n <div className=\"flex items-start justify-between mb-3\">\n <div className=\"flex items-center gap-2\">\n <input\n type=\"checkbox\"\n checked={selectedTemplateIds.has(template.id)}\n onChange={(event) => {\n event.stopPropagation();\n toggleTemplateSelection(template.id, event.target.checked);\n }}\n onClick={(event) => event.stopPropagation()}\n aria-label={tr(\n 'notifTemplates.selectTemplateAria',\n 'Select template {{name}}'\n ).replace('{{name}}', template.name)}\n className=\"h-4 w-4 rounded border-default text-accent-primary\"\n />\n <FileText size={20} className=\"text-accent-primary\" />\n </div>\n <div className=\"flex items-center gap-2\">\n <span\n className={`px-2 py-0.5 text-[10px] font-semibold rounded-full border ${\n TYPE_COLORS[template.type as NotificationType] ||\n 'text-tertiary bg-muted border-default'\n }`}\n >\n {tr(\n `notifTemplates.type.${template.type as NotificationType}`,\n TYPE_LABELS[template.type as NotificationType] || template.type\n )}\n </span>\n {canDeleteTemplate && (\n <button\n onClick={(e) => handleDelete(e, template)}\n disabled={isDeleting && deletingId === template.id}\n className=\"opacity-0 group-hover:opacity-100 p-1 text-tertiary hover:text-error rounded transition-all duration-150\"\n title={tr('notifTemplates.deleteTemplate', 'Delete template')}\n >\n {isDeleting && deletingId === template.id ? (\n <Loader2 size={14} className=\"animate-spin\" />\n ) : (\n <Trash2 size={14} />\n )}\n </button>\n )}\n </div>\n </div>\n\n {/* Name */}\n <h3 className=\"text-sm font-semibold text-primary mb-1 truncate\">{template.name}</h3>\n\n {/* Description */}\n {template.description && (\n <p className=\"text-xs text-secondary mb-2 line-clamp-2\">{template.description}</p>\n )}\n\n {/* Bottom row: slug + enabled badge + locale */}\n <div className=\"flex items-center gap-2 text-[11px] text-tertiary mt-auto pt-2 border-t border-default/50\">\n <code className=\"px-1.5 py-0.5 bg-muted rounded text-[10px]\">{template.slug}</code>\n <span>•</span>\n <span>{template.locale || 'en'}</span>\n <span>•</span>\n <span className={template.enabled ? 'text-success' : 'text-tertiary'}>\n {template.enabled\n ? tr('notifTemplates.enabled', 'Enabled')\n : tr('notifTemplates.disabled', 'Disabled')}\n </span>\n </div>\n\n {/* Updated date */}\n <p className=\"text-[10px] text-tertiary mt-1.5\">\n {tr('notifTemplates.updated', 'Updated')} {formatDate(template.updatedAt, locale)}\n </p>\n </div>\n ))}\n </div>\n\n {/* Load more */}\n {hasMore && (\n <div className=\"flex justify-center pt-2\">\n <button\n onClick={loadMore}\n disabled={isLoading}\n className=\"flex items-center gap-2 px-4 py-2 text-sm text-secondary hover:text-primary border border-default rounded-lg transition-all duration-150 hover:shadow-sm\"\n >\n {isLoading ? <Loader2 size={14} className=\"animate-spin\" /> : null}\n {tr('notifTemplates.loadMore', 'Load More')}\n </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N,kBAAC,MAAD;OAAI,WAAU;iBAAoD,EAAS;OAAU,CAAA;MAGpF,EAAS,eACR,kBAAC,KAAD;OAAG,WAAU;iBAA4C,EAAS;OAAgB,CAAA;MAIpF,kBAAC,OAAD;OAAK,WAAU;iBAAf;QACE,kBAAC,QAAD;SAAM,WAAU;mBAA8C,EAAS;SAAY,CAAA;QACnF,kBAAC,QAAD,EAAA,UAAM,KAAQ,CAAA;QACd,kBAAC,QAAD,EAAA,UAAO,EAAS,UAAU,MAAY,CAAA;QACtC,kBAAC,QAAD,EAAA,UAAM,KAAQ,CAAA;QACd,kBAAC,QAAD;SAAM,WAAW,EAAS,UAAU,iBAAiB;mBAClD,EAAS,UACN,EAAG,0BAA0B,UAAU,GACvC,EAAG,2BAA2B,WAAW;SACxC,CAAA;QACH;;MAGN,kBAAC,KAAD;OAAG,WAAU;iBAAb;QACG,EAAG,0BAA0B,UAAU;QAAC;QAAE,EAAW,EAAS,WAAW,EAAO;QAC/E;;MACA;OA7EC,EAAS,GA6EV,CACN;IACE,CAAA;GAGL,KACC,kBAAC,OAAD;IAAK,WAAU;cACb,kBAAC,UAAD;KACE,SAAS;KACT,UAAU;KACV,WAAU;eAHZ,CAKG,IAAY,kBAAC,GAAD;MAAS,MAAM;MAAI,WAAU;MAAiB,CAAA,GAAG,MAC7D,EAAG,2BAA2B,YAAY,CACpC;;IACL,CAAA;GAEJ;MArQJ,kBAAC,OAAD;EAAK,WAAU;YACZ,EACC,mCACA,4DACD;EACG,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function NotificationTopicsPage(): import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=NotificationTopicsPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationTopicsPage.d.ts","sourceRoot":"","sources":["../../src/pages/NotificationTopicsPage.tsx"],"names":[],"mappings":"AAuBA,wBAAgB,sBAAsB,4CAqRrC"}
@@ -0,0 +1,254 @@
1
+ import { useNotificationTopics as e } from "../hooks/useNotificationTopics.js";
2
+ import "../hooks/index.js";
3
+ import { useTr as t } from "../shared/hooks/useTr.js";
4
+ import { NOTIFICATION_PERMISSIONS as n } from "../constants/permissions.js";
5
+ import { useMemo as r, useState as i } from "react";
6
+ import { Plus as a, Save as o, Search as s, Trash2 as c } from "lucide-react";
7
+ import { usePermissions as l } from "@burdenoff/fe-libs/shared/providers/shell";
8
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
9
+ //#region src/pages/NotificationTopicsPage.tsx
10
+ var f = [
11
+ {
12
+ value: "MARKETING",
13
+ label: "Marketing"
14
+ },
15
+ {
16
+ value: "TRANSACTIONAL",
17
+ label: "Transactional"
18
+ },
19
+ {
20
+ value: "SYSTEM",
21
+ label: "System"
22
+ },
23
+ {
24
+ value: "ALERT",
25
+ label: "Alert"
26
+ }
27
+ ];
28
+ function p(e) {
29
+ return e.toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-");
30
+ }
31
+ function m() {
32
+ let m = t(), { hasPermission: h, isLoading: g } = l(), { topics: _, isLoading: v, createTopic: y, updateTopic: b, deleteTopic: x } = e(), [S, C] = i(""), [w, T] = i(null), [E, D] = i({
33
+ name: "",
34
+ slug: "",
35
+ description: "",
36
+ type: "MARKETING",
37
+ isActive: !0
38
+ }), O = h(n.NOTIFICATION_CREATE), k = r(() => {
39
+ if (!S.trim()) return _;
40
+ let e = S.toLowerCase();
41
+ return _.filter((t) => t.name.toLowerCase().includes(e) || t.slug.toLowerCase().includes(e) || t.description?.toLowerCase().includes(e));
42
+ }, [S, _]);
43
+ return g ? /* @__PURE__ */ u("div", {
44
+ className: "flex h-64 items-center justify-center",
45
+ children: /* @__PURE__ */ u("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
46
+ }) : O ? /* @__PURE__ */ d("div", {
47
+ className: "space-y-6 p-4 sm:p-6",
48
+ children: [/* @__PURE__ */ d("div", { children: [/* @__PURE__ */ u("h1", {
49
+ className: "text-2xl font-bold text-primary",
50
+ children: m("notifications.topicsTitle", "Notification Topics")
51
+ }), /* @__PURE__ */ u("p", {
52
+ className: "mt-1 text-sm text-secondary",
53
+ children: m("notifications.topicsSubtitle", "Create topics for campaigns so users can subscribe or unsubscribe with precision.")
54
+ })] }), /* @__PURE__ */ d("div", {
55
+ className: "grid gap-6 xl:grid-cols-[380px,1fr]",
56
+ children: [/* @__PURE__ */ d("form", {
57
+ className: "space-y-4 rounded-lg border border-default bg-surface p-4 shadow-sm",
58
+ onSubmit: async (e) => {
59
+ e.preventDefault(), !(!E.name.trim() || !E.slug.trim()) && (w ? await b(w, E) : await y(E), T(null), D({
60
+ name: "",
61
+ slug: "",
62
+ description: "",
63
+ type: "MARKETING",
64
+ isActive: !0
65
+ }));
66
+ },
67
+ children: [
68
+ /* @__PURE__ */ d("div", {
69
+ className: "flex items-center gap-2",
70
+ children: [/* @__PURE__ */ u(a, {
71
+ size: 18,
72
+ className: "text-accent-primary"
73
+ }), /* @__PURE__ */ u("h2", {
74
+ className: "text-base font-semibold text-primary",
75
+ children: w ? m("notifications.editTopic", "Edit Topic") : m("notifications.createTopic", "Create Topic")
76
+ })]
77
+ }),
78
+ /* @__PURE__ */ d("label", {
79
+ className: "block space-y-1 text-sm text-secondary",
80
+ children: [/* @__PURE__ */ u("span", { children: m("notifications.topicName", "Name") }), /* @__PURE__ */ u("input", {
81
+ type: "text",
82
+ value: E.name,
83
+ onChange: (e) => D((t) => ({
84
+ ...t,
85
+ name: e.target.value,
86
+ slug: w ? t.slug : p(e.target.value)
87
+ })),
88
+ className: "w-full rounded-md border border-default bg-bg-canvas px-3 py-2 text-primary focus:outline-none focus:ring-2 focus:ring-accent"
89
+ })]
90
+ }),
91
+ /* @__PURE__ */ d("label", {
92
+ className: "block space-y-1 text-sm text-secondary",
93
+ children: [/* @__PURE__ */ u("span", { children: m("notifications.topicSlug", "Slug") }), /* @__PURE__ */ u("input", {
94
+ type: "text",
95
+ value: E.slug,
96
+ onChange: (e) => D((t) => ({
97
+ ...t,
98
+ slug: p(e.target.value)
99
+ })),
100
+ className: "w-full rounded-md border border-default bg-bg-canvas px-3 py-2 text-primary focus:outline-none focus:ring-2 focus:ring-accent"
101
+ })]
102
+ }),
103
+ /* @__PURE__ */ d("label", {
104
+ className: "block space-y-1 text-sm text-secondary",
105
+ children: [/* @__PURE__ */ u("span", { children: m("notifications.topicType", "Type") }), /* @__PURE__ */ u("select", {
106
+ value: E.type,
107
+ onChange: (e) => D((t) => ({
108
+ ...t,
109
+ type: e.target.value
110
+ })),
111
+ className: "w-full rounded-md border border-default bg-bg-canvas px-3 py-2 text-primary focus:outline-none focus:ring-2 focus:ring-accent",
112
+ children: f.map((e) => /* @__PURE__ */ u("option", {
113
+ value: e.value,
114
+ children: e.label
115
+ }, e.value))
116
+ })]
117
+ }),
118
+ /* @__PURE__ */ d("label", {
119
+ className: "block space-y-1 text-sm text-secondary",
120
+ children: [/* @__PURE__ */ u("span", { children: m("notifications.topicDescription", "Description") }), /* @__PURE__ */ u("textarea", {
121
+ value: E.description,
122
+ onChange: (e) => D((t) => ({
123
+ ...t,
124
+ description: e.target.value
125
+ })),
126
+ rows: 4,
127
+ className: "w-full rounded-md border border-default bg-bg-canvas px-3 py-2 text-primary focus:outline-none focus:ring-2 focus:ring-accent"
128
+ })]
129
+ }),
130
+ /* @__PURE__ */ d("label", {
131
+ className: "flex items-center gap-2 text-sm text-secondary",
132
+ children: [/* @__PURE__ */ u("input", {
133
+ type: "checkbox",
134
+ checked: E.isActive,
135
+ onChange: (e) => D((t) => ({
136
+ ...t,
137
+ isActive: e.target.checked
138
+ }))
139
+ }), /* @__PURE__ */ u("span", { children: m("notifications.topicIsActive", "Active topic") })]
140
+ }),
141
+ /* @__PURE__ */ d("div", {
142
+ className: "flex items-center gap-3",
143
+ children: [/* @__PURE__ */ d("button", {
144
+ type: "submit",
145
+ className: "inline-flex items-center gap-2 rounded-md bg-accent-primary px-4 py-2 text-sm font-medium text-white hover:opacity-90",
146
+ children: [/* @__PURE__ */ u(o, { size: 16 }), w ? m("notifications.saveTopic", "Save Topic") : m("notifications.createTopicButton", "Create Topic")]
147
+ }), w && /* @__PURE__ */ u("button", {
148
+ type: "button",
149
+ onClick: () => {
150
+ T(null), D({
151
+ name: "",
152
+ slug: "",
153
+ description: "",
154
+ type: "MARKETING",
155
+ isActive: !0
156
+ });
157
+ },
158
+ className: "rounded-md border border-default px-4 py-2 text-sm text-secondary hover:bg-muted",
159
+ children: m("notifications.cancelTopicEdit", "Cancel")
160
+ })]
161
+ })
162
+ ]
163
+ }), /* @__PURE__ */ d("div", {
164
+ className: "space-y-4 rounded-lg border border-default bg-surface p-4 shadow-sm",
165
+ children: [/* @__PURE__ */ d("div", {
166
+ className: "relative max-w-md",
167
+ children: [/* @__PURE__ */ u(s, {
168
+ size: 16,
169
+ className: "absolute left-3 top-1/2 -translate-y-1/2 text-tertiary"
170
+ }), /* @__PURE__ */ u("input", {
171
+ type: "text",
172
+ value: S,
173
+ onChange: (e) => C(e.target.value),
174
+ placeholder: m("notifications.searchTopics", "Search topics..."),
175
+ className: "w-full rounded-md border border-default bg-bg-canvas py-2 pl-9 pr-4 text-sm text-primary focus:outline-none focus:ring-2 focus:ring-accent"
176
+ })]
177
+ }), /* @__PURE__ */ u("div", {
178
+ className: "space-y-3",
179
+ children: v ? /* @__PURE__ */ u("div", {
180
+ className: "text-sm text-secondary",
181
+ children: m("notifications.loadingTopics", "Loading topics...")
182
+ }) : k.length === 0 ? /* @__PURE__ */ u("div", {
183
+ className: "text-sm text-secondary",
184
+ children: m("notifications.noTopicsFound", "No topics found.")
185
+ }) : k.map((e) => /* @__PURE__ */ d("div", {
186
+ className: "flex flex-col gap-3 rounded-lg border border-default bg-bg-canvas p-4 sm:flex-row sm:items-start sm:justify-between",
187
+ children: [/* @__PURE__ */ d("div", {
188
+ className: "space-y-1",
189
+ children: [
190
+ /* @__PURE__ */ d("div", {
191
+ className: "flex flex-wrap items-center gap-2",
192
+ children: [
193
+ /* @__PURE__ */ u("h3", {
194
+ className: "text-sm font-semibold text-primary",
195
+ children: e.name
196
+ }),
197
+ /* @__PURE__ */ u("span", {
198
+ className: "rounded-full bg-muted px-2 py-0.5 text-xs text-secondary",
199
+ children: e.slug
200
+ }),
201
+ /* @__PURE__ */ u("span", {
202
+ className: "rounded-full bg-muted px-2 py-0.5 text-xs text-secondary",
203
+ children: e.type
204
+ })
205
+ ]
206
+ }),
207
+ e.description && /* @__PURE__ */ u("p", {
208
+ className: "text-sm text-secondary",
209
+ children: e.description
210
+ }),
211
+ /* @__PURE__ */ d("p", {
212
+ className: "text-xs text-tertiary",
213
+ children: [
214
+ m("notifications.topicSubscribers", "Subscribers"),
215
+ ": ",
216
+ e.subscriberCount
217
+ ]
218
+ })
219
+ ]
220
+ }), /* @__PURE__ */ d("div", {
221
+ className: "flex items-center gap-2",
222
+ children: [/* @__PURE__ */ u("button", {
223
+ type: "button",
224
+ onClick: () => {
225
+ T(e.id), D({
226
+ name: e.name,
227
+ slug: e.slug,
228
+ description: e.description || "",
229
+ type: e.type,
230
+ isActive: e.isActive
231
+ });
232
+ },
233
+ className: "rounded-md border border-default px-3 py-2 text-sm text-secondary hover:bg-muted",
234
+ children: m("notifications.edit", "Edit")
235
+ }), /* @__PURE__ */ d("button", {
236
+ type: "button",
237
+ onClick: () => x(e.id),
238
+ className: "inline-flex items-center gap-2 rounded-md border border-status-error-border px-3 py-2 text-sm text-status-error-text hover:bg-status-error-bg-subtle",
239
+ children: [/* @__PURE__ */ u(c, { size: 14 }), m("notifications.delete", "Delete")]
240
+ })]
241
+ })]
242
+ }, e.id))
243
+ })]
244
+ })]
245
+ })]
246
+ }) : /* @__PURE__ */ u("div", {
247
+ className: "p-8 text-center text-text-secondary",
248
+ children: m("notifications.noPermissionTopics", "You don't have permission to manage notification topics.")
249
+ });
250
+ }
251
+ //#endregion
252
+ export { m as NotificationTopicsPage };
253
+
254
+ //# sourceMappingURL=NotificationTopicsPage.js.map