@burdenoff/microfe-notification 2026.731.1 → 2026.828.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.js +14 -11
- package/dist/AdminNotificationRoutes.js.map +1 -1
- package/dist/NotificationRoutes.js +41 -35
- package/dist/NotificationRoutes.js.map +1 -1
- package/dist/UserNotificationRoutes.js +34 -30
- package/dist/UserNotificationRoutes.js.map +1 -1
- package/dist/components/RecipientSelector.js.map +1 -1
- package/dist/hooks/useSendNotification.js.map +1 -1
- package/dist/pages/CreateNotificationPage.js +1 -1
- package/dist/pages/CreateNotificationPage.js.map +1 -1
- package/dist/pages/NotificationHistoryAdminPage.js.map +1 -1
- package/dist/pages/NotificationHistoryPage.js.map +1 -1
- package/dist/pages/NotificationLandingPage.js +1 -1
- package/dist/pages/NotificationLandingPage.js.map +1 -1
- package/dist/pages/NotificationTemplatesPage.js +1 -1
- package/dist/pages/NotificationTemplatesPage.js.map +1 -1
- package/dist/pages/NotificationTopicsPage.js.map +1 -1
- package/dist/pages/TemplateEditorPage.js +1 -1
- package/dist/pages/TemplateEditorPage.js.map +1 -1
- package/dist/providers/NotificationProvider.js +1 -1
- package/dist/providers/NotificationProvider.js.map +1 -1
- package/package.json +4 -4
|
@@ -7,7 +7,7 @@ import { Suspense as a, lazy as o, useEffect as s } from "react";
|
|
|
7
7
|
import { PermissionGate as c } from "@burdenoff/fe-libs/shared/components";
|
|
8
8
|
import { useFeatureFlagDetails as l } from "@burdenoff/fe-libs/shared/feature-flags";
|
|
9
9
|
import { useGlobalUi as u } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
10
|
-
import { Navigate as d, Route as f, Routes as p, useNavigate as m } from "react-router
|
|
10
|
+
import { Navigate as d, Route as f, Routes as p, useNavigate as m } from "react-router";
|
|
11
11
|
import { jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
12
12
|
//#region src/AdminNotificationRoutes.tsx
|
|
13
13
|
var _ = o(() => import("./pages/NotificationHistoryAdminPage.js").then((e) => ({ default: e.NotificationHistoryAdminPage }))), v = o(() => import("./pages/NotificationTemplatesPage.js").then((e) => ({ default: e.NotificationTemplatesPage }))), y = o(() => import("./pages/TemplateEditorPage.js").then((e) => ({ default: e.TemplateEditorPage }))), b = o(() => import("./pages/CreateNotificationPage.js").then((e) => ({ default: e.CreateNotificationPage }))), x = o(() => import("./pages/NotificationTopicsPage.js").then((e) => ({ default: e.NotificationTopicsPage })));
|
|
@@ -35,7 +35,7 @@ function w(e) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
function T() {
|
|
38
|
-
let e = l("notification.templates"),
|
|
38
|
+
let { basePath: o = "/" } = e(), s = `${o.endsWith("/") ? o.slice(0, -1) : o}/center`, c = l("notification.templates"), u = l("notification.create"), m = l("notification.history"), C = c ? !!c.value : !1, T = u ? !!u.value : !1, E = m ? !!m.value : !1;
|
|
39
39
|
return /* @__PURE__ */ h(a, {
|
|
40
40
|
fallback: /* @__PURE__ */ h(S, {}),
|
|
41
41
|
children: /* @__PURE__ */ g(p, { children: [
|
|
@@ -43,18 +43,22 @@ function T() {
|
|
|
43
43
|
index: !0,
|
|
44
44
|
element: /* @__PURE__ */ h(r, {})
|
|
45
45
|
}),
|
|
46
|
+
/* @__PURE__ */ h(f, {
|
|
47
|
+
path: "list",
|
|
48
|
+
element: /* @__PURE__ */ h(n, {})
|
|
49
|
+
}),
|
|
46
50
|
/* @__PURE__ */ h(f, {
|
|
47
51
|
path: "center",
|
|
48
52
|
element: /* @__PURE__ */ h(n, {})
|
|
49
53
|
}),
|
|
50
54
|
/* @__PURE__ */ h(f, {
|
|
51
55
|
path: "history",
|
|
52
|
-
element:
|
|
56
|
+
element: E ? /* @__PURE__ */ h(_, {}) : /* @__PURE__ */ h(i, {
|
|
53
57
|
title: "Notification history is not enabled",
|
|
54
58
|
description: "This admin page is controlled by the notification.history feature flag. Enable the flag before validating delivery history."
|
|
55
59
|
})
|
|
56
60
|
}),
|
|
57
|
-
|
|
61
|
+
C && /* @__PURE__ */ h(f, {
|
|
58
62
|
path: "templates",
|
|
59
63
|
element: /* @__PURE__ */ h(w, {
|
|
60
64
|
permissions: [
|
|
@@ -66,21 +70,21 @@ function T() {
|
|
|
66
70
|
children: /* @__PURE__ */ h(v, {})
|
|
67
71
|
})
|
|
68
72
|
}),
|
|
69
|
-
|
|
73
|
+
C && /* @__PURE__ */ h(f, {
|
|
70
74
|
path: "templates/new",
|
|
71
75
|
element: /* @__PURE__ */ h(w, {
|
|
72
76
|
permission: t.TEMPLATE_CREATE,
|
|
73
77
|
children: /* @__PURE__ */ h(y, {})
|
|
74
78
|
})
|
|
75
79
|
}),
|
|
76
|
-
|
|
80
|
+
C && /* @__PURE__ */ h(f, {
|
|
77
81
|
path: "templates/:templateId",
|
|
78
82
|
element: /* @__PURE__ */ h(w, {
|
|
79
83
|
permission: t.TEMPLATE_UPDATE,
|
|
80
84
|
children: /* @__PURE__ */ h(y, {})
|
|
81
85
|
})
|
|
82
86
|
}),
|
|
83
|
-
|
|
87
|
+
T && /* @__PURE__ */ h(f, {
|
|
84
88
|
path: "create",
|
|
85
89
|
element: /* @__PURE__ */ h(w, {
|
|
86
90
|
permissions: [t.NOTIFICATION_CREATE, t.NOTIFICATION_SEND],
|
|
@@ -88,7 +92,7 @@ function T() {
|
|
|
88
92
|
children: /* @__PURE__ */ h(b, {})
|
|
89
93
|
})
|
|
90
94
|
}),
|
|
91
|
-
|
|
95
|
+
T && /* @__PURE__ */ h(f, {
|
|
92
96
|
path: "topics",
|
|
93
97
|
element: /* @__PURE__ */ h(w, {
|
|
94
98
|
permission: t.NOTIFICATION_CREATE,
|
|
@@ -98,9 +102,8 @@ function T() {
|
|
|
98
102
|
/* @__PURE__ */ h(f, {
|
|
99
103
|
path: "*",
|
|
100
104
|
element: /* @__PURE__ */ h(d, {
|
|
101
|
-
to:
|
|
102
|
-
replace: !0
|
|
103
|
-
relative: "path"
|
|
105
|
+
to: s,
|
|
106
|
+
replace: !0
|
|
104
107
|
})
|
|
105
108
|
})
|
|
106
109
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdminNotificationRoutes.js","names":[],"sources":["../src/AdminNotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense, useEffect, type ReactNode } from 'react';\nimport { Navigate, Route, Routes, useNavigate } from 'react-router-dom';\nimport { useFeatureFlagDetails } from '@burdenoff/fe-libs/shared/feature-flags';\nimport { PermissionGate } from '@burdenoff/fe-libs/shared/components';\nimport { useGlobalUi } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { FeatureDisabledPage } from './components/FeatureDisabledPage';\nimport { NOTIFICATION_PERMISSIONS, type NotificationPermission } from './constants/permissions';\nimport { useNotification } from './providers/NotificationProvider';\n\n// Eager load - Primary landing page\nimport { NotificationCenterPage } from './pages/NotificationCenterPage';\nimport { NotificationLandingPage } from './pages/NotificationLandingPage';\n\n// Lazy load - Secondary pages\nconst NotificationHistoryAdminPage = lazy(() =>\n import('./pages/NotificationHistoryAdminPage').then((m) => ({\n default: m.NotificationHistoryAdminPage,\n }))\n);\nconst NotificationTemplatesPage = lazy(() =>\n import('./pages/NotificationTemplatesPage').then((m) => ({\n default: m.NotificationTemplatesPage,\n }))\n);\nconst TemplateEditorPage = lazy(() =>\n import('./pages/TemplateEditorPage').then((m) => ({ default: m.TemplateEditorPage }))\n);\nconst CreateNotificationPage = lazy(() =>\n import('./pages/CreateNotificationPage').then((m) => ({ default: m.CreateNotificationPage }))\n);\nconst NotificationTopicsPage = lazy(() =>\n import('./pages/NotificationTopicsPage').then((m) => ({ default: m.NotificationTopicsPage }))\n);\n\n// Loading fallback component\nfunction PageLoader() {\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// Pair toast + programmatic navigation in one effect to avoid <Navigate> unmounting before the toast fires.\n// Uses absolute `${basePath}/center` because relative `../center` resolves wrong from nested paths like `/templates/new`.\nfunction AccessDeniedRedirect() {\n const { showToast } = useGlobalUi();\n const navigate = useNavigate();\n const { basePath } = useNotification();\n useEffect(() => {\n showToast('You do not have permission to access that notification page.', 'warning');\n navigate(`${basePath}/center`, { replace: true });\n // Run once per access-denied mount; re-running on hook identity changes would duplicate the toast.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return null;\n}\n\n// Discriminated union: callers must pass exactly one of `permission` / `permissions`.\ntype AdminRouteGateProps = {\n children: ReactNode;\n} & (\n | { permission: NotificationPermission; permissions?: never; requireAll?: never }\n | {\n permission?: never;\n permissions: NotificationPermission[];\n requireAll?: boolean;\n }\n);\n\nfunction AdminRouteGate(props: AdminRouteGateProps) {\n const { children, ...gateProps } = props;\n return (\n <PermissionGate\n permission={gateProps.permission}\n permissions={gateProps.permissions}\n requireAll={gateProps.requireAll}\n loading={<PageLoader />}\n fallback={<AccessDeniedRedirect />}\n >\n {children}\n </PermissionGate>\n );\n}\n\n// Admin-app router for the notification MFE. Admin routes are wrapped in PermissionGate.\nexport function AdminNotificationRoutes() {\n // Explicit `false` fallback prevents provider's default-allow from leaking unseeded flags.\n const templatesDetails = useFeatureFlagDetails('notification.templates');\n const createDetails = useFeatureFlagDetails('notification.create');\n const historyDetails = useFeatureFlagDetails('notification.history');\n const templatesEnabled = templatesDetails ? Boolean(templatesDetails.value) : false;\n const createEnabled = createDetails ? Boolean(createDetails.value) : false;\n const historyEnabled = historyDetails ? Boolean(historyDetails.value) : false;\n\n return (\n <Suspense fallback={<PageLoader />}>\n <Routes>\n {/* Tabbed landing - default route */}\n <Route index element={<NotificationLandingPage />} />\n\n {/* User-facing routes (all users) */}\n <Route path=\"center\" element={<NotificationCenterPage />} />\n <Route\n path=\"history\"\n element={\n historyEnabled ? (\n <NotificationHistoryAdminPage />\n ) : (\n <FeatureDisabledPage\n title=\"Notification history is not enabled\"\n description=\"This admin page is controlled by the notification.history feature flag. Enable the flag before validating delivery history.\"\n />\n )\n }\n />\n\n {/* Gate admits any actor with read or any write permission; page disables write actions for read-only. */}\n {templatesEnabled && (\n <Route\n path=\"templates\"\n element={\n <AdminRouteGate\n permissions={[\n NOTIFICATION_PERMISSIONS.TEMPLATE_LIST,\n NOTIFICATION_PERMISSIONS.TEMPLATE_CREATE,\n NOTIFICATION_PERMISSIONS.TEMPLATE_UPDATE,\n NOTIFICATION_PERMISSIONS.TEMPLATE_DELETE,\n ]}\n >\n <NotificationTemplatesPage />\n </AdminRouteGate>\n }\n />\n )}\n {templatesEnabled && (\n <Route\n path=\"templates/new\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.TEMPLATE_CREATE}>\n <TemplateEditorPage />\n </AdminRouteGate>\n }\n />\n )}\n {templatesEnabled && (\n <Route\n path=\"templates/:templateId\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.TEMPLATE_UPDATE}>\n <TemplateEditorPage />\n </AdminRouteGate>\n }\n />\n )}\n\n {/* Admin routes - Create/Send Notification (wrapped in PermissionGate) */}\n {createEnabled && (\n <Route\n path=\"create\"\n element={\n <AdminRouteGate\n permissions={[\n NOTIFICATION_PERMISSIONS.NOTIFICATION_CREATE,\n NOTIFICATION_PERMISSIONS.NOTIFICATION_SEND,\n ]}\n requireAll\n >\n <CreateNotificationPage />\n </AdminRouteGate>\n }\n />\n )}\n {/* Topics CRUD maps to `notification:create` per backend @rbac — tracked in BOFF-2386. */}\n {createEnabled && (\n <Route\n path=\"topics\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.NOTIFICATION_CREATE}>\n <NotificationTopicsPage />\n </AdminRouteGate>\n }\n />\n )}\n\n {/* Catch-all route - redirect to index using path-relative navigation */}\n <Route path=\"*\" element={<Navigate to=\"..\" replace relative=\"path\" />} />\n </Routes>\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAcA,IAAM,IAA+B,QACnC,OAAO,2CAAwC,MAAM,OAAO,EAC1D,S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AAA;EACA,CAAA"}
|
|
1
|
+
{"version":3,"file":"AdminNotificationRoutes.js","names":[],"sources":["../src/AdminNotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense, useEffect, type ReactNode } from 'react';\nimport { Navigate, Route, Routes, useNavigate } from 'react-router';\nimport { useFeatureFlagDetails } from '@burdenoff/fe-libs/shared/feature-flags';\nimport { PermissionGate } from '@burdenoff/fe-libs/shared/components';\nimport { useGlobalUi } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { FeatureDisabledPage } from './components/FeatureDisabledPage';\nimport { NOTIFICATION_PERMISSIONS, type NotificationPermission } from './constants/permissions';\nimport { useNotification } from './providers/NotificationProvider';\n\n// Eager load - Primary landing page\nimport { NotificationCenterPage } from './pages/NotificationCenterPage';\nimport { NotificationLandingPage } from './pages/NotificationLandingPage';\n\n// Lazy load - Secondary pages\nconst NotificationHistoryAdminPage = lazy(() =>\n import('./pages/NotificationHistoryAdminPage').then((m) => ({\n default: m.NotificationHistoryAdminPage,\n }))\n);\nconst NotificationTemplatesPage = lazy(() =>\n import('./pages/NotificationTemplatesPage').then((m) => ({\n default: m.NotificationTemplatesPage,\n }))\n);\nconst TemplateEditorPage = lazy(() =>\n import('./pages/TemplateEditorPage').then((m) => ({ default: m.TemplateEditorPage }))\n);\nconst CreateNotificationPage = lazy(() =>\n import('./pages/CreateNotificationPage').then((m) => ({ default: m.CreateNotificationPage }))\n);\nconst NotificationTopicsPage = lazy(() =>\n import('./pages/NotificationTopicsPage').then((m) => ({ default: m.NotificationTopicsPage }))\n);\n\n// Loading fallback component\nfunction PageLoader() {\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// Pair toast + programmatic navigation in one effect to avoid <Navigate> unmounting before the toast fires.\n// Uses absolute `${basePath}/center` because relative `../center` resolves wrong from nested paths like `/templates/new`.\nfunction AccessDeniedRedirect() {\n const { showToast } = useGlobalUi();\n const navigate = useNavigate();\n const { basePath } = useNotification();\n useEffect(() => {\n showToast('You do not have permission to access that notification page.', 'warning');\n navigate(`${basePath}/center`, { replace: true });\n // Run once per access-denied mount; re-running on hook identity changes would duplicate the toast.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return null;\n}\n\n// Discriminated union: callers must pass exactly one of `permission` / `permissions`.\ntype AdminRouteGateProps = {\n children: ReactNode;\n} & (\n | { permission: NotificationPermission; permissions?: never; requireAll?: never }\n | {\n permission?: never;\n permissions: NotificationPermission[];\n requireAll?: boolean;\n }\n);\n\nfunction AdminRouteGate(props: AdminRouteGateProps) {\n const { children, ...gateProps } = props;\n return (\n <PermissionGate\n permission={gateProps.permission}\n permissions={gateProps.permissions}\n requireAll={gateProps.requireAll}\n loading={<PageLoader />}\n fallback={<AccessDeniedRedirect />}\n >\n {children}\n </PermissionGate>\n );\n}\n\n// Admin-app router for the notification MFE. Admin routes are wrapped in PermissionGate.\nexport function AdminNotificationRoutes() {\n const { basePath = '/' } = useNotification();\n const centerPath = `${basePath.endsWith('/') ? basePath.slice(0, -1) : basePath}/center`;\n\n // Explicit `false` fallback prevents provider's default-allow from leaking unseeded flags.\n const templatesDetails = useFeatureFlagDetails('notification.templates');\n const createDetails = useFeatureFlagDetails('notification.create');\n const historyDetails = useFeatureFlagDetails('notification.history');\n const templatesEnabled = templatesDetails ? Boolean(templatesDetails.value) : false;\n const createEnabled = createDetails ? Boolean(createDetails.value) : false;\n const historyEnabled = historyDetails ? Boolean(historyDetails.value) : false;\n\n return (\n <Suspense fallback={<PageLoader />}>\n <Routes>\n {/* Tabbed landing - default route */}\n <Route index element={<NotificationLandingPage />} />\n\n {/* Canonical list alias used by product-shell nav homePath */}\n <Route path=\"list\" element={<NotificationCenterPage />} />\n\n {/* User-facing routes (all users) */}\n <Route path=\"center\" element={<NotificationCenterPage />} />\n <Route\n path=\"history\"\n element={\n historyEnabled ? (\n <NotificationHistoryAdminPage />\n ) : (\n <FeatureDisabledPage\n title=\"Notification history is not enabled\"\n description=\"This admin page is controlled by the notification.history feature flag. Enable the flag before validating delivery history.\"\n />\n )\n }\n />\n\n {/* Gate admits any actor with read or any write permission; page disables write actions for read-only. */}\n {templatesEnabled && (\n <Route\n path=\"templates\"\n element={\n <AdminRouteGate\n permissions={[\n NOTIFICATION_PERMISSIONS.TEMPLATE_LIST,\n NOTIFICATION_PERMISSIONS.TEMPLATE_CREATE,\n NOTIFICATION_PERMISSIONS.TEMPLATE_UPDATE,\n NOTIFICATION_PERMISSIONS.TEMPLATE_DELETE,\n ]}\n >\n <NotificationTemplatesPage />\n </AdminRouteGate>\n }\n />\n )}\n {templatesEnabled && (\n <Route\n path=\"templates/new\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.TEMPLATE_CREATE}>\n <TemplateEditorPage />\n </AdminRouteGate>\n }\n />\n )}\n {templatesEnabled && (\n <Route\n path=\"templates/:templateId\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.TEMPLATE_UPDATE}>\n <TemplateEditorPage />\n </AdminRouteGate>\n }\n />\n )}\n\n {/* Admin routes - Create/Send Notification (wrapped in PermissionGate) */}\n {createEnabled && (\n <Route\n path=\"create\"\n element={\n <AdminRouteGate\n permissions={[\n NOTIFICATION_PERMISSIONS.NOTIFICATION_CREATE,\n NOTIFICATION_PERMISSIONS.NOTIFICATION_SEND,\n ]}\n requireAll\n >\n <CreateNotificationPage />\n </AdminRouteGate>\n }\n />\n )}\n {/* Topics CRUD maps to `notification:create` per backend @rbac — tracked in BOFF-2386. */}\n {createEnabled && (\n <Route\n path=\"topics\"\n element={\n <AdminRouteGate permission={NOTIFICATION_PERMISSIONS.NOTIFICATION_CREATE}>\n <NotificationTopicsPage />\n </AdminRouteGate>\n }\n />\n )}\n\n {/* Catch-all route - absolute redirect so an unmatched path like /list\n cannot recursively append /center (e.g. /list/center/center/...) */}\n <Route path=\"*\" element={<Navigate to={centerPath} replace />} />\n </Routes>\n </Suspense>\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CAAA;IAEnB,CAAA;GAGH,KACC,kBAAC,GAAD;IACE,MAAK;IACL,SACE,kBAAC,GAAD;KAAgB,YAAY,EAAyB;eACnD,kBAAC,GAAD,EAA0B,CAAA;KACX,CAAA;IAEnB,CAAA;GAKJ,kBAAC,GAAD;IAAO,MAAK;IAAI,SAAS,kBAAC,GAAD;KAAU,IAAI;KAAY,SAAA;KAAU,CAAA;IAAI,CAAA;GAC1D,EAAA,CAAA;EACA,CAAA"}
|
|
@@ -1,60 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { useNotification as e } from "./providers/NotificationProvider.js";
|
|
2
|
+
import { NotificationCenterPage as t } from "./pages/NotificationCenterPage.js";
|
|
3
|
+
import { NotificationLandingPage as n } from "./pages/NotificationLandingPage.js";
|
|
4
|
+
import { Suspense as r, lazy as i } from "react";
|
|
5
|
+
import { Navigate as a, Route as o, Routes as s } from "react-router";
|
|
6
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
6
7
|
//#region src/NotificationRoutes.tsx
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
return /* @__PURE__ */
|
|
8
|
+
var u = i(() => import("./pages/NotificationHistoryPage.js").then((e) => ({ default: e.NotificationHistoryPage }))), d = i(() => import("./pages/NotificationTemplatesPage.js").then((e) => ({ default: e.NotificationTemplatesPage }))), f = i(() => import("./pages/TemplateEditorPage.js").then((e) => ({ default: e.TemplateEditorPage }))), p = i(() => import("./pages/CreateNotificationPage.js").then((e) => ({ default: e.CreateNotificationPage }))), m = i(() => import("./pages/NotificationTopicsPage.js").then((e) => ({ default: e.NotificationTopicsPage }))), h = i(() => import("./pages/NotificationPreferencesPage.js").then((e) => ({ default: e.NotificationPreferencesPage })));
|
|
9
|
+
function g() {
|
|
10
|
+
return /* @__PURE__ */ c("div", {
|
|
10
11
|
className: "flex h-64 items-center justify-center",
|
|
11
|
-
children: /* @__PURE__ */
|
|
12
|
+
children: /* @__PURE__ */ c("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
function _() {
|
|
16
|
+
let { basePath: i = "/" } = e(), _ = `${i.endsWith("/") ? i.slice(0, -1) : i}/center`;
|
|
17
|
+
return /* @__PURE__ */ c(r, {
|
|
18
|
+
fallback: /* @__PURE__ */ c(g, {}),
|
|
19
|
+
children: /* @__PURE__ */ l(s, { children: [
|
|
20
|
+
/* @__PURE__ */ c(o, {
|
|
19
21
|
index: !0,
|
|
20
|
-
element: /* @__PURE__ */
|
|
22
|
+
element: /* @__PURE__ */ c(n, {})
|
|
23
|
+
}),
|
|
24
|
+
/* @__PURE__ */ c(o, {
|
|
25
|
+
path: "list",
|
|
26
|
+
element: /* @__PURE__ */ c(t, {})
|
|
21
27
|
}),
|
|
22
|
-
/* @__PURE__ */
|
|
28
|
+
/* @__PURE__ */ c(o, {
|
|
23
29
|
path: "center",
|
|
24
|
-
element: /* @__PURE__ */
|
|
30
|
+
element: /* @__PURE__ */ c(t, {})
|
|
25
31
|
}),
|
|
26
|
-
/* @__PURE__ */
|
|
32
|
+
/* @__PURE__ */ c(o, {
|
|
27
33
|
path: "history",
|
|
28
|
-
element: /* @__PURE__ */
|
|
34
|
+
element: /* @__PURE__ */ c(u, {})
|
|
29
35
|
}),
|
|
30
|
-
/* @__PURE__ */
|
|
36
|
+
/* @__PURE__ */ c(o, {
|
|
31
37
|
path: "templates",
|
|
32
|
-
element: /* @__PURE__ */
|
|
38
|
+
element: /* @__PURE__ */ c(d, {})
|
|
33
39
|
}),
|
|
34
|
-
/* @__PURE__ */
|
|
40
|
+
/* @__PURE__ */ c(o, {
|
|
35
41
|
path: "templates/new",
|
|
36
|
-
element: /* @__PURE__ */
|
|
42
|
+
element: /* @__PURE__ */ c(f, {})
|
|
37
43
|
}),
|
|
38
|
-
/* @__PURE__ */
|
|
44
|
+
/* @__PURE__ */ c(o, {
|
|
39
45
|
path: "templates/:templateId",
|
|
40
|
-
element: /* @__PURE__ */
|
|
46
|
+
element: /* @__PURE__ */ c(f, {})
|
|
41
47
|
}),
|
|
42
|
-
/* @__PURE__ */
|
|
48
|
+
/* @__PURE__ */ c(o, {
|
|
43
49
|
path: "create",
|
|
44
|
-
element: /* @__PURE__ */
|
|
50
|
+
element: /* @__PURE__ */ c(p, {})
|
|
45
51
|
}),
|
|
46
|
-
/* @__PURE__ */
|
|
52
|
+
/* @__PURE__ */ c(o, {
|
|
47
53
|
path: "topics",
|
|
48
|
-
element: /* @__PURE__ */
|
|
54
|
+
element: /* @__PURE__ */ c(m, {})
|
|
49
55
|
}),
|
|
50
|
-
/* @__PURE__ */
|
|
56
|
+
/* @__PURE__ */ c(o, {
|
|
51
57
|
path: "preferences",
|
|
52
|
-
element: /* @__PURE__ */
|
|
58
|
+
element: /* @__PURE__ */ c(h, {})
|
|
53
59
|
}),
|
|
54
|
-
/* @__PURE__ */
|
|
60
|
+
/* @__PURE__ */ c(o, {
|
|
55
61
|
path: "*",
|
|
56
|
-
element: /* @__PURE__ */
|
|
57
|
-
to:
|
|
62
|
+
element: /* @__PURE__ */ c(a, {
|
|
63
|
+
to: _,
|
|
58
64
|
replace: !0
|
|
59
65
|
})
|
|
60
66
|
})
|
|
@@ -62,6 +68,6 @@ function g() {
|
|
|
62
68
|
});
|
|
63
69
|
}
|
|
64
70
|
//#endregion
|
|
65
|
-
export {
|
|
71
|
+
export { _ as NotificationRoutes };
|
|
66
72
|
|
|
67
73
|
//# sourceMappingURL=NotificationRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationRoutes.js","names":[],"sources":["../src/NotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense } from 'react';\nimport { Navigate, Route, Routes } from 'react-router
|
|
1
|
+
{"version":3,"file":"NotificationRoutes.js","names":[],"sources":["../src/NotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense } from 'react';\nimport { Navigate, Route, Routes } from 'react-router';\nimport { useNotification } from './providers/NotificationProvider';\n\n// Eager load - Primary landing page\nimport { NotificationCenterPage } from './pages/NotificationCenterPage';\nimport { NotificationLandingPage } from './pages/NotificationLandingPage';\n\n// Lazy load - Secondary pages\nconst NotificationHistoryPage = lazy(() =>\n import('./pages/NotificationHistoryPage').then((m) => ({\n default: m.NotificationHistoryPage,\n }))\n);\nconst NotificationTemplatesPage = lazy(() =>\n import('./pages/NotificationTemplatesPage').then((m) => ({\n default: m.NotificationTemplatesPage,\n }))\n);\nconst TemplateEditorPage = lazy(() =>\n import('./pages/TemplateEditorPage').then((m) => ({ default: m.TemplateEditorPage }))\n);\nconst CreateNotificationPage = lazy(() =>\n import('./pages/CreateNotificationPage').then((m) => ({ default: m.CreateNotificationPage }))\n);\nconst NotificationTopicsPage = lazy(() =>\n import('./pages/NotificationTopicsPage').then((m) => ({ default: m.NotificationTopicsPage }))\n);\nconst NotificationPreferencesPage = lazy(() =>\n import('./pages/NotificationPreferencesPage').then((m) => ({\n default: m.NotificationPreferencesPage,\n }))\n);\n\n// Loading fallback component\nfunction PageLoader() {\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/**\n * Internal router for the Notification microfrontend.\n * This component handles routing within the microfrontend using React Router v7.\n *\n * Routes:\n * - / → Notification landing page\n * - /list → Notification center (canonical list alias used by shell nav homePath)\n * - /center → Notification center (in-app notifications)\n * - /history → Notification history and archive\n * - /templates → Notification templates list (admin)\n * - /templates/new → Create new template (admin)\n * - /templates/:templateId → Edit template (admin)\n * - /create → Create and send notification (admin)\n * - /topics → Manage topics (admin)\n * - /preferences → User topic preferences\n * - unmatched → Absolute redirect to /{basePath}/center (avoids relative redirect loops)\n */\nexport function NotificationRoutes() {\n const { basePath = '/' } = useNotification();\n const centerPath = `${basePath.endsWith('/') ? basePath.slice(0, -1) : basePath}/center`;\n\n return (\n <Suspense fallback={<PageLoader />}>\n <Routes>\n {/* Tabbed landing - default route */}\n <Route index element={<NotificationLandingPage />} />\n\n {/* Canonical list alias used by product-shell nav homePath */}\n <Route path=\"list\" element={<NotificationCenterPage />} />\n\n {/* User-facing routes (all users) */}\n <Route path=\"center\" element={<NotificationCenterPage />} />\n <Route path=\"history\" element={<NotificationHistoryPage />} />\n\n {/* Admin routes - Templates */}\n <Route path=\"templates\" element={<NotificationTemplatesPage />} />\n <Route path=\"templates/new\" element={<TemplateEditorPage />} />\n <Route path=\"templates/:templateId\" element={<TemplateEditorPage />} />\n\n {/* Admin routes - Create/Send Notification */}\n <Route path=\"create\" element={<CreateNotificationPage />} />\n <Route path=\"topics\" element={<NotificationTopicsPage />} />\n <Route path=\"preferences\" element={<NotificationPreferencesPage />} />\n\n {/* Catch-all route - absolute redirect so an unmatched path like /list\n cannot recursively append /center (e.g. /list/center/center/...) */}\n <Route path=\"*\" element={<Navigate to={centerPath} replace />} />\n </Routes>\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;AASA,IAAM,IAA0B,QAC9B,OAAO,sCAAmC,MAAM,OAAO,EACrD,SAAS,EAAE,yBACZ,EAAE,CACJ,EACK,IAA4B,QAChC,OAAO,wCAAqC,MAAM,OAAO,EACvD,SAAS,EAAE,2BACZ,EAAE,CACJ,EACK,IAAqB,QACzB,OAAO,iCAA8B,MAAM,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,CACtF,EACK,IAAyB,QAC7B,OAAO,qCAAkC,MAAM,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAC9F,EACK,IAAyB,QAC7B,OAAO,qCAAkC,MAAM,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAC9F,EACK,IAA8B,QAClC,OAAO,0CAAuC,MAAM,OAAO,EACzD,SAAS,EAAE,6BACZ,EAAE,CACJ;A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AAU,IAAI;KAAY,SAAA;KAAU,CAAA;IAAI,CAAA;GAC1D,EAAA,CAAA;EACA,CAAA"}
|
|
@@ -1,56 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { useNotification as e } from "./providers/NotificationProvider.js";
|
|
2
|
+
import { NotificationCenterPage as t } from "./pages/NotificationCenterPage.js";
|
|
3
|
+
import { FeatureDisabledPage as n } from "./components/FeatureDisabledPage.js";
|
|
4
|
+
import { Suspense as r, lazy as i } from "react";
|
|
5
|
+
import { useFeatureFlagDetails as a } from "@burdenoff/fe-libs/shared/feature-flags";
|
|
6
|
+
import { Navigate as o, Route as s, Routes as c } from "react-router";
|
|
7
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
7
8
|
//#region src/UserNotificationRoutes.tsx
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
-
return /* @__PURE__ */
|
|
9
|
+
var d = i(() => import("./pages/NotificationHistoryPage.js").then((e) => ({ default: e.NotificationHistoryPage }))), f = i(() => import("./pages/NotificationPreferencesPage.js").then((e) => ({ default: e.NotificationPreferencesPage })));
|
|
10
|
+
function p() {
|
|
11
|
+
return /* @__PURE__ */ l("div", {
|
|
11
12
|
className: "flex h-64 items-center justify-center",
|
|
12
|
-
children: /* @__PURE__ */
|
|
13
|
+
children: /* @__PURE__ */ l("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" })
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
let
|
|
17
|
-
return /* @__PURE__ */
|
|
18
|
-
fallback: /* @__PURE__ */
|
|
19
|
-
children: /* @__PURE__ */
|
|
20
|
-
/* @__PURE__ */
|
|
16
|
+
function m() {
|
|
17
|
+
let { basePath: i = "/" } = e(), m = `${i.endsWith("/") ? i.slice(0, -1) : i}/center`, h = a("notification.history"), g = h ? !!h.value : !1;
|
|
18
|
+
return /* @__PURE__ */ l(r, {
|
|
19
|
+
fallback: /* @__PURE__ */ l(p, {}),
|
|
20
|
+
children: /* @__PURE__ */ u(c, { children: [
|
|
21
|
+
/* @__PURE__ */ l(s, {
|
|
21
22
|
index: !0,
|
|
22
|
-
element: /* @__PURE__ */
|
|
23
|
-
to:
|
|
23
|
+
element: /* @__PURE__ */ l(o, {
|
|
24
|
+
to: m,
|
|
24
25
|
replace: !0
|
|
25
26
|
})
|
|
26
27
|
}),
|
|
27
|
-
/* @__PURE__ */
|
|
28
|
+
/* @__PURE__ */ l(s, {
|
|
29
|
+
path: "list",
|
|
30
|
+
element: /* @__PURE__ */ l(t, {})
|
|
31
|
+
}),
|
|
32
|
+
/* @__PURE__ */ l(s, {
|
|
28
33
|
path: "center",
|
|
29
|
-
element: /* @__PURE__ */
|
|
34
|
+
element: /* @__PURE__ */ l(t, {})
|
|
30
35
|
}),
|
|
31
|
-
/* @__PURE__ */
|
|
36
|
+
/* @__PURE__ */ l(s, {
|
|
32
37
|
path: "history",
|
|
33
|
-
element:
|
|
38
|
+
element: g ? /* @__PURE__ */ l(d, {}) : /* @__PURE__ */ l(n, {
|
|
34
39
|
title: "Notification history is not enabled",
|
|
35
40
|
description: "This page is controlled by the notification.history feature flag. Ask an administrator to enable it for this tenant if history should be available."
|
|
36
41
|
})
|
|
37
42
|
}),
|
|
38
|
-
/* @__PURE__ */
|
|
43
|
+
/* @__PURE__ */ l(s, {
|
|
39
44
|
path: "preferences",
|
|
40
|
-
element: /* @__PURE__ */
|
|
45
|
+
element: /* @__PURE__ */ l(f, {})
|
|
41
46
|
}),
|
|
42
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ l(s, {
|
|
43
48
|
path: "*",
|
|
44
|
-
element: /* @__PURE__ */
|
|
45
|
-
to:
|
|
46
|
-
replace: !0
|
|
47
|
-
relative: "path"
|
|
49
|
+
element: /* @__PURE__ */ l(o, {
|
|
50
|
+
to: m,
|
|
51
|
+
replace: !0
|
|
48
52
|
})
|
|
49
53
|
})
|
|
50
54
|
] })
|
|
51
55
|
});
|
|
52
56
|
}
|
|
53
57
|
//#endregion
|
|
54
|
-
export {
|
|
58
|
+
export { m as UserNotificationRoutes };
|
|
55
59
|
|
|
56
60
|
//# sourceMappingURL=UserNotificationRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserNotificationRoutes.js","names":[],"sources":["../src/UserNotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense } from 'react';\nimport { Navigate, Route, Routes } from 'react-router
|
|
1
|
+
{"version":3,"file":"UserNotificationRoutes.js","names":[],"sources":["../src/UserNotificationRoutes.tsx"],"sourcesContent":["import { lazy, Suspense } from 'react';\nimport { Navigate, Route, Routes } from 'react-router';\nimport { useFeatureFlagDetails } from '@burdenoff/fe-libs/shared/feature-flags';\nimport { FeatureDisabledPage } from './components/FeatureDisabledPage';\nimport { useNotification } from './providers/NotificationProvider';\n\n// Eager load - Primary landing page\nimport { NotificationCenterPage } from './pages/NotificationCenterPage';\n\n// Lazy load - Secondary pages\nconst NotificationHistoryPage = lazy(() =>\n import('./pages/NotificationHistoryPage').then((m) => ({\n default: m.NotificationHistoryPage,\n }))\n);\nconst NotificationPreferencesPage = lazy(() =>\n import('./pages/NotificationPreferencesPage').then((m) => ({\n default: m.NotificationPreferencesPage,\n }))\n);\n\n// Loading fallback component\nfunction PageLoader() {\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/**\n * Internal router for the User-facing Notification microfrontend.\n * This component handles routing within the microfrontend using React Router v7.\n *\n * Only exposes user-facing routes intended for product shells. RBAC permissions\n * still gate in-page actions via usePermissions checks.\n *\n * Routes:\n * - / → Redirect to notification center\n * - /list → Notification center (canonical list alias used by shell nav homePath)\n * - /center → Notification center (in-app notifications)\n * - /history → Notification history and archive\n * - /preferences → Topic subscriptions and preferences\n * - unmatched → Absolute redirect to /{basePath}/center (avoids relative redirect loops)\n */\nexport function UserNotificationRoutes() {\n const { basePath = '/' } = useNotification();\n const centerPath = `${basePath.endsWith('/') ? basePath.slice(0, -1) : basePath}/center`;\n\n // Component-level feature gate. `notification.history` is declared as\n // unreleased (defaultValue=false). We use `useFeatureFlagDetails` and\n // explicitly fall back to `false` when the flag is absent from the cache,\n // because the provider's global default-allow would otherwise return `true`\n // for unseeded flags — which would defeat the whole point of the unreleased\n // pattern.\n const historyDetails = useFeatureFlagDetails('notification.history');\n const historyEnabled = historyDetails ? Boolean(historyDetails.value) : false;\n\n return (\n <Suspense fallback={<PageLoader />}>\n <Routes>\n {/* Default redirect to notification center */}\n <Route index element={<Navigate to={centerPath} replace />} />\n\n {/* Canonical list alias used by product-shell nav homePath */}\n <Route path=\"list\" element={<NotificationCenterPage />} />\n\n {/* User-facing routes (all users) */}\n <Route path=\"center\" element={<NotificationCenterPage />} />\n <Route\n path=\"history\"\n element={\n historyEnabled ? (\n <NotificationHistoryPage />\n ) : (\n <FeatureDisabledPage\n title=\"Notification history is not enabled\"\n description=\"This page is controlled by the notification.history feature flag. Ask an administrator to enable it for this tenant if history should be available.\"\n />\n )\n }\n />\n <Route path=\"preferences\" element={<NotificationPreferencesPage />} />\n\n {/* Catch-all route - absolute redirect so an unmatched path like /list\n cannot recursively append /center (e.g. /list/center/center/...) */}\n <Route path=\"*\" element={<Navigate to={centerPath} replace />} />\n </Routes>\n </Suspense>\n );\n}\n"],"mappings":";;;;;;;;AAUA,IAAM,IAA0B,QAC9B,OAAO,sCAAmC,MAAM,OAAO,EACrD,SAAS,EAAE,yBACZ,EAAE,CACJ,EACK,IAA8B,QAClC,OAAO,0CAAuC,MAAM,OAAO,EACzD,SAAS,EAAE,6BACZ,EAAE,CACJ;AAGD,SAAS,IAAa;AACpB,QACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,OAAD,EAAK,WAAU,kFAAmF,CAAA;EAC9F,CAAA;;AAmBV,SAAgB,IAAyB;CACvC,IAAM,EAAE,cAAW,QAAQ,GAAiB,EACtC,IAAa,GAAG,EAAS,SAAS,IAAI,GAAG,EAAS,MAAM,GAAG,GAAG,GAAG,EAAS,UAQ1E,IAAiB,EAAsB,uBAAuB,EAC9D,IAAiB,IAAiB,EAAQ,EAAe,QAAS;AAExE,QACE,kBAAC,GAAD;EAAU,UAAU,kBAAC,GAAD,EAAc,CAAA;YAChC,kBAAC,GAAD,EAAA,UAAA;GAEE,kBAAC,GAAD;IAAO,OAAA;IAAM,SAAS,kBAAC,GAAD;KAAU,IAAI;KAAY,SAAA;KAAU,CAAA;IAAI,CAAA;GAG9D,kBAAC,GAAD;IAAO,MAAK;IAAO,SAAS,kBAAC,GAAD,EAA0B,CAAA;IAAI,CAAA;GAG1D,kBAAC,GAAD;IAAO,MAAK;IAAS,SAAS,kBAAC,GAAD,EAA0B,CAAA;IAAI,CAAA;GAC5D,kBAAC,GAAD;IACE,MAAK;IACL,SACE,IACE,kBAAC,GAAD,EAA2B,CAAA,GAE3B,kBAAC,GAAD;KACE,OAAM;KACN,aAAY;KACZ,CAAA;IAGN,CAAA;GACF,kBAAC,GAAD;IAAO,MAAK;IAAc,SAAS,kBAAC,GAAD,EAA+B,CAAA;IAAI,CAAA;GAItE,kBAAC,GAAD;IAAO,MAAK;IAAI,SAAS,kBAAC,GAAD;KAAU,IAAI;KAAY,SAAA;KAAU,CAAA;IAAI,CAAA;GAC1D,EAAA,CAAA;EACA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecipientSelector.js","names":[],"sources":["../../src/components/RecipientSelector.tsx"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from 'react';\nimport { X, Plus, Mail, Phone, User, Users, AlertCircle } from 'lucide-react';\nimport type { RecipientInput, NotificationChannelType } from '../hooks/useSendNotification';\nimport { useTr } from '../shared/hooks/useTr';\n\n/**\n * Recipient with display info\n */\nexport interface Recipient extends RecipientInput {\n id: string;\n displayName: string;\n type: 'email' | 'phone' | 'user' | 'manual';\n}\n\ninterface RecipientSelectorProps {\n recipients: Recipient[];\n onChange: (recipients: Recipient[]) => void;\n channel: NotificationChannelType;\n placeholder?: string;\n disabled?: boolean;\n maxRecipients?: number;\n error?: string;\n}\n\n/**\n * Get icon for recipient type\n */\nfunction getRecipientIcon(type: Recipient['type']) {\n switch (type) {\n case 'email':\n return <Mail size={14} className=\"text-status-info-text\" />;\n case 'phone':\n return <Phone size={14} className=\"text-status-success-text\" />;\n case 'user':\n return <User size={14} className=\"text-accent-purple\" />;\n default:\n return <User size={14} className=\"text-text-secondary\" />;\n }\n}\n\n/**\n * Validate email format\n */\nfunction isValidEmail(email: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n\n/**\n * Validate phone format (basic validation)\n */\nfunction isValidPhone(phone: string): boolean {\n const phoneRegex = /^\\+?[1-9]\\d{6,14}$/;\n return phoneRegex.test(phone.replace(/[\\s\\-\\(\\)]/g, ''));\n}\n\n/**\n * Generate unique ID\n */\nfunction generateId(): string {\n return `recipient-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n}\n\n/**\n * RecipientSelector component\n *\n * Allows selecting multiple recipients for notifications.\n * Supports email, phone, and manual input based on channel type.\n */\nexport function RecipientSelector({\n recipients,\n onChange,\n channel,\n placeholder,\n disabled = false,\n maxRecipients = 100,\n error,\n}: RecipientSelectorProps) {\n const tr = useTr();\n const [inputValue, setInputValue] = useState('');\n const [inputError, setInputError] = useState<string | null>(null);\n const [isFocused, setIsFocused] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n\n // Determine input type based on channel\n const inputType =\n channel === 'EMAIL' ? 'email' : channel === 'SMS' || channel === 'WHATSAPP' ? 'phone' : 'text';\n const inputPlaceholder =\n placeholder ||\n (channel === 'EMAIL'\n ? tr('notifCommon.enterEmailPlaceholder', 'Enter email address...')\n : channel === 'SMS' || channel === 'WHATSAPP'\n ? tr('notifCommon.enterPhonePlaceholder', 'Enter phone number (e.g., +1234567890)...')\n : channel === 'PUSH'\n ? tr('notifCommon.enterDeviceTokenPlaceholder', 'Enter device token...')\n : channel === 'SLACK'\n ? tr('notifCommon.enterSlackIdPlaceholder', 'Enter Slack user ID...')\n : channel === 'TEAMS'\n ? tr('notifCommon.enterTeamsIdPlaceholder', 'Enter Teams user ID...')\n : tr('notifCommon.enterRecipientPlaceholder', 'Enter recipient...'));\n\n // Clear input error when input changes\n useEffect(() => {\n if (inputValue) {\n setInputError(null);\n }\n }, [inputValue]);\n\n /**\n * Add a recipient\n */\n const addRecipient = useCallback(\n (value: string) => {\n const trimmedValue = value.trim();\n if (!trimmedValue) return;\n\n // Check max recipients\n if (recipients.length >= maxRecipients) {\n setInputError(\n tr('notifCommon.maxRecipientsAllowed', `Maximum ${maxRecipients} recipients allowed`)\n );\n return;\n }\n\n // Check for duplicates\n const isDuplicate = recipients.some((r) => {\n if (channel === 'EMAIL') return r.email === trimmedValue;\n if (channel === 'SMS' || channel === 'WHATSAPP')\n return r.phoneNumber === trimmedValue || r.whatsappNumber === trimmedValue;\n return false;\n });\n\n if (isDuplicate) {\n setInputError(\n tr('notifCommon.duplicateRecipient', 'This recipient has already been added')\n );\n return;\n }\n\n // Validate based on channel\n let recipient: Recipient | null = null;\n\n if (channel === 'EMAIL') {\n if (!isValidEmail(trimmedValue)) {\n setInputError(tr('notifCommon.invalidEmail', 'Please enter a valid email address'));\n return;\n }\n recipient = {\n id: generateId(),\n email: trimmedValue,\n displayName: trimmedValue,\n type: 'email',\n };\n } else if (channel === 'SMS') {\n if (!isValidPhone(trimmedValue)) {\n setInputError(\n tr('notifCommon.invalidPhone', 'Please enter a valid phone number (e.g., +1234567890)')\n );\n return;\n }\n recipient = {\n id: generateId(),\n phoneNumber: trimmedValue,\n displayName: trimmedValue,\n type: 'phone',\n };\n } else if (channel === 'WHATSAPP') {\n if (!isValidPhone(trimmedValue)) {\n setInputError(\n tr(\n 'notifCommon.invalidWhatsApp',\n 'Please enter a valid WhatsApp number (e.g., +1234567890)'\n )\n );\n return;\n }\n recipient = {\n id: generateId(),\n whatsappNumber: trimmedValue,\n displayName: trimmedValue,\n type: 'phone',\n };\n } else if (channel === 'PUSH') {\n recipient = {\n id: generateId(),\n pushToken: trimmedValue,\n displayName: trimmedValue.substring(0, 20) + '...',\n type: 'manual',\n };\n } else if (channel === 'SLACK') {\n recipient = {\n id: generateId(),\n slackUserId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n } else if (channel === 'TEAMS') {\n recipient = {\n id: generateId(),\n teamsUserId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n } else if (channel === 'WEBHOOK') {\n recipient = {\n id: generateId(),\n webhookUrl: trimmedValue,\n displayName: trimmedValue,\n type: 'manual',\n };\n } else {\n // Other channels - use userId\n recipient = {\n id: generateId(),\n userId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n }\n\n if (recipient) {\n onChange([...recipients, recipient]);\n setInputValue('');\n setInputError(null);\n }\n },\n [recipients, onChange, channel, maxRecipients, tr]\n );\n\n /**\n * Remove a recipient\n */\n const removeRecipient = useCallback(\n (id: string) => {\n onChange(recipients.filter((r) => r.id !== id));\n },\n [recipients, onChange]\n );\n\n /**\n * Handle key down\n */\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter' || e.key === ',') {\n e.preventDefault();\n addRecipient(inputValue);\n } else if (e.key === 'Backspace' && !inputValue && recipients.length > 0) {\n // Remove last recipient on backspace when input is empty\n removeRecipient(recipients[recipients.length - 1].id);\n }\n };\n\n /**\n * Handle paste (for bulk adding)\n */\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n const pastedText = e.clipboardData.getData('text');\n\n // Check if pasted text contains multiple values (comma or newline separated)\n if (pastedText.includes(',') || pastedText.includes('\\n')) {\n e.preventDefault();\n const values = pastedText\n .split(/[,\\n]/)\n .map((v) => v.trim())\n .filter(Boolean);\n\n values.forEach((value) => {\n addRecipient(value);\n });\n }\n };\n\n return (\n <div className=\"space-y-2\">\n {/* Input container */}\n <div\n className={`\n relative flex flex-wrap items-center gap-2 p-2 min-h-[42px]\n bg-surface border rounded-lg transition-colors\n ${isFocused ? 'border-primary-500 ring-1 ring-primary-500' : 'border-border-subtle'}\n ${disabled ? 'opacity-50 cursor-not-allowed bg-bg-sunken' : ''}\n ${error || inputError ? 'border-error-500' : ''}\n `}\n onClick={() => inputRef.current?.focus()}\n >\n {/* Selected recipients */}\n {recipients.map((recipient) => (\n <div\n key={recipient.id}\n className=\"flex items-center gap-1.5 px-2 py-1 bg-surface-elevated border border-border-subtle rounded-full text-sm\"\n >\n {getRecipientIcon(recipient.type)}\n <span className=\"text-text-primary max-w-[200px] truncate\">{recipient.displayName}</span>\n {!disabled && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeRecipient(recipient.id);\n }}\n className=\"p-0.5 hover:bg-surface-hover rounded-full transition-colors\"\n aria-label={tr('notifCommon.removeRecipient', 'Remove {{name}}').replace(\n '{{name}}',\n recipient.displayName\n )}\n >\n <X size={12} className=\"text-text-secondary\" />\n </button>\n )}\n </div>\n ))}\n\n {/* Input */}\n {!disabled && recipients.length < maxRecipients && (\n <input\n ref={inputRef}\n type={inputType}\n value={inputValue}\n onChange={(e) => setInputValue(e.target.value)}\n onKeyDown={handleKeyDown}\n onPaste={handlePaste}\n onFocus={() => setIsFocused(true)}\n onBlur={() => {\n setIsFocused(false);\n if (inputValue.trim()) {\n addRecipient(inputValue);\n }\n }}\n placeholder={\n recipients.length === 0 ? inputPlaceholder : tr('notifCommon.addMore', 'Add more...')\n }\n className=\"flex-1 min-w-[150px] bg-transparent border-none outline-none text-sm text-text-primary placeholder:text-text-secondary\"\n disabled={disabled}\n />\n )}\n\n {/* Add button for clarity */}\n {!disabled && inputValue.trim() && (\n <button\n type=\"button\"\n onClick={() => addRecipient(inputValue)}\n className=\"p-1 text-primary-500 hover:bg-primary-100 rounded transition-colors\"\n aria-label={tr('notifCommon.addRecipient', 'Add recipient')}\n >\n <Plus size={16} />\n </button>\n )}\n </div>\n\n {/* Error message */}\n {(error || inputError) && (\n <div className=\"flex items-center gap-1.5 text-error-500 text-sm\">\n <AlertCircle size={14} />\n <span>{error || inputError}</span>\n </div>\n )}\n\n {/* Helper text */}\n <div className=\"flex items-center justify-between text-xs text-text-secondary\">\n <span>\n {channel === 'EMAIL' &&\n tr(\n 'notifCommon.emailHelperText',\n 'Enter email addresses. Press Enter or comma to add multiple.'\n )}\n {(channel === 'SMS' || channel === 'WHATSAPP') &&\n tr(\n 'notifCommon.phoneHelperText',\n 'Enter phone numbers with country code (e.g., +1234567890).'\n )}\n\n {channel === 'PUSH' &&\n tr('notifCommon.pushHelperText', 'Enter device tokens for push notifications.')}\n {channel === 'SLACK' && tr('notifCommon.slackHelperText', 'Enter Slack user IDs.')}\n {channel === 'TEAMS' &&\n tr('notifCommon.teamsHelperText', 'Enter Microsoft Teams user IDs.')}\n {channel === 'WEBHOOK' && tr('notifCommon.webhookHelperText', 'Enter webhook URLs.')}\n </span>\n <span>\n {recipients.length} / {maxRecipients}\n </span>\n </div>\n </div>\n );\n}\n\n/**\n * Compact recipient display for read-only views\n */\nexport function RecipientList({ recipients }: { recipients: Recipient[] }) {\n const tr = useTr();\n\n if (recipients.length === 0) {\n return (\n <span className=\"text-text-secondary text-sm\">\n {tr('notifCommon.noRecipients', 'No recipients')}\n </span>\n );\n }\n\n return (\n <div className=\"flex flex-wrap items-center gap-1.5\">\n {recipients.slice(0, 5).map((recipient) => (\n <div\n key={recipient.id}\n className=\"flex items-center gap-1 px-2 py-0.5 bg-surface-elevated border border-border-subtle rounded-full text-xs\"\n >\n {getRecipientIcon(recipient.type)}\n <span className=\"text-text-primary max-w-[150px] truncate\">{recipient.displayName}</span>\n </div>\n ))}\n {recipients.length > 5 && (\n <span className=\"flex items-center gap-1 px-2 py-0.5 bg-bg-sunken text-text-secondary rounded-full text-xs\">\n <Users size={12} />+{recipients.length - 5} {tr('notifCommon.more', 'more')}\n </span>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;AA2BA,SAAS,EAAiB,GAAyB;AACjD,SAAQ,GAAR;EACE,KAAK,QACH,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAA0B,CAAA;EAC7D,KAAK,QACH,QAAO,kBAAC,GAAD;GAAO,MAAM;GAAI,WAAU;GAA6B,CAAA;EACjE,KAAK,OACH,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAAuB,CAAA;EAC1D,QACE,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAAwB,CAAA;;;AAO/D,SAAS,EAAa,GAAwB;AAE5C,QADmB,6BACD,KAAK,EAAM;;AAM/B,SAAS,EAAa,GAAwB;AAE5C,QADmB,qBACD,KAAK,EAAM,QAAQ,eAAe,GAAG,CAAC;;AAM1D,SAAS,IAAqB;AAC5B,QAAO,aAAa,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,GAAG,EAAE;;AAS3E,SAAgB,EAAkB,EAChC,eACA,aACA,YACA,gBACA,cAAW,IACX,mBAAgB,KAChB,YACyB;CACzB,IAAM,IAAK,GAAO,EACZ,CAAC,GAAY,KAAiB,EAAS,GAAG,EAC1C,CAAC,GAAY,KAAiB,EAAwB,KAAK,EAC3D,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,IAAW,EAAyB,KAAK,EAGzC,IACJ,MAAY,UAAU,UAAU,MAAY,SAAS,MAAY,aAAa,UAAU,QACpF,IACJ,MACC,MAAY,UACT,EAAG,qCAAqC,yBAAyB,GACjE,MAAY,SAAS,MAAY,aAC/B,EAAG,qCAAqC,4CAA4C,GACpF,MAAY,SACV,EAAG,2CAA2C,wBAAwB,GACtE,MAAY,UACV,EAAG,uCAAuC,yBAAyB,GACnE,MAAY,UACV,EAAG,uCAAuC,yBAA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,CAAA,EACP,kBAAC,QAAD,EAAA,UAAA;KACG,EAAW;KAAO;KAAI;KAClB,EAAA,CAAA,CACH;;GACF"}
|
|
1
|
+
{"version":3,"file":"RecipientSelector.js","names":[],"sources":["../../src/components/RecipientSelector.tsx"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from 'react';\nimport { X, Plus, Mail, Phone, User, Users, AlertCircle } from 'lucide-react';\nimport type { RecipientInput, NotificationChannelType } from '../hooks/useSendNotification';\nimport { useTr } from '../shared/hooks/useTr';\n\n/**\n * Recipient with display info\n */\nexport interface Recipient extends RecipientInput {\n id: string;\n displayName: string;\n type: 'email' | 'phone' | 'user' | 'manual';\n}\n\ninterface RecipientSelectorProps {\n recipients: Recipient[];\n onChange: (recipients: Recipient[]) => void;\n channel: NotificationChannelType;\n placeholder?: string;\n disabled?: boolean;\n maxRecipients?: number;\n error?: string;\n}\n\n/**\n * Get icon for recipient type\n */\nfunction getRecipientIcon(type: Recipient['type']) {\n switch (type) {\n case 'email':\n return <Mail size={14} className=\"text-status-info-text\" />;\n case 'phone':\n return <Phone size={14} className=\"text-status-success-text\" />;\n case 'user':\n return <User size={14} className=\"text-accent-purple\" />;\n default:\n return <User size={14} className=\"text-text-secondary\" />;\n }\n}\n\n/**\n * Validate email format\n */\nfunction isValidEmail(email: string): boolean {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n}\n\n/**\n * Validate phone format (basic validation)\n */\nfunction isValidPhone(phone: string): boolean {\n const phoneRegex = /^\\+?[1-9]\\d{6,14}$/;\n return phoneRegex.test(phone.replace(/[\\s\\-\\(\\)]/g, ''));\n}\n\n/**\n * Generate unique ID\n */\nfunction generateId(): string {\n return `recipient-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;\n}\n\n/**\n * RecipientSelector component\n *\n * Allows selecting multiple recipients for notifications.\n * Supports email, phone, and manual input based on channel type.\n */\nexport function RecipientSelector({\n recipients,\n onChange,\n channel,\n placeholder,\n disabled = false,\n maxRecipients = 100,\n error,\n}: RecipientSelectorProps) {\n const tr = useTr();\n const [inputValue, setInputValue] = useState('');\n const [inputError, setInputError] = useState<string | null>(null);\n const [isFocused, setIsFocused] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n\n // Determine input type based on channel\n const inputType =\n channel === 'EMAIL' ? 'email' : channel === 'SMS' || channel === 'WHATSAPP' ? 'phone' : 'text';\n const inputPlaceholder =\n placeholder ||\n (channel === 'EMAIL'\n ? tr('notifCommon.enterEmailPlaceholder', 'Enter email address...')\n : channel === 'SMS' || channel === 'WHATSAPP'\n ? tr('notifCommon.enterPhonePlaceholder', 'Enter phone number (e.g., +1234567890)...')\n : channel === 'PUSH'\n ? tr('notifCommon.enterDeviceTokenPlaceholder', 'Enter device token...')\n : channel === 'SLACK'\n ? tr('notifCommon.enterSlackIdPlaceholder', 'Enter Slack user ID...')\n : channel === 'TEAMS'\n ? tr('notifCommon.enterTeamsIdPlaceholder', 'Enter Teams user ID...')\n : tr('notifCommon.enterRecipientPlaceholder', 'Enter recipient...'));\n\n // Clear input error when input changes\n useEffect(() => {\n if (inputValue) {\n setInputError(null);\n }\n }, [inputValue]);\n\n /**\n * Add a recipient\n */\n const addRecipient = useCallback(\n (value: string) => {\n const trimmedValue = value.trim();\n if (!trimmedValue) return;\n\n // Check max recipients\n if (recipients.length >= maxRecipients) {\n setInputError(\n tr('notifCommon.maxRecipientsAllowed', `Maximum ${maxRecipients} recipients allowed`)\n );\n return;\n }\n\n // Check for duplicates\n const isDuplicate = recipients.some((r) => {\n if (channel === 'EMAIL') return r.email === trimmedValue;\n if (channel === 'SMS' || channel === 'WHATSAPP')\n return r.phoneNumber === trimmedValue || r.whatsappNumber === trimmedValue;\n return false;\n });\n\n if (isDuplicate) {\n setInputError(\n tr('notifCommon.duplicateRecipient', 'This recipient has already been added')\n );\n return;\n }\n\n // Validate based on channel\n let recipient: Recipient | null = null;\n\n if (channel === 'EMAIL') {\n if (!isValidEmail(trimmedValue)) {\n setInputError(tr('notifCommon.invalidEmail', 'Please enter a valid email address'));\n return;\n }\n recipient = {\n id: generateId(),\n email: trimmedValue,\n displayName: trimmedValue,\n type: 'email',\n };\n } else if (channel === 'SMS') {\n if (!isValidPhone(trimmedValue)) {\n setInputError(\n tr('notifCommon.invalidPhone', 'Please enter a valid phone number (e.g., +1234567890)')\n );\n return;\n }\n recipient = {\n id: generateId(),\n phoneNumber: trimmedValue,\n displayName: trimmedValue,\n type: 'phone',\n };\n } else if (channel === 'WHATSAPP') {\n if (!isValidPhone(trimmedValue)) {\n setInputError(\n tr(\n 'notifCommon.invalidWhatsApp',\n 'Please enter a valid WhatsApp number (e.g., +1234567890)'\n )\n );\n return;\n }\n recipient = {\n id: generateId(),\n whatsappNumber: trimmedValue,\n displayName: trimmedValue,\n type: 'phone',\n };\n } else if (channel === 'PUSH') {\n recipient = {\n id: generateId(),\n pushToken: trimmedValue,\n displayName: trimmedValue.substring(0, 20) + '...',\n type: 'manual',\n };\n } else if (channel === 'SLACK') {\n recipient = {\n id: generateId(),\n slackUserId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n } else if (channel === 'TEAMS') {\n recipient = {\n id: generateId(),\n teamsUserId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n } else if (channel === 'WEBHOOK') {\n recipient = {\n id: generateId(),\n webhookUrl: trimmedValue,\n displayName: trimmedValue,\n type: 'manual',\n };\n } else {\n // Other channels - use userId\n recipient = {\n id: generateId(),\n userId: trimmedValue,\n displayName: trimmedValue,\n type: 'user',\n };\n }\n\n if (recipient) {\n onChange([...recipients, recipient]);\n setInputValue('');\n setInputError(null);\n }\n },\n [recipients, onChange, channel, maxRecipients, tr]\n );\n\n /**\n * Remove a recipient\n */\n const removeRecipient = useCallback(\n (id: string) => {\n onChange(recipients.filter((r) => r.id !== id));\n },\n [recipients, onChange]\n );\n\n /**\n * Handle key down\n */\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (e.key === 'Enter' || e.key === ',') {\n e.preventDefault();\n addRecipient(inputValue);\n } else if (e.key === 'Backspace' && !inputValue && recipients.length > 0) {\n // Remove last recipient on backspace when input is empty\n removeRecipient(recipients[recipients.length - 1].id);\n }\n };\n\n /**\n * Handle paste (for bulk adding)\n */\n const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {\n const pastedText = e.clipboardData.getData('text');\n\n // Check if pasted text contains multiple values (comma or newline separated)\n if (pastedText.includes(',') || pastedText.includes('\\n')) {\n e.preventDefault();\n const values = pastedText\n .split(/[,\\n]/)\n .map((v) => v.trim())\n .filter(Boolean);\n\n values.forEach((value) => {\n addRecipient(value);\n });\n }\n };\n\n return (\n <div className=\"space-y-2\">\n {/* Input container */}\n <div\n className={`\n relative flex flex-wrap items-center gap-2 p-2 min-h-[42px]\n bg-surface border rounded-lg transition-colors\n ${isFocused ? 'border-primary-500 ring-1 ring-primary-500' : 'border-border-subtle'}\n ${disabled ? 'opacity-50 cursor-not-allowed bg-bg-sunken' : ''}\n ${error || inputError ? 'border-error-500' : ''}\n `}\n onClick={() => inputRef.current?.focus()}\n >\n {/* Selected recipients */}\n {recipients.map((recipient) => (\n <div\n key={recipient.id}\n className=\"flex items-center gap-1.5 px-2 py-1 bg-surface-elevated border border-border-subtle rounded-full text-sm\"\n >\n {getRecipientIcon(recipient.type)}\n <span className=\"text-text-primary max-w-[200px] truncate\">\n {recipient.displayName}\n </span>\n {!disabled && (\n <button\n type=\"button\"\n onClick={(e) => {\n e.stopPropagation();\n removeRecipient(recipient.id);\n }}\n className=\"p-0.5 hover:bg-surface-hover rounded-full transition-colors\"\n aria-label={tr('notifCommon.removeRecipient', 'Remove {{name}}').replace(\n '{{name}}',\n recipient.displayName\n )}\n >\n <X size={12} className=\"text-text-secondary\" />\n </button>\n )}\n </div>\n ))}\n\n {/* Input */}\n {!disabled && recipients.length < maxRecipients && (\n <input\n ref={inputRef}\n type={inputType}\n value={inputValue}\n onChange={(e) => setInputValue(e.target.value)}\n onKeyDown={handleKeyDown}\n onPaste={handlePaste}\n onFocus={() => setIsFocused(true)}\n onBlur={() => {\n setIsFocused(false);\n if (inputValue.trim()) {\n addRecipient(inputValue);\n }\n }}\n placeholder={\n recipients.length === 0 ? inputPlaceholder : tr('notifCommon.addMore', 'Add more...')\n }\n className=\"flex-1 min-w-[150px] bg-transparent border-none outline-none text-sm text-text-primary placeholder:text-text-secondary\"\n disabled={disabled}\n />\n )}\n\n {/* Add button for clarity */}\n {!disabled && inputValue.trim() && (\n <button\n type=\"button\"\n onClick={() => addRecipient(inputValue)}\n className=\"p-1 text-primary-500 hover:bg-primary-100 rounded transition-colors\"\n aria-label={tr('notifCommon.addRecipient', 'Add recipient')}\n >\n <Plus size={16} />\n </button>\n )}\n </div>\n\n {/* Error message */}\n {(error || inputError) && (\n <div className=\"flex items-center gap-1.5 text-error-500 text-sm\">\n <AlertCircle size={14} />\n <span>{error || inputError}</span>\n </div>\n )}\n\n {/* Helper text */}\n <div className=\"flex items-center justify-between text-xs text-text-secondary\">\n <span>\n {channel === 'EMAIL' &&\n tr(\n 'notifCommon.emailHelperText',\n 'Enter email addresses. Press Enter or comma to add multiple.'\n )}\n {(channel === 'SMS' || channel === 'WHATSAPP') &&\n tr(\n 'notifCommon.phoneHelperText',\n 'Enter phone numbers with country code (e.g., +1234567890).'\n )}\n\n {channel === 'PUSH' &&\n tr('notifCommon.pushHelperText', 'Enter device tokens for push notifications.')}\n {channel === 'SLACK' && tr('notifCommon.slackHelperText', 'Enter Slack user IDs.')}\n {channel === 'TEAMS' &&\n tr('notifCommon.teamsHelperText', 'Enter Microsoft Teams user IDs.')}\n {channel === 'WEBHOOK' && tr('notifCommon.webhookHelperText', 'Enter webhook URLs.')}\n </span>\n <span>\n {recipients.length} / {maxRecipients}\n </span>\n </div>\n </div>\n );\n}\n\n/**\n * Compact recipient display for read-only views\n */\nexport function RecipientList({ recipients }: { recipients: Recipient[] }) {\n const tr = useTr();\n\n if (recipients.length === 0) {\n return (\n <span className=\"text-text-secondary text-sm\">\n {tr('notifCommon.noRecipients', 'No recipients')}\n </span>\n );\n }\n\n return (\n <div className=\"flex flex-wrap items-center gap-1.5\">\n {recipients.slice(0, 5).map((recipient) => (\n <div\n key={recipient.id}\n className=\"flex items-center gap-1 px-2 py-0.5 bg-surface-elevated border border-border-subtle rounded-full text-xs\"\n >\n {getRecipientIcon(recipient.type)}\n <span className=\"text-text-primary max-w-[150px] truncate\">{recipient.displayName}</span>\n </div>\n ))}\n {recipients.length > 5 && (\n <span className=\"flex items-center gap-1 px-2 py-0.5 bg-bg-sunken text-text-secondary rounded-full text-xs\">\n <Users size={12} />+{recipients.length - 5} {tr('notifCommon.more', 'more')}\n </span>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;AA2BA,SAAS,EAAiB,GAAyB;AACjD,SAAQ,GAAR;EACE,KAAK,QACH,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAA0B,CAAA;EAC7D,KAAK,QACH,QAAO,kBAAC,GAAD;GAAO,MAAM;GAAI,WAAU;GAA6B,CAAA;EACjE,KAAK,OACH,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAAuB,CAAA;EAC1D,QACE,QAAO,kBAAC,GAAD;GAAM,MAAM;GAAI,WAAU;GAAwB,CAAA;;;AAO/D,SAAS,EAAa,GAAwB;AAE5C,QADmB,6BACD,KAAK,EAAM;;AAM/B,SAAS,EAAa,GAAwB;AAE5C,QADmB,qBACD,KAAK,EAAM,QAAQ,eAAe,GAAG,CAAC;;AAM1D,SAAS,IAAqB;AAC5B,QAAO,aAAa,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,GAAG,EAAE;;AAS3E,SAAgB,EAAkB,EAChC,eACA,aACA,YACA,gBACA,cAAW,IACX,mBAAgB,KAChB,YACyB;CACzB,IAAM,IAAK,GAAO,EACZ,CAAC,GAAY,KAAiB,EAAS,GAAG,EAC1C,CAAC,G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C,QAAD,EAAA,UAAO,KAAS,GAAkB,CAAA,CAC9B;;GAIR,kBAAC,OAAD;IAAK,WAAU;cAAf,CACE,kBAAC,QAAD,EAAA,UAAA;KACG,MAAY,WACX,EACE,+BACA,+DACD;MACD,MAAY,SAAS,MAAY,eACjC,EACE,+BACA,6DACD;KAEF,MAAY,UACX,EAAG,8BAA8B,8CAA8C;KAChF,MAAY,WAAW,EAAG,+BAA+B,wBAAwB;KACjF,MAAY,WACX,EAAG,+BAA+B,kCAAkC;KACrE,MAAY,aAAa,EAAG,iCAAiC,sBAAsB;KAC/E,EAAA,CAAA,EACP,kBAAC,QAAD,EAAA,UAAA;KACG,EAAW;KAAO;KAAI;KAClB,EAAA,CAAA,CACH;;GACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSendNotification.js","names":[],"sources":["../../src/hooks/useSendNotification.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n TriggerNotificationMutation,\n TriggerNotificationWithTemplateMutation,\n TriggerBatchNotificationsMutation,\n} from '../generated/global-operations';\n\n// =============================================================================\n// Type Definitions (aligned with backend GraphQL schema)\n// =============================================================================\n\nexport type NotificationChannelType =\n | 'DISCORD'\n | 'EMAIL'\n | 'PUSH'\n | 'SLACK'\n | 'SMS'\n | 'TEAMS'\n | 'TELEGRAM'\n | 'WEBHOOK'\n | 'WHATSAPP';\n\nexport type NotificationTypeEnum = 'ALERT' | 'MARKETING' | 'SYSTEM' | 'TRANSACTIONAL';\n\nexport type NotificationPriorityEnum = 'HIGH' | 'LOW' | 'MEDIUM' | 'URGENT';\n\nexport type NotificationStatusEnum =\n | 'CANCELLED'\n | 'DELIVERED'\n | 'DRAFT'\n | 'EXPIRED'\n | 'FAILED'\n | 'PENDING'\n | 'READ'\n | 'SCHEDULED'\n | 'SENT'\n | 'TRIGGERED';\n\nexport type NotificationDeliveryStatusEnum =\n | 'BOUNCED'\n | 'CLICKED'\n | 'COMPLAINED'\n | 'DELIVERED'\n | 'DELIVERING'\n | 'FAILED'\n | 'OPENED'\n | 'PENDING'\n | 'PROCESSING'\n | 'QUEUED'\n | 'RETRYING'\n | 'SENT'\n | 'UNSUBSCRIBED';\n\nexport type TriggerStatusEnum = 'CANCELLED' | 'FAILED' | 'PENDING' | 'TRIGGERED';\n\nexport interface RecipientInput {\n email?: string;\n locale?: string;\n name?: string;\n phoneNumber?: string;\n pushToken?: string;\n slackUserId?: string;\n teamsUserId?: string;\n timezone?: string;\n userId?: string;\n webhookUrl?: string;\n whatsappNumber?: string;\n}\n\nexport interface CreateNotificationInput {\n actions?: Array<{\n id?: string;\n label: string;\n url: string;\n style?: string;\n actionType?: string;\n metadata?: Record<string, unknown>;\n }>;\n appName?: string;\n body: string;\n channel: NotificationChannelType;\n data?: Record<string, unknown>;\n expiresAt?: string;\n htmlBody?: string;\n media?: Array<{\n url: string;\n label?: string;\n kind?: string;\n contentType?: string;\n thumbnailUrl?: string;\n }>;\n metadata?: Record<string, unknown>;\n priority?: NotificationPriorityEnum;\n recipient: RecipientInput;\n redirectUrl?: string;\n subject?: string;\n trackClicks?: boolean;\n trackOpens?: boolean;\n topicId?: string;\n type?: NotificationTypeEnum;\n}\n\nexport interface TriggerNotificationInput {\n notificationId?: string;\n notification?: CreateNotificationInput;\n channelId?: string;\n platform?: NotificationChannelType;\n includeInApp?: boolean;\n userIds?: string[];\n}\n\nexport interface TemplateNotificationResult {\n totalRequested: number;\n totalTriggered: number;\n totalFailed: number;\n notifications: TriggerNotificationResult[];\n}\n\nexport interface TriggerWithTemplateInput {\n actions?: Array<{\n id?: string;\n label: string;\n url: string;\n style?: string;\n actionType?: string;\n metadata?: Record<string, unknown>;\n }>;\n channelId?: string;\n platform?: NotificationChannelType;\n includeInApp?: boolean;\n userIds?: string[];\n expiresAt?: string;\n redirectUrl?: string;\n priority?: NotificationPriorityEnum;\n /** Single recipient (use this OR recipients, not both) */\n recipient?: RecipientInput;\n /** Multiple recipients for bulk delivery (use this OR recipient, not both) */\n recipients?: RecipientInput[];\n templateSlug: string;\n trackClicks?: boolean;\n trackOpens?: boolean;\n media?: Array<{\n url: string;\n label?: string;\n kind?: string;\n contentType?: string;\n thumbnailUrl?: string;\n }>;\n topicId?: string;\n variables: Record<string, unknown>;\n scheduledFor?: string;\n timezone?: string;\n}\n\nexport interface TriggerBatchInput {\n notificationIds?: string[];\n notifications?: CreateNotificationInput[];\n priority?: NotificationPriorityEnum;\n delayBetweenBatches?: number;\n batchSize?: number;\n scheduledFor?: string;\n timezone?: string;\n}\n\nexport interface TriggerNotificationResult {\n id: string;\n status: NotificationStatusEnum;\n deliveryStatus?: NotificationDeliveryStatusEnum;\n triggerStatus: TriggerStatusEnum;\n sentAt?: string;\n title: string;\n message: string;\n}\n\nexport interface BatchNotificationResult {\n batchId: string;\n totalRequested: number;\n totalTriggered: number;\n totalFailed: number;\n successCount: number;\n failureCount: number;\n results: Record<string, unknown>;\n}\n\n// =============================================================================\n\n/**\n * Hook to send notifications\n * Provides methods for triggering single, batch, and template-based notifications\n */\nexport function useSendNotification() {\n const { authToken, apiGatewayUrl } = useNotification();\n const [isLoading, _setIsLoading] = useState(false);\n const [isSending, setIsSending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [lastResult, setLastResult] = useState<\n TriggerNotificationResult | BatchNotificationResult | TemplateNotificationResult | null\n >(null);\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n /**\n * Send a single notification.\n * @throws the underlying GraphQL/network error after setting the hook's `error` state, so callers can inspect it (e.g. detect gateway FORBIDDEN via `isPermissionError`).\n */\n const sendNotification = useCallback(\n async (input: TriggerNotificationInput): Promise<TriggerNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerNotificationMutation>({\n mutation: NotificationOps.TriggerNotificationDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerNotification ?? null;\n if (!raw) return null;\n const notification: TriggerNotificationResult = {\n id: raw.id,\n status: raw.status as unknown as NotificationStatusEnum,\n deliveryStatus: (raw.deliveryStatus ?? undefined) as\n | NotificationDeliveryStatusEnum\n | undefined,\n triggerStatus: raw.triggerStatus as unknown as TriggerStatusEnum,\n sentAt: raw.sentAt ?? undefined,\n title: raw.title,\n message: raw.message,\n };\n setLastResult(notification);\n return notification;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to send notification';\n console.error('[useSendNotification] Failed to send notification:', err);\n setError(message);\n // Re-throw so the caller's catch block can inspect the raw error (e.g.,\n // detect gateway FORBIDDEN via isPermissionError) — matches the\n // useNotificationTemplates pattern.\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Send notification using a template. Supports single recipient (recipient) or bulk delivery (recipients).\n * @throws the underlying error after setting `error` state — same contract as `sendNotification`.\n */\n const sendWithTemplate = useCallback(\n async (input: TriggerWithTemplateInput): Promise<TemplateNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerNotificationWithTemplateMutation>({\n mutation: NotificationOps.TriggerNotificationWithTemplateDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerNotificationWithTemplate ?? null;\n if (!raw) return null;\n const templateResult: TemplateNotificationResult = {\n totalRequested: raw.totalRequested,\n totalTriggered: raw.totalTriggered,\n totalFailed: raw.totalFailed,\n notifications: raw.notifications.map((n) => ({\n id: n.id,\n status: n.status as unknown as NotificationStatusEnum,\n deliveryStatus: undefined,\n triggerStatus: 'TRIGGERED' as TriggerStatusEnum,\n sentAt: n.sentAt ?? undefined,\n title: n.title,\n message: n.message,\n })),\n };\n setLastResult(templateResult);\n return templateResult;\n } catch (err: unknown) {\n const message =\n err instanceof Error ? err.message : 'Failed to send notification with template';\n console.error('[useSendNotification] Failed to send notification with template:', err);\n setError(message);\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Send notifications to multiple recipients.\n * @throws the underlying error after setting `error` state — same contract as `sendNotification`.\n */\n const sendBatch = useCallback(\n async (input: TriggerBatchInput): Promise<BatchNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerBatchNotificationsMutation>({\n mutation: NotificationOps.TriggerBatchNotificationsDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerBatchNotifications ?? null;\n if (!raw) return null;\n const batchResult: BatchNotificationResult = {\n batchId: raw.batchId,\n totalRequested: raw.totalRequested,\n totalTriggered: raw.totalTriggered,\n totalFailed: raw.totalFailed,\n successCount: raw.totalTriggered,\n failureCount: raw.totalFailed,\n results: raw.results,\n };\n setLastResult(batchResult);\n return batchResult;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to send batch notifications';\n console.error('[useSendNotification] Failed to send batch notifications:', err);\n setError(message);\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Helper: Send a simple notification to one recipient\n * Simplified interface for common use case\n */\n const sendSimple = useCallback(\n async (params: {\n recipient: RecipientInput;\n channel: NotificationChannelType;\n body: string;\n subject?: string;\n type?: NotificationTypeEnum;\n priority?: NotificationPriorityEnum;\n }): Promise<TriggerNotificationResult | null> => {\n return sendNotification({\n notification: {\n body: params.body,\n channel: params.channel,\n recipient: params.recipient,\n subject: params.subject,\n type: params.type || 'TRANSACTIONAL',\n priority: params.priority || 'MEDIUM',\n },\n platform: params.channel,\n });\n },\n [sendNotification]\n );\n\n /**\n * Helper: Send to multiple recipients with same message\n */\n const sendToMultiple = useCallback(\n async (params: {\n recipients: RecipientInput[];\n channel: NotificationChannelType;\n body: string;\n subject?: string;\n type?: NotificationTypeEnum;\n priority?: NotificationPriorityEnum;\n }): Promise<BatchNotificationResult | null> => {\n const notifications: CreateNotificationInput[] = params.recipients.map((recipient) => ({\n body: params.body,\n channel: params.channel,\n recipient,\n subject: params.subject,\n type: params.type || 'MARKETING',\n priority: params.priority || 'MEDIUM',\n }));\n\n return sendBatch({ notifications });\n },\n [sendBatch]\n );\n\n /**\n * Clear error state\n */\n const clearError = useCallback(() => {\n setError(null);\n }, []);\n\n /**\n * Clear last result\n */\n const clearResult = useCallback(() => {\n setLastResult(null);\n }, []);\n\n return {\n // State\n isLoading,\n isSending,\n error,\n lastResult,\n\n // Core methods\n sendNotification,\n sendWithTemplate,\n sendBatch,\n\n // Helper methods\n sendSimple,\n sendToMultiple,\n\n // Utilities\n clearError,\n clearResult,\n };\n}\n"],"mappings":";;;;;AAiMA,SAAgB,IAAsB;CACpC,IAAM,EAAE,cAAW,qBAAkB,GAAiB,EAChD,CAAC,GAAW,KAAiB,EAAS,GAAM,EAC5C,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAO,KAAY,EAAwB,KAAK,EACjD,CAAC,GAAY,KAAiB,EAElC,KAAK,EAGD,IAAY,QACT,EAA4B,KAAiB,KAAA,GAAW,KAAa,KAAA,EAAU,EACrF,CAAC,GAAe,EAAU,CAAC,EAMxB,IAAmB,EACvB,OAAO,MAA+E;AAEpF,EADA,EAAa,GAAK,EAClB,EAAS,KAAK;AAEd,MAAI;GAOF,IAAM,KALS,MADA,GAAW,CACE,OAAoC;IAC9D,UAAU;IACV,WAAW,EAAE,UAAO;IACrB,CAAC,EAEiB,MAAM,uBAAuB;AAChD,OAAI,CAAC,EAAK,QAAO;GACjB,IAAM,IAA0C;IAC9C,IAAI,EAAI;IACR,QAAQ,EAAI;IACZ,gBAAiB,EAAI,kBAAkB,KAAA;IAGvC,eAAe,EAAI;IACnB,QAAQ,EAAI,UAAU,KAAA;IACtB,OAAO,EAAI;IACX,SAAS,EAAI;IACd;AAED,UADA,EAAc,EAAa,EACpB;WACA,GAAc;GACrB,IAAM,IAAU,aAAe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GAAc;GACrB,IAAM,IAAU,aAAe,QAAQ,EAAI,UAAU;AAGrD,SAFA,QAAQ,MAAM,6DAA6D,EAAI,EAC/E,EAAS,EAAQ,EACX;YACE;AACR,KAAa,GAAM;;IAGvB,CAAC,EAAU,CACZ;AAsED,QAAO;EAEL;EACA;EACA;EACA;EAGA;EACA;EACA;EAGA,YA7EiB,EACjB,OAAO,MAQE,EAAiB;GACtB,cAAc;IACZ,MAAM,EAAO;IACb,SAAS,EAAO;IAChB,WAAW,EAAO;IAClB,SAAS,EAAO;IAChB,MAAM,EAAO,QAAQ;IACrB,UAAU,EAAO,YAAY;IAC9B;GACD,UAAU,EAAO;GAClB,CAAC,EAEJ,CAAC,EAAiB,CACnB;EAwDC,gBAnDqB,EACrB,OAAO,MAiBE,EAAU,EAAE,eAT8B,EAAO,WAAW,KAAK,OAAe;GACrF,MAAM,EAAO;GACb,SAAS,EAAO;GAChB;GACA,SAAS,EAAO;GAChB,MAAM,EAAO,QAAQ;GACrB,UAAU,EAAO,YAAY;GAC9B,EAAE,EAE+B,CAAC,EAErC,CAAC,EAAU,CACZ;EAiCC,YA5BiB,QAAkB;AACnC,KAAS,KAAK;KACb,EAAE,CAAC;EA2BJ,aAtBkB,QAAkB;AACpC,KAAc,KAAK;KAClB,EAAE,CAAC;EAqBL"}
|
|
1
|
+
{"version":3,"file":"useSendNotification.js","names":[],"sources":["../../src/hooks/useSendNotification.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport { useNotification } from '../providers/NotificationProvider';\nimport { getGlobalNotificationClient } from '../graphql/global-client';\nimport * as NotificationOps from '../generated/global-operations';\nimport type {\n TriggerNotificationMutation,\n TriggerNotificationWithTemplateMutation,\n TriggerBatchNotificationsMutation,\n} from '../generated/global-operations';\n\n// =============================================================================\n// Type Definitions (aligned with backend GraphQL schema)\n// =============================================================================\n\nexport type NotificationChannelType =\n 'DISCORD' | 'EMAIL' | 'PUSH' | 'SLACK' | 'SMS' | 'TEAMS' | 'TELEGRAM' | 'WEBHOOK' | 'WHATSAPP';\n\nexport type NotificationTypeEnum = 'ALERT' | 'MARKETING' | 'SYSTEM' | 'TRANSACTIONAL';\n\nexport type NotificationPriorityEnum = 'HIGH' | 'LOW' | 'MEDIUM' | 'URGENT';\n\nexport type NotificationStatusEnum =\n | 'CANCELLED'\n | 'DELIVERED'\n | 'DRAFT'\n | 'EXPIRED'\n | 'FAILED'\n | 'PENDING'\n | 'READ'\n | 'SCHEDULED'\n | 'SENT'\n | 'TRIGGERED';\n\nexport type NotificationDeliveryStatusEnum =\n | 'BOUNCED'\n | 'CLICKED'\n | 'COMPLAINED'\n | 'DELIVERED'\n | 'DELIVERING'\n | 'FAILED'\n | 'OPENED'\n | 'PENDING'\n | 'PROCESSING'\n | 'QUEUED'\n | 'RETRYING'\n | 'SENT'\n | 'UNSUBSCRIBED';\n\nexport type TriggerStatusEnum = 'CANCELLED' | 'FAILED' | 'PENDING' | 'TRIGGERED';\n\nexport interface RecipientInput {\n email?: string;\n locale?: string;\n name?: string;\n phoneNumber?: string;\n pushToken?: string;\n slackUserId?: string;\n teamsUserId?: string;\n timezone?: string;\n userId?: string;\n webhookUrl?: string;\n whatsappNumber?: string;\n}\n\nexport interface CreateNotificationInput {\n actions?: Array<{\n id?: string;\n label: string;\n url: string;\n style?: string;\n actionType?: string;\n metadata?: Record<string, unknown>;\n }>;\n appName?: string;\n body: string;\n channel: NotificationChannelType;\n data?: Record<string, unknown>;\n expiresAt?: string;\n htmlBody?: string;\n media?: Array<{\n url: string;\n label?: string;\n kind?: string;\n contentType?: string;\n thumbnailUrl?: string;\n }>;\n metadata?: Record<string, unknown>;\n priority?: NotificationPriorityEnum;\n recipient: RecipientInput;\n redirectUrl?: string;\n subject?: string;\n trackClicks?: boolean;\n trackOpens?: boolean;\n topicId?: string;\n type?: NotificationTypeEnum;\n}\n\nexport interface TriggerNotificationInput {\n notificationId?: string;\n notification?: CreateNotificationInput;\n channelId?: string;\n platform?: NotificationChannelType;\n includeInApp?: boolean;\n userIds?: string[];\n}\n\nexport interface TemplateNotificationResult {\n totalRequested: number;\n totalTriggered: number;\n totalFailed: number;\n notifications: TriggerNotificationResult[];\n}\n\nexport interface TriggerWithTemplateInput {\n actions?: Array<{\n id?: string;\n label: string;\n url: string;\n style?: string;\n actionType?: string;\n metadata?: Record<string, unknown>;\n }>;\n channelId?: string;\n platform?: NotificationChannelType;\n includeInApp?: boolean;\n userIds?: string[];\n expiresAt?: string;\n redirectUrl?: string;\n priority?: NotificationPriorityEnum;\n /** Single recipient (use this OR recipients, not both) */\n recipient?: RecipientInput;\n /** Multiple recipients for bulk delivery (use this OR recipient, not both) */\n recipients?: RecipientInput[];\n templateSlug: string;\n trackClicks?: boolean;\n trackOpens?: boolean;\n media?: Array<{\n url: string;\n label?: string;\n kind?: string;\n contentType?: string;\n thumbnailUrl?: string;\n }>;\n topicId?: string;\n variables: Record<string, unknown>;\n scheduledFor?: string;\n timezone?: string;\n}\n\nexport interface TriggerBatchInput {\n notificationIds?: string[];\n notifications?: CreateNotificationInput[];\n priority?: NotificationPriorityEnum;\n delayBetweenBatches?: number;\n batchSize?: number;\n scheduledFor?: string;\n timezone?: string;\n}\n\nexport interface TriggerNotificationResult {\n id: string;\n status: NotificationStatusEnum;\n deliveryStatus?: NotificationDeliveryStatusEnum;\n triggerStatus: TriggerStatusEnum;\n sentAt?: string;\n title: string;\n message: string;\n}\n\nexport interface BatchNotificationResult {\n batchId: string;\n totalRequested: number;\n totalTriggered: number;\n totalFailed: number;\n successCount: number;\n failureCount: number;\n results: Record<string, unknown>;\n}\n\n// =============================================================================\n\n/**\n * Hook to send notifications\n * Provides methods for triggering single, batch, and template-based notifications\n */\nexport function useSendNotification() {\n const { authToken, apiGatewayUrl } = useNotification();\n const [isLoading, _setIsLoading] = useState(false);\n const [isSending, setIsSending] = useState(false);\n const [error, setError] = useState<string | null>(null);\n const [lastResult, setLastResult] = useState<\n TriggerNotificationResult | BatchNotificationResult | TemplateNotificationResult | null\n >(null);\n\n // Get global client — coerce null/undefined authToken to undefined\n const getClient = useCallback(() => {\n return getGlobalNotificationClient(apiGatewayUrl ?? undefined, authToken ?? undefined);\n }, [apiGatewayUrl, authToken]);\n\n /**\n * Send a single notification.\n * @throws the underlying GraphQL/network error after setting the hook's `error` state, so callers can inspect it (e.g. detect gateway FORBIDDEN via `isPermissionError`).\n */\n const sendNotification = useCallback(\n async (input: TriggerNotificationInput): Promise<TriggerNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerNotificationMutation>({\n mutation: NotificationOps.TriggerNotificationDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerNotification ?? null;\n if (!raw) return null;\n const notification: TriggerNotificationResult = {\n id: raw.id,\n status: raw.status as unknown as NotificationStatusEnum,\n deliveryStatus: (raw.deliveryStatus ?? undefined) as\n NotificationDeliveryStatusEnum | undefined,\n triggerStatus: raw.triggerStatus as unknown as TriggerStatusEnum,\n sentAt: raw.sentAt ?? undefined,\n title: raw.title,\n message: raw.message,\n };\n setLastResult(notification);\n return notification;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to send notification';\n console.error('[useSendNotification] Failed to send notification:', err);\n setError(message);\n // Re-throw so the caller's catch block can inspect the raw error (e.g.,\n // detect gateway FORBIDDEN via isPermissionError) — matches the\n // useNotificationTemplates pattern.\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Send notification using a template. Supports single recipient (recipient) or bulk delivery (recipients).\n * @throws the underlying error after setting `error` state — same contract as `sendNotification`.\n */\n const sendWithTemplate = useCallback(\n async (input: TriggerWithTemplateInput): Promise<TemplateNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerNotificationWithTemplateMutation>({\n mutation: NotificationOps.TriggerNotificationWithTemplateDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerNotificationWithTemplate ?? null;\n if (!raw) return null;\n const templateResult: TemplateNotificationResult = {\n totalRequested: raw.totalRequested,\n totalTriggered: raw.totalTriggered,\n totalFailed: raw.totalFailed,\n notifications: raw.notifications.map((n) => ({\n id: n.id,\n status: n.status as unknown as NotificationStatusEnum,\n deliveryStatus: undefined,\n triggerStatus: 'TRIGGERED' as TriggerStatusEnum,\n sentAt: n.sentAt ?? undefined,\n title: n.title,\n message: n.message,\n })),\n };\n setLastResult(templateResult);\n return templateResult;\n } catch (err: unknown) {\n const message =\n err instanceof Error ? err.message : 'Failed to send notification with template';\n console.error('[useSendNotification] Failed to send notification with template:', err);\n setError(message);\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Send notifications to multiple recipients.\n * @throws the underlying error after setting `error` state — same contract as `sendNotification`.\n */\n const sendBatch = useCallback(\n async (input: TriggerBatchInput): Promise<BatchNotificationResult | null> => {\n setIsSending(true);\n setError(null);\n\n try {\n const client = getClient();\n const result = await client.mutate<TriggerBatchNotificationsMutation>({\n mutation: NotificationOps.TriggerBatchNotificationsDocument,\n variables: { input },\n });\n\n const raw = result.data?.triggerBatchNotifications ?? null;\n if (!raw) return null;\n const batchResult: BatchNotificationResult = {\n batchId: raw.batchId,\n totalRequested: raw.totalRequested,\n totalTriggered: raw.totalTriggered,\n totalFailed: raw.totalFailed,\n successCount: raw.totalTriggered,\n failureCount: raw.totalFailed,\n results: raw.results,\n };\n setLastResult(batchResult);\n return batchResult;\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Failed to send batch notifications';\n console.error('[useSendNotification] Failed to send batch notifications:', err);\n setError(message);\n throw err;\n } finally {\n setIsSending(false);\n }\n },\n [getClient]\n );\n\n /**\n * Helper: Send a simple notification to one recipient\n * Simplified interface for common use case\n */\n const sendSimple = useCallback(\n async (params: {\n recipient: RecipientInput;\n channel: NotificationChannelType;\n body: string;\n subject?: string;\n type?: NotificationTypeEnum;\n priority?: NotificationPriorityEnum;\n }): Promise<TriggerNotificationResult | null> => {\n return sendNotification({\n notification: {\n body: params.body,\n channel: params.channel,\n recipient: params.recipient,\n subject: params.subject,\n type: params.type || 'TRANSACTIONAL',\n priority: params.priority || 'MEDIUM',\n },\n platform: params.channel,\n });\n },\n [sendNotification]\n );\n\n /**\n * Helper: Send to multiple recipients with same message\n */\n const sendToMultiple = useCallback(\n async (params: {\n recipients: RecipientInput[];\n channel: NotificationChannelType;\n body: string;\n subject?: string;\n type?: NotificationTypeEnum;\n priority?: NotificationPriorityEnum;\n }): Promise<BatchNotificationResult | null> => {\n const notifications: CreateNotificationInput[] = params.recipients.map((recipient) => ({\n body: params.body,\n channel: params.channel,\n recipient,\n subject: params.subject,\n type: params.type || 'MARKETING',\n priority: params.priority || 'MEDIUM',\n }));\n\n return sendBatch({ notifications });\n },\n [sendBatch]\n );\n\n /**\n * Clear error state\n */\n const clearError = useCallback(() => {\n setError(null);\n }, []);\n\n /**\n * Clear last result\n */\n const clearResult = useCallback(() => {\n setLastResult(null);\n }, []);\n\n return {\n // State\n isLoading,\n isSending,\n error,\n lastResult,\n\n // Core methods\n sendNotification,\n sendWithTemplate,\n sendBatch,\n\n // Helper methods\n sendSimple,\n sendToMultiple,\n\n // Utilities\n clearError,\n clearResult,\n };\n}\n"],"mappings":";;;;;AAyLA,SAAgB,IAAsB;CACpC,IAAM,EAAE,cAAW,qBAAkB,GAAiB,EAChD,CAAC,GAAW,KAAiB,EAAS,GAAM,EAC5C,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,CAAC,GAAO,KAAY,EAAwB,KAAK,EACjD,CAAC,GAAY,KAAiB,EAElC,KAAK,EAGD,IAAY,QACT,EAA4B,KAAiB,KAAA,GAAW,KAAa,KAAA,EAAU,EACrF,CAAC,GAAe,EAAU,CAAC,EAMxB,IAAmB,EACvB,OAAO,MAA+E;AAEpF,EADA,EAAa,GAAK,EAClB,EAAS,KAAK;AAEd,MAAI;GAOF,IAAM,KALS,MADA,GAAW,CACE,OAAoC;IAC9D,UAAU;IACV,WAAW,EAAE,UAAO;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A,GAAW,CACE,OAA0C;IACpE,UAAU;IACV,WAAW,EAAE,UAAO;IACrB,CAAC,EAEiB,MAAM,6BAA6B;AACtD,OAAI,CAAC,EAAK,QAAO;GACjB,IAAM,IAAuC;IAC3C,SAAS,EAAI;IACb,gBAAgB,EAAI;IACpB,gBAAgB,EAAI;IACpB,aAAa,EAAI;IACjB,cAAc,EAAI;IAClB,cAAc,EAAI;IAClB,SAAS,EAAI;IACd;AAED,UADA,EAAc,EAAY,EACnB;WACA,GAAc;GACrB,IAAM,IAAU,aAAe,QAAQ,EAAI,UAAU;AAGrD,SAFA,QAAQ,MAAM,6DAA6D,EAAI,EAC/E,EAAS,EAAQ,EACX;YACE;AACR,KAAa,GAAM;;IAGvB,CAAC,EAAU,CACZ;AAsED,QAAO;EAEL;EACA;EACA;EACA;EAGA;EACA;EACA;EAGA,YA7EiB,EACjB,OAAO,MAQE,EAAiB;GACtB,cAAc;IACZ,MAAM,EAAO;IACb,SAAS,EAAO;IAChB,WAAW,EAAO;IAClB,SAAS,EAAO;IAChB,MAAM,EAAO,QAAQ;IACrB,UAAU,EAAO,YAAY;IAC9B;GACD,UAAU,EAAO;GAClB,CAAC,EAEJ,CAAC,EAAiB,CACnB;EAwDC,gBAnDqB,EACrB,OAAO,MAiBE,EAAU,EAAE,eAT8B,EAAO,WAAW,KAAK,OAAe;GACrF,MAAM,EAAO;GACb,SAAS,EAAO;GAChB;GACA,SAAS,EAAO;GAChB,MAAM,EAAO,QAAQ;GACrB,UAAU,EAAO,YAAY;GAC9B,EAAE,EAE+B,CAAC,EAErC,CAAC,EAAU,CACZ;EAiCC,YA5BiB,QAAkB;AACnC,KAAS,KAAK;KACb,EAAE,CAAC;EA2BJ,aAtBkB,QAAkB;AACpC,KAAc,KAAK;KAClB,EAAE,CAAC;EAqBL"}
|
|
@@ -11,7 +11,7 @@ import { RecipientSelector as ae } from "../components/RecipientSelector.js";
|
|
|
11
11
|
import { useMemo as a, useState as o } from "react";
|
|
12
12
|
import { useGlobalUi as oe, usePermissions as se } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
13
13
|
import { AlertCircle as ce, ArrowLeft as le, Bell as ue, CheckCircle2 as s, Eye as de, EyeOff as fe, FileText as pe, ImagePlus as me, Link2 as he, Loader2 as c, Mail as ge, MessageSquare as l, Send as _e, Smartphone as ve, User as u, Users as ye, X as be } from "lucide-react";
|
|
14
|
-
import { useNavigate as xe } from "react-router
|
|
14
|
+
import { useNavigate as xe } from "react-router";
|
|
15
15
|
import { Fragment as Se, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
16
16
|
import { CTAOverflowMenu as Ce, GlassCard as we, IllustratedEmptyState as Te, NextSteps as Ee, PagePurpose as De } from "@burdenoff/fe-libs/ui";
|
|
17
17
|
//#region src/pages/CreateNotificationPage.tsx
|