@burdenoff/microfe-notification 2026.1129.1 → 2026.1129.3
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/NotificationRoutes.js +73 -72
- package/dist/NotificationRoutes.js.map +1 -1
- package/dist/generated/global-operations.d.ts +4 -0
- package/dist/generated/global-operations.js +4 -0
- package/dist/generated/global-operations.js.map +1 -1
- package/dist/hooks/useNotificationTemplates.d.ts +3 -0
- package/dist/hooks/useSendNotification.d.ts +1 -1
- package/dist/hooks/useSendNotification.js.map +1 -1
- package/dist/translations/en.d.ts +179 -0
- package/dist/v2/InboxPage.js +113 -97
- package/dist/v2/InboxPage.js.map +1 -1
- package/dist/v2/NotificationDetailPanel.d.ts +9 -4
- package/dist/v2/NotificationDetailPanel.js +66 -51
- package/dist/v2/NotificationDetailPanel.js.map +1 -1
- package/dist/v2/admin/ChoiceSelect.d.ts +9 -0
- package/dist/v2/admin/ChoiceSelect.js +24 -0
- package/dist/v2/admin/ChoiceSelect.js.map +1 -0
- package/dist/v2/admin/DeliveryLogPage.d.ts +1 -0
- package/dist/v2/admin/DeliveryLogPage.js +207 -0
- package/dist/v2/admin/DeliveryLogPage.js.map +1 -0
- package/dist/v2/admin/InsertDetail.d.ts +6 -0
- package/dist/v2/admin/InsertDetail.js +77 -0
- package/dist/v2/admin/InsertDetail.js.map +1 -0
- package/dist/v2/admin/TemplateEditor.d.ts +6 -0
- package/dist/v2/admin/TemplateEditor.js +92 -0
- package/dist/v2/admin/TemplateEditor.js.map +1 -0
- package/dist/v2/admin/TemplateFields.d.ts +9 -0
- package/dist/v2/admin/TemplateFields.js +130 -0
- package/dist/v2/admin/TemplateFields.js.map +1 -0
- package/dist/v2/admin/TemplatePage.d.ts +1 -0
- package/dist/v2/admin/TemplatePage.js +62 -0
- package/dist/v2/admin/TemplatePage.js.map +1 -0
- package/dist/v2/admin/TemplatePreview.d.ts +8 -0
- package/dist/v2/admin/TemplatePreview.js +112 -0
- package/dist/v2/admin/TemplatePreview.js.map +1 -0
- package/dist/v2/admin/TemplatesPage.d.ts +1 -0
- package/dist/v2/admin/TemplatesPage.js +173 -0
- package/dist/v2/admin/TemplatesPage.js.map +1 -0
- package/dist/v2/admin/TopicDialog.d.ts +11 -0
- package/dist/v2/admin/TopicDialog.js +113 -0
- package/dist/v2/admin/TopicDialog.js.map +1 -0
- package/dist/v2/admin/TopicsPage.d.ts +1 -0
- package/dist/v2/admin/TopicsPage.js +152 -0
- package/dist/v2/admin/TopicsPage.js.map +1 -0
- package/dist/v2/admin/templateText.d.ts +35 -0
- package/dist/v2/admin/templateText.js +114 -0
- package/dist/v2/admin/templateText.js.map +1 -0
- package/dist/v2/admin/useTemplateDraft.d.ts +32 -0
- package/dist/v2/admin/useTemplateDraft.js +117 -0
- package/dist/v2/admin/useTemplateDraft.js.map +1 -0
- package/dist/v2/admin/words.d.ts +15 -0
- package/dist/v2/admin/words.js +67 -0
- package/dist/v2/admin/words.js.map +1 -0
- package/dist/v2/send/MessageTab.d.ts +4 -0
- package/dist/v2/send/MessageTab.js +152 -0
- package/dist/v2/send/MessageTab.js.map +1 -0
- package/dist/v2/send/PeopleTab.d.ts +4 -0
- package/dist/v2/send/PeopleTab.js +156 -0
- package/dist/v2/send/PeopleTab.js.map +1 -0
- package/dist/v2/send/SendNotificationDialog.d.ts +4 -0
- package/dist/v2/send/SendNotificationDialog.js +98 -0
- package/dist/v2/send/SendNotificationDialog.js.map +1 -0
- package/dist/v2/send/SendRedirect.d.ts +1 -0
- package/dist/v2/send/SendRedirect.js +20 -0
- package/dist/v2/send/SendRedirect.js.map +1 -0
- package/dist/v2/send/WhenTab.d.ts +4 -0
- package/dist/v2/send/WhenTab.js +64 -0
- package/dist/v2/send/WhenTab.js.map +1 -0
- package/dist/v2/send/sendModel.d.ts +47 -0
- package/dist/v2/send/sendModel.js +90 -0
- package/dist/v2/send/sendModel.js.map +1 -0
- package/dist/v2/send/useSendDraft.d.ts +24 -0
- package/dist/v2/send/useSendDraft.js +120 -0
- package/dist/v2/send/useSendDraft.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplatePreview.js","names":["TemplatePreview","tr","useTr","view","setView","useState","filledTitle","fillSamples","title","details","filledMessage","message","Eye","Segmented","productName","IconTile","Bell"],"sources":["../../../src/v2/admin/TemplatePreview.tsx"],"sourcesContent":["/**\n * A template's live preview (BOFF-16785, C2): In app · Email · Push, with sample details filled in\n * (Maya, Lead routing, …) so the message reads as someone will see it.\n */\nimport { useState } from 'react';\nimport { Bell, Eye } from 'lucide-react';\nimport { IconTile, Segmented } from '@burdenoff/fe-libs/ui';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { fillSamples, type TemplateDetail } from './templateText';\n\ntype View = 'inApp' | 'email' | 'push';\n\nexport function TemplatePreview({\n productName,\n title,\n message,\n details,\n}: {\n productName: string;\n /** Stored text (`{{name}}`). */\n title: string;\n message: string;\n details: readonly TemplateDetail[];\n}) {\n const tr = useTr();\n const [view, setView] = useState<View>('inApp');\n const filledTitle =\n fillSamples(title, details) || tr('notifications.v3.template.previewTitle', 'Your title');\n const filledMessage =\n fillSamples(message, details) ||\n tr('notifications.v3.template.previewMessage', 'Your message shows here.');\n return (\n <section\n className=\"flex flex-col gap-3 self-start rounded-lg border border-border-subtle bg-bg-sunken p-4\"\n aria-label={tr('notifications.v3.template.preview', 'Preview')}\n data-testid=\"template-preview\"\n >\n <div className=\"flex flex-wrap items-center justify-between gap-2\">\n <span className=\"inline-flex items-center gap-1.5 text-xs font-medium text-text-secondary\">\n <Eye className=\"size-3.5\" aria-hidden=\"true\" />\n {tr('notifications.v3.template.previewWith', 'Preview, with sample details')}\n </span>\n <Segmented<View>\n aria-label={tr('notifications.v3.template.preview', 'Preview')}\n value={view}\n onValueChange={setView}\n options={[\n { value: 'inApp', label: tr('notifications.v3.channel.inApp', 'In app') },\n { value: 'email', label: tr('notifications.v3.channel.email', 'Email') },\n { value: 'push', label: tr('notifications.v3.channel.push', 'Push') },\n ]}\n />\n </div>\n {view === 'email' ? (\n <div className=\"flex flex-col gap-2 rounded-md border border-border-subtle bg-bg-surface p-4\">\n <span className=\"text-xs text-text-muted\">\n {tr(\n 'notifications.v3.template.previewFrom',\n 'From {{product}} · to maya@northwind.example',\n {\n product: productName,\n }\n )}\n </span>\n <b className=\"text-sm text-text-primary\">{filledTitle}</b>\n <p className=\"m-0 text-sm whitespace-pre-wrap text-text-primary\">{filledMessage}</p>\n </div>\n ) : view === 'push' ? (\n <div className=\"flex items-start gap-3 rounded-xl border border-border-subtle bg-bg-surface p-3\">\n <IconTile size=\"sm\">\n <Bell aria-hidden=\"true\" />\n </IconTile>\n <div className=\"min-w-0 flex-1\">\n <div className=\"flex items-center justify-between gap-2\">\n <b className=\"truncate text-sm text-text-primary\">{productName}</b>\n <span className=\"text-xs text-text-muted\">\n {tr('notifications.v3.template.now', 'now')}\n </span>\n </div>\n <p className=\"m-0 truncate text-sm text-text-primary\">{filledTitle}</p>\n <p className=\"m-0 line-clamp-2 text-xs text-text-secondary\">{filledMessage}</p>\n </div>\n </div>\n ) : (\n <div className=\"flex items-start gap-3 rounded-lg border border-border-subtle bg-bg-surface p-3\">\n <IconTile size=\"sm\">\n <Bell aria-hidden=\"true\" />\n </IconTile>\n <div className=\"min-w-0 flex-1\">\n <b className=\"block text-sm text-text-primary\">{filledTitle}</b>\n <p className=\"m-0 text-xs whitespace-pre-wrap text-text-secondary\">{filledMessage}</p>\n </div>\n <span className=\"text-xs text-text-muted\">\n {tr('notifications.v3.template.now', 'now')}\n </span>\n </div>\n )}\n </section>\n );\n}\n"],"mappings":";;;;;;;AAYA,SAAgBA,EAAgB,EAC9B,gBACA,UACA,YACA,cAOC;CACD,IAAMC,IAAKC,EAAM,GACX,CAACC,GAAMC,KAAWC,EAAe,OAAO,GACxCC,IACJC,EAAYC,GAAOC,CAAO,KAAKR,EAAG,0CAA0C,YAAY,GACpFS,IACJH,EAAYI,GAAS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AAG,iCAAiC,KAAK;MACtC,CAAA,CACH;;KACL,kBAAC,KAAD;MAAG,WAAU;MAA0C,UAAAK;KAAe,CAAA;KACtE,kBAAC,KAAD;MAAG,WAAU;MAAgD,UAAAI;KAAiB,CAAA;IAC3E;GACF,CAAA,CAAA;EAEL,CAAA,IAAA,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA;IACE,kBAACK,GAAD;KAAU,MAAK;KACb,UAAA,kBAACC,GAAD,EAAM,eAAY,OAAQ,CAAA;IAClB,CAAA;IACV,kBAAC,OAAD;KAAK,WAAU;KAAf,UAAA,CACE,kBAAC,KAAD;MAAG,WAAU;MAAmC,UAAAV;KAAe,CAAA,GAC/D,kBAAC,KAAD;MAAG,WAAU;MAAuD,UAAAI;KAAiB,CAAA,CAClF;;IACL,kBAAC,QAAD;KAAM,WAAU;KACb,UAAAT,EAAG,iCAAiC,KAAK;IACtC,CAAA;GACH;EAEA,CAAA,CAAA;;AAEb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function TemplatesPage(): import('react').JSX.Element;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { useNotificationTemplates as e } from "../../hooks/useNotificationTemplates.js";
|
|
2
|
+
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
+
import { useNotificationPaths as n } from "../../navigation-v2/paths.js";
|
|
4
|
+
import { AdminPageV2 as r } from "../../navigation-v2/AdminPageV2.js";
|
|
5
|
+
import { channelWord as i, kindWord as a } from "./words.js";
|
|
6
|
+
import { readDetails as o, toReadable as s } from "./templateText.js";
|
|
7
|
+
import { useMemo as c, useState as l } from "react";
|
|
8
|
+
import { Mail as u, Plus as d, Search as f } from "lucide-react";
|
|
9
|
+
import { useNavigate as p } from "react-router";
|
|
10
|
+
import { jsx as m, jsxs as h } from "react/jsx-runtime";
|
|
11
|
+
import { PageHeader as g } from "@burdenoff/fe-libs/chrome";
|
|
12
|
+
import { ActionMenu as _, Button as v, DataRows as y, EmptyState as b, IconTile as x, Input as S, LoadError as C, StatusChip as w, useConfirm as T, useNotify as E, useWhenLabels as D } from "@burdenoff/fe-libs/ui";
|
|
13
|
+
// src/v2/admin/TemplatesPage.tsx
|
|
14
|
+
function O() {
|
|
15
|
+
return /* @__PURE__ */ m(r, {
|
|
16
|
+
tool: "templates",
|
|
17
|
+
back: !1,
|
|
18
|
+
children: /* @__PURE__ */ m(k, {})
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function k() {
|
|
22
|
+
let r = t(), O = p(), k = n(), A = T(), j = E(), M = D(), N = e(), [P, F] = l(""), I = c(() => {
|
|
23
|
+
let e = P.trim().toLowerCase(), t = N.allTemplates;
|
|
24
|
+
return e ? t.filter((t) => t.name.toLowerCase().includes(e) || (t.subject ?? "").toLowerCase().includes(e)) : t;
|
|
25
|
+
}, [P, N.allTemplates]), L = async (e) => {
|
|
26
|
+
try {
|
|
27
|
+
await N.updateTemplate(e.id, { enabled: !e.enabled }), j({
|
|
28
|
+
title: e.enabled ? r("notifications.v3.templates.turnedOff", "{{name}} is off", { name: e.name }) : r("notifications.v3.templates.turnedOn", "{{name}} is on", { name: e.name }),
|
|
29
|
+
tone: "success"
|
|
30
|
+
}), await N.refetch();
|
|
31
|
+
} catch {
|
|
32
|
+
j({
|
|
33
|
+
title: r("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
|
|
34
|
+
tone: "error"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}, R = async (e) => {
|
|
38
|
+
if (await A({
|
|
39
|
+
title: r("notifications.v3.templates.deleteTitle", "Delete {{name}}?", { name: e.name }),
|
|
40
|
+
description: r("notifications.v3.templates.deleteBody", "Anything that sends this template stops sending it. Messages already sent stay as they are."),
|
|
41
|
+
confirmLabel: r("notifications.v3.templates.delete", "Delete"),
|
|
42
|
+
tone: "danger",
|
|
43
|
+
typeToConfirm: e.name
|
|
44
|
+
})) try {
|
|
45
|
+
await N.deleteTemplate(e.id), j({
|
|
46
|
+
title: r("notifications.v3.templates.deleted", "Deleted {{name}}", { name: e.name }),
|
|
47
|
+
tone: "success"
|
|
48
|
+
}), await N.refetch();
|
|
49
|
+
} catch {
|
|
50
|
+
j({
|
|
51
|
+
title: r("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
|
|
52
|
+
tone: "error"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return /* @__PURE__ */ h("div", {
|
|
57
|
+
"data-account-pages-v2": "notification-templates",
|
|
58
|
+
className: "flex w-full min-w-0 flex-col",
|
|
59
|
+
children: [/* @__PURE__ */ m(g, {
|
|
60
|
+
variant: "compact",
|
|
61
|
+
title: r("notifications.v3.templates.title", "Templates"),
|
|
62
|
+
description: r("notifications.v3.templates.purpose", "Messages written once and sent many times: what they say, and how they’re sent."),
|
|
63
|
+
back: {
|
|
64
|
+
label: r("notifications.v3.title", "Notifications"),
|
|
65
|
+
to: k.inbox
|
|
66
|
+
},
|
|
67
|
+
primary: /* @__PURE__ */ h(v, {
|
|
68
|
+
onClick: () => O(k.newTemplate),
|
|
69
|
+
"data-testid": "templates-new",
|
|
70
|
+
children: [/* @__PURE__ */ m(d, { "aria-hidden": "true" }), r("notifications.v3.templates.new", "New template")]
|
|
71
|
+
})
|
|
72
|
+
}), /* @__PURE__ */ h("div", {
|
|
73
|
+
className: "flex flex-col gap-3",
|
|
74
|
+
children: [/* @__PURE__ */ h("label", {
|
|
75
|
+
className: "relative block max-w-md",
|
|
76
|
+
children: [
|
|
77
|
+
/* @__PURE__ */ m("span", {
|
|
78
|
+
className: "sr-only",
|
|
79
|
+
children: r("notifications.v3.templates.search", "Search templates")
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ m(f, {
|
|
82
|
+
className: "pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-text-muted",
|
|
83
|
+
"aria-hidden": "true"
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ m(S, {
|
|
86
|
+
type: "search",
|
|
87
|
+
className: "pl-9",
|
|
88
|
+
value: P,
|
|
89
|
+
placeholder: r("notifications.v3.templates.search", "Search templates"),
|
|
90
|
+
onChange: (e) => F(e.target.value)
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}), N.error && I.length === 0 ? /* @__PURE__ */ m(C, {
|
|
94
|
+
what: r("notifications.v3.templates.title", "Templates"),
|
|
95
|
+
error: N.error,
|
|
96
|
+
onRetry: () => void N.refetch()
|
|
97
|
+
}) : !N.isLoading && I.length === 0 ? P.trim() ? /* @__PURE__ */ m(b, {
|
|
98
|
+
kind: "no-results",
|
|
99
|
+
title: r("notifications.v3.templates.noMatch", "No templates match"),
|
|
100
|
+
description: r("notifications.v3.empty.searchBody", "Try other words.")
|
|
101
|
+
}) : /* @__PURE__ */ m(b, {
|
|
102
|
+
kind: "first-use",
|
|
103
|
+
title: r("notifications.v3.templates.emptyTitle", "No templates yet"),
|
|
104
|
+
description: r("notifications.v3.templates.emptyBody", "A template is a message you write once, like a welcome email, and send many times."),
|
|
105
|
+
action: /* @__PURE__ */ m(v, {
|
|
106
|
+
onClick: () => O(k.newTemplate),
|
|
107
|
+
children: r("notifications.v3.templates.new", "New template")
|
|
108
|
+
})
|
|
109
|
+
}) : /* @__PURE__ */ m(y, {
|
|
110
|
+
items: I,
|
|
111
|
+
loading: N.isLoading && I.length === 0,
|
|
112
|
+
skeletonRows: 5,
|
|
113
|
+
getId: (e) => e.id,
|
|
114
|
+
label: r("notifications.v3.templates.title", "Templates"),
|
|
115
|
+
lead: {
|
|
116
|
+
header: r("notifications.v3.templates.template", "Template"),
|
|
117
|
+
media: () => /* @__PURE__ */ m(x, {
|
|
118
|
+
size: "sm",
|
|
119
|
+
children: /* @__PURE__ */ m(u, { "aria-hidden": "true" })
|
|
120
|
+
}),
|
|
121
|
+
title: (e) => e.name,
|
|
122
|
+
subtitle: (e) => e.subject ? s(e.subject, o(e.variables)) : void 0,
|
|
123
|
+
onOpen: (e) => O(k.template(e.slug))
|
|
124
|
+
},
|
|
125
|
+
columns: [
|
|
126
|
+
{
|
|
127
|
+
id: "kind",
|
|
128
|
+
header: r("notifications.v3.templates.kind", "About"),
|
|
129
|
+
cell: (e) => a(e.type, r)
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "channel",
|
|
133
|
+
header: r("notifications.v3.templates.channel", "Sent by"),
|
|
134
|
+
cell: (e) => i(e.channel, r)
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: "edited",
|
|
138
|
+
header: r("notifications.v3.templates.edited", "Edited"),
|
|
139
|
+
cell: (e) => M.moment(e.updatedAt)
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: "status",
|
|
143
|
+
header: r("notifications.v3.templates.status", "Status"),
|
|
144
|
+
cell: (e) => e.enabled ? /* @__PURE__ */ m(w, {
|
|
145
|
+
status: "ok",
|
|
146
|
+
children: r("notifications.v3.on", "On")
|
|
147
|
+
}) : /* @__PURE__ */ m(w, {
|
|
148
|
+
status: "paused",
|
|
149
|
+
children: r("notifications.v3.off", "Off")
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
actions: (e) => /* @__PURE__ */ m(_, {
|
|
154
|
+
placement: "row",
|
|
155
|
+
label: r("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
|
|
156
|
+
items: [{
|
|
157
|
+
id: "toggle",
|
|
158
|
+
label: e.enabled ? r("notifications.v3.templates.turnOff", "Turn off") : r("notifications.v3.templates.turnOn", "Turn on"),
|
|
159
|
+
onSelect: () => void L(e)
|
|
160
|
+
}, {
|
|
161
|
+
id: "delete",
|
|
162
|
+
label: r("notifications.v3.templates.delete", "Delete"),
|
|
163
|
+
danger: !0,
|
|
164
|
+
onSelect: () => void R(e)
|
|
165
|
+
}]
|
|
166
|
+
})
|
|
167
|
+
})]
|
|
168
|
+
})]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
export { O as TemplatesPage };
|
|
172
|
+
|
|
173
|
+
//# sourceMappingURL=TemplatesPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplatesPage.js","names":["TemplatesPage","AdminPageV2","TemplatesList","tr","useTr","navigate","useNavigate","paths","useNotificationPaths","confirm","useConfirm","notify","useNotify","when","useWhenLabels","templates","useNotificationTemplates","search","setSearch","useState","shown","useMemo","query","all","template","toggle","remove","PageHeader","Button","Plus","Search","Input","event","LoadError","EmptyState","DataRows","IconTile","Mail","toReadable","readDetails","kindWord","channelWord","StatusChip","ActionMenu"],"sources":["../../../src/v2/admin/TemplatesPage.tsx"],"sourcesContent":["/**\n * Templates (BOFF-16785, C2; the mockup's `ntemplates`), under fe-libs' `accountPagesV2`: the\n * messages this product sends, at the list width. A row each (what it's about, how it's sent,\n * when it was edited, on or off), search, New template, and ⋯ (turn off or on, delete). Admins\n * only: anyone else sees who to ask (`AdminPageV2`). Today's hook and storage.\n */\nimport { useMemo, useState } from 'react';\nimport { useNavigate } from 'react-router';\nimport { Mail, Plus, Search } from 'lucide-react';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport {\n ActionMenu,\n Button,\n DataRows,\n EmptyState,\n IconTile,\n Input,\n LoadError,\n StatusChip,\n useConfirm,\n useNotify,\n useWhenLabels,\n} from '@burdenoff/fe-libs/ui';\nimport {\n useNotificationTemplates,\n type BackendNotificationTemplate,\n} from '../../hooks/useNotificationTemplates';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { channelWord, kindWord } from './words';\nimport { readDetails, toReadable } from './templateText';\n\nexport function TemplatesPage() {\n return (\n <AdminPageV2 tool=\"templates\" back={false}>\n <TemplatesList />\n </AdminPageV2>\n );\n}\n\nfunction TemplatesList() {\n const tr = useTr();\n const navigate = useNavigate();\n const paths = useNotificationPaths();\n const confirm = useConfirm();\n const notify = useNotify();\n const when = useWhenLabels();\n const templates = useNotificationTemplates();\n const [search, setSearch] = useState('');\n const shown = useMemo(() => {\n const query = search.trim().toLowerCase();\n const all = templates.allTemplates;\n if (!query) return all;\n return all.filter(\n (template) =>\n template.name.toLowerCase().includes(query) ||\n (template.subject ?? '').toLowerCase().includes(query)\n );\n }, [search, templates.allTemplates]);\n\n const toggle = async (template: BackendNotificationTemplate) => {\n try {\n await templates.updateTemplate(template.id, { enabled: !template.enabled });\n notify({\n title: template.enabled\n ? tr('notifications.v3.templates.turnedOff', '{{name}} is off', { name: template.name })\n : tr('notifications.v3.templates.turnedOn', '{{name}} is on', { name: template.name }),\n tone: 'success',\n });\n await templates.refetch();\n } catch {\n notify({\n title: tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.'),\n tone: 'error',\n });\n }\n };\n\n const remove = async (template: BackendNotificationTemplate) => {\n const yes = await confirm({\n title: tr('notifications.v3.templates.deleteTitle', 'Delete {{name}}?', {\n name: template.name,\n }),\n description: tr(\n 'notifications.v3.templates.deleteBody',\n 'Anything that sends this template stops sending it. Messages already sent stay as they are.'\n ),\n confirmLabel: tr('notifications.v3.templates.delete', 'Delete'),\n tone: 'danger',\n typeToConfirm: template.name,\n });\n if (!yes) return;\n try {\n await templates.deleteTemplate(template.id);\n notify({\n title: tr('notifications.v3.templates.deleted', 'Deleted {{name}}', {\n name: template.name,\n }),\n tone: 'success',\n });\n await templates.refetch();\n } catch {\n notify({\n title: tr('notifications.v3.templates.deleteFailed', 'Couldn’t delete it. Try again.'),\n tone: 'error',\n });\n }\n };\n\n return (\n <div data-account-pages-v2=\"notification-templates\" className=\"flex w-full min-w-0 flex-col\">\n <PageHeader\n variant=\"compact\"\n title={tr('notifications.v3.templates.title', 'Templates')}\n description={tr(\n 'notifications.v3.templates.purpose',\n 'Messages written once and sent many times: what they say, and how they’re sent.'\n )}\n back={{ label: tr('notifications.v3.title', 'Notifications'), to: paths.inbox }}\n primary={\n <Button onClick={() => navigate(paths.newTemplate)} data-testid=\"templates-new\">\n <Plus aria-hidden=\"true\" />\n {tr('notifications.v3.templates.new', 'New template')}\n </Button>\n }\n />\n <div className=\"flex flex-col gap-3\">\n <label className=\"relative block max-w-md\">\n <span className=\"sr-only\">\n {tr('notifications.v3.templates.search', 'Search templates')}\n </span>\n <Search\n className=\"pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-text-muted\"\n aria-hidden=\"true\"\n />\n <Input\n type=\"search\"\n className=\"pl-9\"\n value={search}\n placeholder={tr('notifications.v3.templates.search', 'Search templates')}\n onChange={(event) => setSearch(event.target.value)}\n />\n </label>\n {templates.error && shown.length === 0 ? (\n <LoadError\n what={tr('notifications.v3.templates.title', 'Templates')}\n error={templates.error}\n onRetry={() => void templates.refetch()}\n />\n ) : !templates.isLoading && shown.length === 0 ? (\n search.trim() ? (\n <EmptyState\n kind=\"no-results\"\n title={tr('notifications.v3.templates.noMatch', 'No templates match')}\n description={tr('notifications.v3.empty.searchBody', 'Try other words.')}\n />\n ) : (\n <EmptyState\n kind=\"first-use\"\n title={tr('notifications.v3.templates.emptyTitle', 'No templates yet')}\n description={tr(\n 'notifications.v3.templates.emptyBody',\n 'A template is a message you write once, like a welcome email, and send many times.'\n )}\n action={\n <Button onClick={() => navigate(paths.newTemplate)}>\n {tr('notifications.v3.templates.new', 'New template')}\n </Button>\n }\n />\n )\n ) : (\n <DataRows\n items={shown}\n loading={templates.isLoading && shown.length === 0}\n skeletonRows={5}\n getId={(template) => template.id}\n label={tr('notifications.v3.templates.title', 'Templates')}\n lead={{\n header: tr('notifications.v3.templates.template', 'Template'),\n media: () => (\n <IconTile size=\"sm\">\n <Mail aria-hidden=\"true\" />\n </IconTile>\n ),\n title: (template) => template.name,\n subtitle: (template) =>\n template.subject\n ? toReadable(template.subject, readDetails(template.variables))\n : undefined,\n onOpen: (template) => navigate(paths.template(template.slug)),\n }}\n columns={[\n {\n id: 'kind',\n header: tr('notifications.v3.templates.kind', 'About'),\n cell: (template) => kindWord(template.type, tr),\n },\n {\n id: 'channel',\n header: tr('notifications.v3.templates.channel', 'Sent by'),\n cell: (template) => channelWord(template.channel, tr),\n },\n {\n id: 'edited',\n header: tr('notifications.v3.templates.edited', 'Edited'),\n cell: (template) => when.moment(template.updatedAt),\n },\n {\n id: 'status',\n header: tr('notifications.v3.templates.status', 'Status'),\n cell: (template) =>\n template.enabled ? (\n <StatusChip status=\"ok\">{tr('notifications.v3.on', 'On')}</StatusChip>\n ) : (\n <StatusChip status=\"paused\">{tr('notifications.v3.off', 'Off')}</StatusChip>\n ),\n },\n ]}\n actions={(template) => (\n <ActionMenu\n placement=\"row\"\n label={tr('notifications.v3.templates.actionsFor', 'Actions for {{name}}', {\n name: template.name,\n })}\n items={[\n {\n id: 'toggle',\n label: template.enabled\n ? tr('notifications.v3.templates.turnOff', 'Turn off')\n : tr('notifications.v3.templates.turnOn', 'Turn on'),\n onSelect: () => void toggle(template),\n },\n {\n id: 'delete',\n label: tr('notifications.v3.templates.delete', 'Delete'),\n danger: true,\n onSelect: () => void remove(template),\n },\n ]}\n />\n )}\n />\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAiCA,SAAgBA,IAAgB;CAC9B,OACE,kBAACC,GAAD;EAAa,MAAK;EAAY,MAAM;EAClC,UAAA,kBAACC,GAAD,CAAgB,CAAA;CACL,CAAA;AAEjB;AAEA,SAASA,IAAgB;CACvB,IAAMC,IAAKC,EAAM,GACXC,IAAWC,EAAY,GACvBC,IAAQC,EAAqB,GAC7BC,IAAUC,EAAW,GACrBC,IAASC,EAAU,GACnBC,IAAOC,EAAc,GACrBC,IAAYC,EAAyB,GACrC,CAACC,GAAQC,KAAaC,EAAS,EAAE,GACjCC,IAAQC,QAAc;EAC1B,IAAMC,IAAQL,EAAO,KAAK,CAAC,CAAC,YAAY,GAClCM,IAAMR,EAAU;EAEtB,OADKO,IACEC,EAAI,QACR,MACCC,EAAS,KAAK,YAAY,CAAC,CAAC,SAASF,CAAK,MACzCE,EAAS,WAAW,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AAQ;MACR,gBAAgB,KAAKuB,EAAOF,CAAQ;KACtC,CACF;IACD,CAAA;GAEJ,CAAA,CAEA;EACF,CAAA,CAAA;;AAET"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NotificationTopic } from '../../types';
|
|
2
|
+
import { useNotificationTopics } from '../../hooks/useNotificationTopics';
|
|
3
|
+
type Topics = ReturnType<typeof useNotificationTopics>;
|
|
4
|
+
export declare function TopicDialog({ open, topic, onClose, onCreate, onUpdate, }: {
|
|
5
|
+
open: boolean;
|
|
6
|
+
topic: NotificationTopic | null;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onCreate: Topics['createTopic'];
|
|
9
|
+
onUpdate: Topics['updateTopic'];
|
|
10
|
+
}): import('react').JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { useTr as e } from "../../shared/hooks/useTr.js";
|
|
2
|
+
import { templateSlug as t } from "./templateText.js";
|
|
3
|
+
import { ChoiceSelect as n } from "./ChoiceSelect.js";
|
|
4
|
+
import { TEMPLATE_KINDS as r, isKind as i, kindWord as a } from "./words.js";
|
|
5
|
+
import { useId as o, useState as s } from "react";
|
|
6
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
7
|
+
import { Button as u, Input as d, Label as f, Notice as p, ResponsiveDialog as m, ResponsiveDialogContent as h, ResponsiveDialogDescription as g, ResponsiveDialogFooter as _, ResponsiveDialogHeader as v, ResponsiveDialogTitle as y, useNotify as b } from "@burdenoff/fe-libs/ui";
|
|
8
|
+
// src/v2/admin/TopicDialog.tsx
|
|
9
|
+
function x({ open: e, topic: t, onClose: n, onCreate: r, onUpdate: i }) {
|
|
10
|
+
return /* @__PURE__ */ c(m, {
|
|
11
|
+
open: e,
|
|
12
|
+
onOpenChange: (e) => e ? void 0 : n(),
|
|
13
|
+
children: e ? /* @__PURE__ */ c(S, {
|
|
14
|
+
topic: t,
|
|
15
|
+
onClose: n,
|
|
16
|
+
onCreate: r,
|
|
17
|
+
onUpdate: i
|
|
18
|
+
}, t?.id ?? "new") : null
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function S({ topic: m, onClose: x, onCreate: S, onUpdate: C }) {
|
|
22
|
+
let w = e(), T = o(), E = b(), [D, O] = s(m?.name ?? ""), [k, A] = s(m?.description ?? ""), [j, M] = s(m && i(m.type) ? m.type : "MARKETING"), [N, P] = s(!1), [F, I] = s(!1), L = () => m ? C(m.id, {
|
|
23
|
+
name: D.trim(),
|
|
24
|
+
description: k.trim() || void 0
|
|
25
|
+
}) : S({
|
|
26
|
+
name: D.trim(),
|
|
27
|
+
slug: t(D),
|
|
28
|
+
description: k.trim() || void 0,
|
|
29
|
+
type: j,
|
|
30
|
+
isActive: !0
|
|
31
|
+
}), R = async () => {
|
|
32
|
+
P(!0), I(!1);
|
|
33
|
+
let e = null;
|
|
34
|
+
try {
|
|
35
|
+
e = await L();
|
|
36
|
+
} catch {
|
|
37
|
+
e = null;
|
|
38
|
+
} finally {
|
|
39
|
+
P(!1);
|
|
40
|
+
}
|
|
41
|
+
e ? (E({
|
|
42
|
+
title: m ? w("notifications.v3.topics.saved", "Saved {{name}}", { name: e.name }) : w("notifications.v3.topics.created", "{{name}} is ready", { name: e.name }),
|
|
43
|
+
tone: "success"
|
|
44
|
+
}), x()) : I(!0);
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ l(h, { children: [/* @__PURE__ */ l(v, { children: [/* @__PURE__ */ c(y, { children: m ? w("notifications.v3.topics.editTitle", "Edit topic") : w("notifications.v3.topics.new", "New topic") }), /* @__PURE__ */ c(g, { children: w("notifications.v3.topics.dialogHelp", "People see its name and line in their notification settings.") })] }), /* @__PURE__ */ l("form", {
|
|
47
|
+
className: "flex flex-col gap-4",
|
|
48
|
+
onSubmit: (e) => {
|
|
49
|
+
e.preventDefault(), D.trim().length > 1 && !N && R();
|
|
50
|
+
},
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ l("div", {
|
|
53
|
+
className: "flex flex-col gap-1.5",
|
|
54
|
+
children: [/* @__PURE__ */ c(f, {
|
|
55
|
+
htmlFor: `${T}-name`,
|
|
56
|
+
children: w("notifications.v3.template.name", "Name")
|
|
57
|
+
}), /* @__PURE__ */ c(d, {
|
|
58
|
+
id: `${T}-name`,
|
|
59
|
+
autoFocus: !0,
|
|
60
|
+
value: D,
|
|
61
|
+
placeholder: w("notifications.v3.topics.namePlaceholder", "For example: Product news"),
|
|
62
|
+
onChange: (e) => O(e.target.value),
|
|
63
|
+
"data-testid": "topic-name"
|
|
64
|
+
})]
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ l("div", {
|
|
67
|
+
className: "flex flex-col gap-1.5",
|
|
68
|
+
children: [/* @__PURE__ */ c(f, {
|
|
69
|
+
htmlFor: `${T}-about`,
|
|
70
|
+
children: w("notifications.v3.topics.about", "One line about it (optional)")
|
|
71
|
+
}), /* @__PURE__ */ c(d, {
|
|
72
|
+
id: `${T}-about`,
|
|
73
|
+
value: k,
|
|
74
|
+
onChange: (e) => A(e.target.value)
|
|
75
|
+
})]
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ l("div", {
|
|
78
|
+
className: "flex flex-col gap-1.5",
|
|
79
|
+
children: [/* @__PURE__ */ c(f, {
|
|
80
|
+
htmlFor: `${T}-kind`,
|
|
81
|
+
children: w("notifications.v3.template.kind", "About")
|
|
82
|
+
}), /* @__PURE__ */ c(n, {
|
|
83
|
+
id: `${T}-kind`,
|
|
84
|
+
value: j,
|
|
85
|
+
options: r,
|
|
86
|
+
word: (e) => a(e, w),
|
|
87
|
+
onChange: M,
|
|
88
|
+
disabled: !!m
|
|
89
|
+
})]
|
|
90
|
+
}),
|
|
91
|
+
F ? /* @__PURE__ */ c(p, {
|
|
92
|
+
tone: "bad",
|
|
93
|
+
role: "alert",
|
|
94
|
+
children: w("notifications.v3.templates.saveFailed", "Couldn’t save. Try again.")
|
|
95
|
+
}) : null,
|
|
96
|
+
/* @__PURE__ */ l(_, { children: [/* @__PURE__ */ c(u, {
|
|
97
|
+
type: "button",
|
|
98
|
+
variant: "ghost",
|
|
99
|
+
onClick: x,
|
|
100
|
+
children: w("notifications.v3.cancel", "Cancel")
|
|
101
|
+
}), /* @__PURE__ */ c(u, {
|
|
102
|
+
type: "submit",
|
|
103
|
+
busy: N,
|
|
104
|
+
disabled: D.trim().length < 2,
|
|
105
|
+
"data-testid": "topic-save",
|
|
106
|
+
children: m ? w("notifications.v3.template.save", "Save") : w("notifications.v3.topics.create", "Create topic")
|
|
107
|
+
})] })
|
|
108
|
+
]
|
|
109
|
+
})] });
|
|
110
|
+
}
|
|
111
|
+
export { x as TopicDialog };
|
|
112
|
+
|
|
113
|
+
//# sourceMappingURL=TopicDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TopicDialog.js","names":["TopicDialog","ResponsiveDialog","next","onClose","open","TopicForm","topic","tr","useTr","id","useId","notify","useNotify","name","setName","useState","description","setDescription","kind","setKind","isKind","busy","setBusy","failed","setFailed","send","onUpdate","onCreate","templateSlug","save","result","ResponsiveDialogContent","ResponsiveDialogHeader","ResponsiveDialogTitle","ResponsiveDialogDescription","event","Label","Input","ChoiceSelect","TEMPLATE_KINDS","kindWord","option","Notice","ResponsiveDialogFooter","Button"],"sources":["../../../src/v2/admin/TopicDialog.tsx"],"sourcesContent":["/**\n * New topic or Edit topic (BOFF-16785, C2): its name, one line about it, and what kind of\n * notifications it groups (set when it's made).\n */\nimport { useId, useState } from 'react';\nimport {\n Button,\n Input,\n Label,\n Notice,\n ResponsiveDialog,\n ResponsiveDialogContent,\n ResponsiveDialogDescription,\n ResponsiveDialogFooter,\n ResponsiveDialogHeader,\n ResponsiveDialogTitle,\n useNotify,\n} from '@burdenoff/fe-libs/ui';\nimport type { NotificationTopic } from '../../types';\nimport type { useNotificationTopics } from '../../hooks/useNotificationTopics';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { templateSlug } from './templateText';\nimport { ChoiceSelect } from './ChoiceSelect';\nimport { isKind, kindWord, TEMPLATE_KINDS, type TemplateKind } from './words';\n\ntype Topics = ReturnType<typeof useNotificationTopics>;\n\nexport function TopicDialog({\n open,\n topic,\n onClose,\n onCreate,\n onUpdate,\n}: {\n open: boolean;\n topic: NotificationTopic | null;\n onClose: () => void;\n onCreate: Topics['createTopic'];\n onUpdate: Topics['updateTopic'];\n}) {\n return (\n <ResponsiveDialog open={open} onOpenChange={(next) => (next ? undefined : onClose())}>\n {open ? (\n <TopicForm\n key={topic?.id ?? 'new'}\n topic={topic}\n onClose={onClose}\n onCreate={onCreate}\n onUpdate={onUpdate}\n />\n ) : null}\n </ResponsiveDialog>\n );\n}\n\nfunction TopicForm({\n topic,\n onClose,\n onCreate,\n onUpdate,\n}: {\n topic: NotificationTopic | null;\n onClose: () => void;\n onCreate: Topics['createTopic'];\n onUpdate: Topics['updateTopic'];\n}) {\n const tr = useTr();\n const id = useId();\n const notify = useNotify();\n const [name, setName] = useState(topic?.name ?? '');\n const [description, setDescription] = useState(topic?.description ?? '');\n const [kind, setKind] = useState<TemplateKind>(\n topic && isKind(topic.type) ? topic.type : 'MARKETING'\n );\n const [busy, setBusy] = useState(false);\n const [failed, setFailed] = useState(false);\n\n const send = () =>\n topic\n ? onUpdate(topic.id, {\n name: name.trim(),\n description: description.trim() || undefined,\n })\n : onCreate({\n name: name.trim(),\n slug: templateSlug(name),\n description: description.trim() || undefined,\n type: kind,\n isActive: true,\n });\n\n const save = async () => {\n setBusy(true);\n setFailed(false);\n let result: NotificationTopic | null = null;\n try {\n result = await send();\n } catch {\n result = null;\n } finally {\n setBusy(false);\n }\n if (!result) {\n setFailed(true);\n return;\n }\n notify({\n title: topic\n ? tr('notifications.v3.topics.saved', 'Saved {{name}}', { name: result.name })\n : tr('notifications.v3.topics.created', '{{name}} is ready', { name: result.name }),\n tone: 'success',\n });\n onClose();\n };\n\n return (\n <ResponsiveDialogContent>\n <ResponsiveDialogHeader>\n <ResponsiveDialogTitle>\n {topic\n ? tr('notifications.v3.topics.editTitle', 'Edit topic')\n : tr('notifications.v3.topics.new', 'New topic')}\n </ResponsiveDialogTitle>\n <ResponsiveDialogDescription>\n {tr(\n 'notifications.v3.topics.dialogHelp',\n 'People see its name and line in their notification settings.'\n )}\n </ResponsiveDialogDescription>\n </ResponsiveDialogHeader>\n <form\n className=\"flex flex-col gap-4\"\n onSubmit={(event) => {\n event.preventDefault();\n if (name.trim().length > 1 && !busy) void save();\n }}\n >\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor={`${id}-name`}>{tr('notifications.v3.template.name', 'Name')}</Label>\n <Input\n id={`${id}-name`}\n autoFocus\n value={name}\n placeholder={tr('notifications.v3.topics.namePlaceholder', 'For example: Product news')}\n onChange={(event) => setName(event.target.value)}\n data-testid=\"topic-name\"\n />\n </div>\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor={`${id}-about`}>\n {tr('notifications.v3.topics.about', 'One line about it (optional)')}\n </Label>\n <Input\n id={`${id}-about`}\n value={description}\n onChange={(event) => setDescription(event.target.value)}\n />\n </div>\n <div className=\"flex flex-col gap-1.5\">\n <Label htmlFor={`${id}-kind`}>{tr('notifications.v3.template.kind', 'About')}</Label>\n <ChoiceSelect\n id={`${id}-kind`}\n value={kind}\n options={TEMPLATE_KINDS}\n word={(option) => kindWord(option, tr)}\n onChange={setKind}\n disabled={Boolean(topic)}\n />\n </div>\n {failed ? (\n <Notice tone=\"bad\" role=\"alert\">\n {tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.')}\n </Notice>\n ) : null}\n <ResponsiveDialogFooter>\n <Button type=\"button\" variant=\"ghost\" onClick={onClose}>\n {tr('notifications.v3.cancel', 'Cancel')}\n </Button>\n <Button\n type=\"submit\"\n busy={busy}\n disabled={name.trim().length < 2}\n data-testid=\"topic-save\"\n >\n {topic\n ? tr('notifications.v3.template.save', 'Save')\n : tr('notifications.v3.topics.create', 'Create topic')}\n </Button>\n </Responsive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G7B,EAAG;KACV,OAAOS;KACP,SAASqB;KACT,OAAO,MAAWC,EAASC,GAAQlC,CAAE;KACrC,UAAUY;KACV,UAAU,EAAQb;IACnB,CAAA,CACE;;GACJiB,IACC,kBAACmB,GAAD;IAAQ,MAAK;IAAM,MAAK;IACrB,UAAAnC,EAAG,yCAAyC,2BAA2B;GAClE,CAAA,IACN;GACJ,kBAACoC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;IAAQ,MAAK;IAAS,SAAQ;IAAQ,SAASzC;IAC5C,UAAAI,EAAG,2BAA2B,QAAQ;GACjC,CAAA,GACR,kBAACqC,GAAD;IACE,MAAK;IACC;IACN,UAAU/B,EAAK,KAAK,CAAC,CAAC,SAAS;IAC/B,eAAY;IAEX,UAAAP,IACGC,EAAG,kCAAkC,MAAM,IAC3CA,EAAG,kCAAkC,cAAc;GACjD,CAAA,CACc,EAAA,CAAA;EACpB;CACiB,CAAA,CAAA,EAAA,CAAA;AAE7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function TopicsPage(): import('react').JSX.Element;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { useNotificationTopics as e } from "../../hooks/useNotificationTopics.js";
|
|
2
|
+
import { useTr as t } from "../../shared/hooks/useTr.js";
|
|
3
|
+
import { useNotificationPaths as n } from "../../navigation-v2/paths.js";
|
|
4
|
+
import { AdminPageV2 as r } from "../../navigation-v2/AdminPageV2.js";
|
|
5
|
+
import { kindWord as i } from "./words.js";
|
|
6
|
+
import { TopicDialog as a } from "./TopicDialog.js";
|
|
7
|
+
import { useState as o } from "react";
|
|
8
|
+
import { Plus as s, Tag as c } from "lucide-react";
|
|
9
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
10
|
+
import { PageHeader as d } from "@burdenoff/fe-libs/chrome";
|
|
11
|
+
import { ActionMenu as f, Button as p, DataRows as m, EmptyState as h, IconTile as g, LoadError as _, StatusChip as v, useConfirm as y, useNotify as b } from "@burdenoff/fe-libs/ui";
|
|
12
|
+
// src/v2/admin/TopicsPage.tsx
|
|
13
|
+
var x = new Intl.NumberFormat();
|
|
14
|
+
function S() {
|
|
15
|
+
return /* @__PURE__ */ l(r, {
|
|
16
|
+
tool: "topics",
|
|
17
|
+
back: !1,
|
|
18
|
+
children: /* @__PURE__ */ l(C, {})
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function C() {
|
|
22
|
+
let r = t(), S = n(), C = y(), w = b(), T = e(), [E, D] = o(null), O = async (e) => {
|
|
23
|
+
let t = await T.updateTopic(e.id, { isActive: !e.isActive });
|
|
24
|
+
w(t ? {
|
|
25
|
+
title: e.isActive ? r("notifications.v3.topics.turnedOff", "{{name}} is off", { name: e.name }) : r("notifications.v3.topics.turnedOn", "{{name}} is on", { name: e.name }),
|
|
26
|
+
tone: "success"
|
|
27
|
+
} : {
|
|
28
|
+
title: r("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
|
|
29
|
+
tone: "error"
|
|
30
|
+
});
|
|
31
|
+
}, k = async (e) => {
|
|
32
|
+
if (!await C({
|
|
33
|
+
title: r("notifications.v3.topics.deleteTitle", "Delete {{name}}?", { name: e.name }),
|
|
34
|
+
description: r("notifications.v3.topics.deleteBody", "People stop being able to choose it in their settings."),
|
|
35
|
+
confirmLabel: r("notifications.v3.templates.delete", "Delete"),
|
|
36
|
+
tone: "danger",
|
|
37
|
+
typeToConfirm: e.name
|
|
38
|
+
})) return;
|
|
39
|
+
let t = await T.deleteTopic(e.id);
|
|
40
|
+
w(t ? {
|
|
41
|
+
title: r("notifications.v3.templates.deleted", "Deleted {{name}}", { name: e.name }),
|
|
42
|
+
tone: "success"
|
|
43
|
+
} : {
|
|
44
|
+
title: r("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
|
|
45
|
+
tone: "error"
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return /* @__PURE__ */ u("div", {
|
|
49
|
+
"data-account-pages-v2": "notification-topics",
|
|
50
|
+
className: "flex w-full min-w-0 flex-col",
|
|
51
|
+
children: [
|
|
52
|
+
/* @__PURE__ */ l(d, {
|
|
53
|
+
variant: "compact",
|
|
54
|
+
title: r("notifications.v3.topics.title", "Topics"),
|
|
55
|
+
description: r("notifications.v3.topics.purpose", "Groups of notifications people can turn on or off."),
|
|
56
|
+
back: {
|
|
57
|
+
label: r("notifications.v3.title", "Notifications"),
|
|
58
|
+
to: S.inbox
|
|
59
|
+
},
|
|
60
|
+
primary: /* @__PURE__ */ u(p, {
|
|
61
|
+
onClick: () => D("new"),
|
|
62
|
+
"data-testid": "topics-new",
|
|
63
|
+
children: [/* @__PURE__ */ l(s, { "aria-hidden": "true" }), r("notifications.v3.topics.new", "New topic")]
|
|
64
|
+
})
|
|
65
|
+
}),
|
|
66
|
+
T.error && T.topics.length === 0 ? /* @__PURE__ */ l(_, {
|
|
67
|
+
what: r("notifications.v3.topics.title", "Topics"),
|
|
68
|
+
error: T.error,
|
|
69
|
+
onRetry: () => void T.refetch()
|
|
70
|
+
}) : !T.isLoading && T.topics.length === 0 ? /* @__PURE__ */ l(h, {
|
|
71
|
+
kind: "first-use",
|
|
72
|
+
title: r("notifications.v3.topics.emptyTitle", "No topics yet"),
|
|
73
|
+
description: r("notifications.v3.topics.emptyBody", "Topics let people choose what they hear about, like “Billing” or “Product news”."),
|
|
74
|
+
action: /* @__PURE__ */ l(p, {
|
|
75
|
+
onClick: () => D("new"),
|
|
76
|
+
children: r("notifications.v3.topics.new", "New topic")
|
|
77
|
+
})
|
|
78
|
+
}) : /* @__PURE__ */ l(m, {
|
|
79
|
+
items: T.topics,
|
|
80
|
+
loading: T.isLoading && T.topics.length === 0,
|
|
81
|
+
skeletonRows: 4,
|
|
82
|
+
getId: (e) => e.id,
|
|
83
|
+
label: r("notifications.v3.topics.title", "Topics"),
|
|
84
|
+
lead: {
|
|
85
|
+
header: r("notifications.v3.topics.topic", "Topic"),
|
|
86
|
+
media: () => /* @__PURE__ */ l(g, {
|
|
87
|
+
size: "sm",
|
|
88
|
+
children: /* @__PURE__ */ l(c, { "aria-hidden": "true" })
|
|
89
|
+
}),
|
|
90
|
+
title: (e) => e.name,
|
|
91
|
+
subtitle: (e) => e.description || void 0,
|
|
92
|
+
onOpen: (e) => D(e)
|
|
93
|
+
},
|
|
94
|
+
columns: [
|
|
95
|
+
{
|
|
96
|
+
id: "people",
|
|
97
|
+
header: r("notifications.v3.topics.people", "Following"),
|
|
98
|
+
cell: (e) => x.format(e.subscriberCount ?? 0)
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "kind",
|
|
102
|
+
header: r("notifications.v3.templates.kind", "About"),
|
|
103
|
+
cell: (e) => i(e.type, r)
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "status",
|
|
107
|
+
header: r("notifications.v3.templates.status", "Status"),
|
|
108
|
+
cell: (e) => e.isActive ? /* @__PURE__ */ l(v, {
|
|
109
|
+
status: "ok",
|
|
110
|
+
children: r("notifications.v3.on", "On")
|
|
111
|
+
}) : /* @__PURE__ */ l(v, {
|
|
112
|
+
status: "paused",
|
|
113
|
+
children: r("notifications.v3.off", "Off")
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
actions: (e) => /* @__PURE__ */ l(f, {
|
|
118
|
+
placement: "row",
|
|
119
|
+
label: r("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
|
|
120
|
+
items: [
|
|
121
|
+
{
|
|
122
|
+
id: "edit",
|
|
123
|
+
label: r("notifications.v3.topics.edit", "Edit"),
|
|
124
|
+
onSelect: () => D(e)
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: "toggle",
|
|
128
|
+
label: e.isActive ? r("notifications.v3.templates.turnOff", "Turn off") : r("notifications.v3.templates.turnOn", "Turn on"),
|
|
129
|
+
onSelect: () => void O(e)
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "delete",
|
|
133
|
+
label: r("notifications.v3.templates.delete", "Delete"),
|
|
134
|
+
danger: !0,
|
|
135
|
+
onSelect: () => void k(e)
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
}),
|
|
140
|
+
/* @__PURE__ */ l(a, {
|
|
141
|
+
open: E !== null,
|
|
142
|
+
topic: E === "new" ? null : E,
|
|
143
|
+
onClose: () => D(null),
|
|
144
|
+
onCreate: T.createTopic,
|
|
145
|
+
onUpdate: T.updateTopic
|
|
146
|
+
})
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export { S as TopicsPage };
|
|
151
|
+
|
|
152
|
+
//# sourceMappingURL=TopicsPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TopicsPage.js","names":["COUNT","TopicsPage","AdminPageV2","TopicsList","tr","useTr","paths","useNotificationPaths","confirm","useConfirm","notify","useNotify","topics","useNotificationTopics","editing","setEditing","useState","toggle","result","topic","remove","done","PageHeader","Button","Plus","LoadError","EmptyState","DataRows","IconTile","Tag","kindWord","StatusChip","ActionMenu","TopicDialog"],"sources":["../../../src/v2/admin/TopicsPage.tsx"],"sourcesContent":["/**\n * Topics (BOFF-16785, C2; the mockup's `ntopics`), under fe-libs' `accountPagesV2`: the groups of\n * notifications people can turn on or off. A row each (who follows it, what it's about, on or off),\n * New topic and Edit in a short dialog, and ⋯ (turn off or on, delete). Admins only\n * (`AdminPageV2`). Today's hook and storage.\n */\nimport { useState } from 'react';\nimport { Plus, Tag } from 'lucide-react';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport {\n ActionMenu,\n Button,\n DataRows,\n EmptyState,\n IconTile,\n LoadError,\n StatusChip,\n useConfirm,\n useNotify,\n} from '@burdenoff/fe-libs/ui';\nimport { useNotificationTopics } from '../../hooks';\nimport type { NotificationTopic } from '../../types';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { kindWord } from './words';\nimport { TopicDialog } from './TopicDialog';\n\nconst COUNT = new Intl.NumberFormat();\n\nexport function TopicsPage() {\n return (\n <AdminPageV2 tool=\"topics\" back={false}>\n <TopicsList />\n </AdminPageV2>\n );\n}\n\nfunction TopicsList() {\n const tr = useTr();\n const paths = useNotificationPaths();\n const confirm = useConfirm();\n const notify = useNotify();\n const topics = useNotificationTopics();\n const [editing, setEditing] = useState<NotificationTopic | 'new' | null>(null);\n\n const toggle = async (topic: NotificationTopic) => {\n const result = await topics.updateTopic(topic.id, { isActive: !topic.isActive });\n notify(\n result\n ? {\n title: topic.isActive\n ? tr('notifications.v3.topics.turnedOff', '{{name}} is off', { name: topic.name })\n : tr('notifications.v3.topics.turnedOn', '{{name}} is on', { name: topic.name }),\n tone: 'success',\n }\n : {\n title: tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.'),\n tone: 'error',\n }\n );\n };\n\n const remove = async (topic: NotificationTopic) => {\n const yes = await confirm({\n title: tr('notifications.v3.topics.deleteTitle', 'Delete {{name}}?', { name: topic.name }),\n description: tr(\n 'notifications.v3.topics.deleteBody',\n 'People stop being able to choose it in their settings.'\n ),\n confirmLabel: tr('notifications.v3.templates.delete', 'Delete'),\n tone: 'danger',\n typeToConfirm: topic.name,\n });\n if (!yes) return;\n const done = await topics.deleteTopic(topic.id);\n notify(\n done\n ? {\n title: tr('notifications.v3.templates.deleted', 'Deleted {{name}}', {\n name: topic.name,\n }),\n tone: 'success',\n }\n : {\n title: tr('notifications.v3.templates.deleteFailed', 'Couldn’t delete it. Try again.'),\n tone: 'error',\n }\n );\n };\n\n return (\n <div data-account-pages-v2=\"notification-topics\" className=\"flex w-full min-w-0 flex-col\">\n <PageHeader\n variant=\"compact\"\n title={tr('notifications.v3.topics.title', 'Topics')}\n description={tr(\n 'notifications.v3.topics.purpose',\n 'Groups of notifications people can turn on or off.'\n )}\n back={{ label: tr('notifications.v3.title', 'Notifications'), to: paths.inbox }}\n primary={\n <Button onClick={() => setEditing('new')} data-testid=\"topics-new\">\n <Plus aria-hidden=\"true\" />\n {tr('notifications.v3.topics.new', 'New topic')}\n </Button>\n }\n />\n {topics.error && topics.topics.length === 0 ? (\n <LoadError\n what={tr('notifications.v3.topics.title', 'Topics')}\n error={topics.error}\n onRetry={() => void topics.refetch()}\n />\n ) : !topics.isLoading && topics.topics.length === 0 ? (\n <EmptyState\n kind=\"first-use\"\n title={tr('notifications.v3.topics.emptyTitle', 'No topics yet')}\n description={tr(\n 'notifications.v3.topics.emptyBody',\n 'Topics let people choose what they hear about, like “Billing” or “Product news”.'\n )}\n action={\n <Button onClick={() => setEditing('new')}>\n {tr('notifications.v3.topics.new', 'New topic')}\n </Button>\n }\n />\n ) : (\n <DataRows\n items={topics.topics}\n loading={topics.isLoading && topics.topics.length === 0}\n skeletonRows={4}\n getId={(topic) => topic.id}\n label={tr('notifications.v3.topics.title', 'Topics')}\n lead={{\n header: tr('notifications.v3.topics.topic', 'Topic'),\n media: () => (\n <IconTile size=\"sm\">\n <Tag aria-hidden=\"true\" />\n </IconTile>\n ),\n title: (topic) => topic.name,\n subtitle: (topic) => topic.description || undefined,\n onOpen: (topic) => setEditing(topic),\n }}\n columns={[\n {\n id: 'people',\n header: tr('notifications.v3.topics.people', 'Following'),\n cell: (topic) => COUNT.format(topic.subscriberCount ?? 0),\n },\n {\n id: 'kind',\n header: tr('notifications.v3.templates.kind', 'About'),\n cell: (topic) => kindWord(topic.type, tr),\n },\n {\n id: 'status',\n header: tr('notifications.v3.templates.status', 'Status'),\n cell: (topic) =>\n topic.isActive ? (\n <StatusChip status=\"ok\">{tr('notifications.v3.on', 'On')}</StatusChip>\n ) : (\n <StatusChip status=\"paused\">{tr('notifications.v3.off', 'Off')}</StatusChip>\n ),\n },\n ]}\n actions={(topic) => (\n <ActionMenu\n placement=\"row\"\n label={tr('notifications.v3.templates.actionsFor', 'Actions for {{name}}', {\n name: topic.name,\n })}\n items={[\n {\n id: 'edit',\n label: tr('notifications.v3.topics.edit', 'Edit'),\n onSelect: () => setEditing(topic),\n },\n {\n id: 'toggle',\n label: topic.isActive\n ? tr('notifications.v3.templates.turnOff', 'Turn off')\n : tr('notifications.v3.templates.turnOn', 'Turn on'),\n onSelect: () => void toggle(topic),\n },\n {\n id: 'delete',\n label: tr('notifications.v3.templates.delete', 'Delete'),\n danger: true,\n onSelect: () => void remove(topic),\n },\n ]}\n />\n )}\n />\n )}\n <TopicDialog\n open={editing !== null}\n topic={editing === 'new' ? null : editing}\n onClose={() => setEditing(null)}\n onCreate={topics.createTopic}\n onUpdate={topics.updateTopic}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAMA,IAAQ,IAAI,KAAK,aAAa;AAEpC,SAAgBC,IAAa;CAC3B,OACE,kBAACC,GAAD;EAAa,MAAK;EAAS,MAAM;EAC/B,UAAA,kBAACC,GAAD,CAAa,CAAA;CACF,CAAA;AAEjB;AAEA,SAASA,IAAa;CACpB,IAAMC,IAAKC,EAAM,GACXC,IAAQC,EAAqB,GAC7BC,IAAUC,EAAW,GACrBC,IAASC,EAAU,GACnBC,IAASC,EAAsB,GAC/B,CAACC,GAASC,KAAcC,EAA2C,IAAI,GAEvEC,IAAS,OAAO,MAA6B;EACjD,IAAMC,IAAS,MAAMN,EAAO,YAAYO,EAAM,IAAI,EAAE,UAAU,CAACA,EAAM,SAAS,CAAC;EAC/E,EACED,IACI;GACE,OAAOC,EAAM,WACTf,EAAG,qCAAqC,mBAAmB,EAAE,MAAMe,EAAM,KAAK,CAAC,IAC/Ef,EAAG,oCAAoC,kBAAkB,EAAE,MAAMe,EAAM,KAAK,CAAC;GACjF,MAAM;EACR,IACA;GACE,OAAOf,EAAG,yCAAyC,2BAA2B;GAC9E,MAAM;EACR,CACN;CACF,GAEMgB,IAAS,OAAO,MAA6B;EAWjD,IAAI,CAAC,MAVaZ,EAAQ;GACxB,OAAOJ,EAAG,uCAAuC,oBAAoB,EAAE,MAAMe,EAAM,KAAK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J,CAAA;GAEH,kBAACc,GAAD;IACE,MAAMnB,MAAY;IAClB,OAAOA,MAAY,QAAQ,OAAOA;IAClC,eAAeC,EAAW,IAAI;IAC9B,UAAUH,EAAO;IACjB,UAAUA,EAAO;GAClB,CAAA;EACE;;AAET"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A template's text as people read it (BOFF-16785, C2; the mockup's `ntemplate`): the stored
|
|
3
|
+
* `{{firstName}}` shows as the detail `[First name]`, and Insert adds details, so nobody types
|
|
4
|
+
* braces. Saving turns each known `[Label]` back into `{{name}}`; anything else in brackets stays
|
|
5
|
+
* as written. The template's details are its `variables`, stored as today
|
|
6
|
+
* (`{name: {type, required, defaultValue}}`).
|
|
7
|
+
*/
|
|
8
|
+
export type DetailType = 'string' | 'number' | 'boolean' | 'date';
|
|
9
|
+
export interface TemplateDetail {
|
|
10
|
+
name: string;
|
|
11
|
+
type: DetailType;
|
|
12
|
+
defaultValue: string;
|
|
13
|
+
}
|
|
14
|
+
/** "firstName" → "First name", "workflow_name" → "Workflow name", "url" → "Url". */
|
|
15
|
+
export declare function detailLabel(name: string): string;
|
|
16
|
+
/** "First name" → "firstName": the stored name for a detail someone adds. */
|
|
17
|
+
export declare function detailName(label: string): string;
|
|
18
|
+
/** Stored text as people read it: each `{{name}}` of a known detail becomes `[Label]`. */
|
|
19
|
+
export declare function toReadable(text: string, details: readonly Pick<TemplateDetail, 'name'>[]): string;
|
|
20
|
+
/** Text as people wrote it, ready to store: each `[Label]` of a known detail becomes `{{name}}`. */
|
|
21
|
+
export declare function toStored(text: string, details: readonly Pick<TemplateDetail, 'name'>[]): string;
|
|
22
|
+
/** The details a stored text uses (`{{name}}`), in order, once each. */
|
|
23
|
+
export declare function usedDetailNames(stored: string): string[];
|
|
24
|
+
/** A sample for the preview: the detail's default, else a likely value, else its label. */
|
|
25
|
+
export declare function sampleValue(detail: TemplateDetail, locale?: string): string;
|
|
26
|
+
/** Stored text with samples filled in, for the preview. Unknown `{{x}}` stay as they are. */
|
|
27
|
+
export declare function fillSamples(stored: string, details: readonly TemplateDetail[], locale?: string): string;
|
|
28
|
+
/** The stored `variables` (object, or the older array) as details. */
|
|
29
|
+
export declare function readDetails(json: unknown): TemplateDetail[];
|
|
30
|
+
/** Details as stored today: `{name: {type, required, defaultValue?}}`. */
|
|
31
|
+
export declare function writeDetails(details: readonly TemplateDetail[]): Record<string, unknown>;
|
|
32
|
+
/** "Hi there, Maya" → "hi-there-maya": a template's web-safe key from its name. */
|
|
33
|
+
export declare function templateSlug(name: string): string;
|
|
34
|
+
/** Details most messages need, offered when the template doesn't have them yet. */
|
|
35
|
+
export declare const COMMON_DETAILS: readonly TemplateDetail[];
|