@burdenoff/microfe-notification 2026.1129.2 → 2026.1130.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.
Files changed (48) hide show
  1. package/dist/NotificationRoutes.js +73 -72
  2. package/dist/NotificationRoutes.js.map +1 -1
  3. package/dist/hooks/useSendNotification.d.ts +1 -1
  4. package/dist/hooks/useSendNotification.js.map +1 -1
  5. package/dist/translations/en.d.ts +55 -0
  6. package/dist/v2/InboxPage.js +150 -138
  7. package/dist/v2/InboxPage.js.map +1 -1
  8. package/dist/v2/NotificationDetailPanel.d.ts +9 -5
  9. package/dist/v2/NotificationDetailPanel.js +66 -51
  10. package/dist/v2/NotificationDetailPanel.js.map +1 -1
  11. package/dist/v2/PreferencesPage.js +80 -84
  12. package/dist/v2/PreferencesPage.js.map +1 -1
  13. package/dist/v2/admin/DeliveryLogPage.js +44 -48
  14. package/dist/v2/admin/DeliveryLogPage.js.map +1 -1
  15. package/dist/v2/admin/TemplateEditor.js +28 -33
  16. package/dist/v2/admin/TemplateEditor.js.map +1 -1
  17. package/dist/v2/admin/TemplateFields.js +1 -1
  18. package/dist/v2/admin/TemplateFields.js.map +1 -1
  19. package/dist/v2/admin/TemplatePage.js +19 -19
  20. package/dist/v2/admin/TemplatePage.js.map +1 -1
  21. package/dist/v2/admin/TemplatesPage.js +123 -127
  22. package/dist/v2/admin/TemplatesPage.js.map +1 -1
  23. package/dist/v2/admin/TopicsPage.js +101 -105
  24. package/dist/v2/admin/TopicsPage.js.map +1 -1
  25. package/dist/v2/admin/templateText.js +22 -17
  26. package/dist/v2/admin/templateText.js.map +1 -1
  27. package/dist/v2/send/MessageTab.d.ts +4 -0
  28. package/dist/v2/send/MessageTab.js +152 -0
  29. package/dist/v2/send/MessageTab.js.map +1 -0
  30. package/dist/v2/send/PeopleTab.d.ts +4 -0
  31. package/dist/v2/send/PeopleTab.js +156 -0
  32. package/dist/v2/send/PeopleTab.js.map +1 -0
  33. package/dist/v2/send/SendNotificationDialog.d.ts +4 -0
  34. package/dist/v2/send/SendNotificationDialog.js +98 -0
  35. package/dist/v2/send/SendNotificationDialog.js.map +1 -0
  36. package/dist/v2/send/SendRedirect.d.ts +1 -0
  37. package/dist/v2/send/SendRedirect.js +20 -0
  38. package/dist/v2/send/SendRedirect.js.map +1 -0
  39. package/dist/v2/send/WhenTab.d.ts +4 -0
  40. package/dist/v2/send/WhenTab.js +64 -0
  41. package/dist/v2/send/WhenTab.js.map +1 -0
  42. package/dist/v2/send/sendModel.d.ts +47 -0
  43. package/dist/v2/send/sendModel.js +90 -0
  44. package/dist/v2/send/sendModel.js.map +1 -0
  45. package/dist/v2/send/useSendDraft.d.ts +24 -0
  46. package/dist/v2/send/useSendDraft.js +120 -0
  47. package/dist/v2/send/useSendDraft.js.map +1 -0
  48. package/package.json +1 -1
@@ -0,0 +1,90 @@
1
+ import { toStored as e, usedDetailNames as t } from "../admin/templateText.js";
2
+ // src/v2/send/sendModel.ts
3
+ var n = "send", r = [
4
+ "IN_APP",
5
+ "EMAIL",
6
+ "PUSH"
7
+ ];
8
+ function i(e) {
9
+ return r.some((t) => t === e);
10
+ }
11
+ function a(n, r, i) {
12
+ let a = new Set(t(`${e(n, i)}\n${e(r, i)}`));
13
+ return i.filter((e) => a.has(e.name));
14
+ }
15
+ function o(t, n, r) {
16
+ let i = new Set(n.map((e) => e.name));
17
+ return e(t, n).replace(/\{\{\s*([A-Za-z_][\w.]*)\s*\}\}/g, (e, t) => i.has(t) ? (r[t] ?? "").trim() : e);
18
+ }
19
+ function s(e, t) {
20
+ return e === "IN_APP" ? { userId: t.id } : {
21
+ userId: t.id,
22
+ email: t.email
23
+ };
24
+ }
25
+ function c(e) {
26
+ let t = o(e.title, e.details, e.values).trim(), n = o(e.message, e.details, e.values).trim();
27
+ return e.people.flatMap((r) => e.channels.map((i) => ({
28
+ channel: i,
29
+ recipient: s(i, r),
30
+ subject: t,
31
+ body: n,
32
+ type: e.kind,
33
+ priority: "MEDIUM",
34
+ ...e.topicId ? { topicId: e.topicId } : {}
35
+ })));
36
+ }
37
+ function l(e, t) {
38
+ if (!e || !t) return null;
39
+ let n = /* @__PURE__ */ new Date(`${e}T${t}:00`);
40
+ return Number.isNaN(n.getTime()) ? null : n;
41
+ }
42
+ function u(e) {
43
+ return e.title.trim() ? e.message.trim() ? a(e.title, e.message, e.details).some((t) => !(e.values[t.name] ?? "").trim()) ? {
44
+ tab: "message",
45
+ key: "notifications.v3.send.needDetails",
46
+ fallback: "Fill in every detail in brackets."
47
+ } : e.channels.length === 0 ? {
48
+ tab: "message",
49
+ key: "notifications.v3.send.needChannel",
50
+ fallback: "Pick at least one way to send it."
51
+ } : null : {
52
+ tab: "message",
53
+ key: "notifications.v3.send.needMessage",
54
+ fallback: "Write the message."
55
+ } : {
56
+ tab: "message",
57
+ key: "notifications.v3.send.needTitle",
58
+ fallback: "Add a title."
59
+ };
60
+ }
61
+ function d(e) {
62
+ return e.people.length === 0 ? {
63
+ tab: "people",
64
+ key: "notifications.v3.send.needPeople",
65
+ fallback: "Choose who gets it."
66
+ } : e.kind === "MARKETING" && !e.topicId ? {
67
+ tab: "people",
68
+ key: "notifications.v3.send.needTopic",
69
+ fallback: "Marketing messages need a topic, so people can turn them off."
70
+ } : null;
71
+ }
72
+ function f(e, t) {
73
+ if (!e.later) return null;
74
+ let n = l(e.date, e.time);
75
+ return n ? n.getTime() <= t.getTime() ? {
76
+ tab: "when",
77
+ key: "notifications.v3.send.needFuture",
78
+ fallback: "Pick a time that hasn’t passed."
79
+ } : null : {
80
+ tab: "when",
81
+ key: "notifications.v3.send.needWhen",
82
+ fallback: "Pick a day and a time."
83
+ };
84
+ }
85
+ function p(e, t) {
86
+ return u(e) ?? d(e) ?? f(e, t);
87
+ }
88
+ export { r as SEND_CHANNELS, n as SEND_PARAM, c as buildSendBatch, a as detailsInUse, o as finalText, i as isSendChannel, s as recipientFor, l as scheduledAt, p as sendProblem };
89
+
90
+ //# sourceMappingURL=sendModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendModel.js","names":["SEND_PARAM","SEND_CHANNELS","isSendChannel","channel","value","detailsInUse","used","usedDetailNames","toStored","title","details","message","detail","finalText","known","text","name","values","match","recipientFor","person","buildSendBatch","subject","body","scheduledAt","date","time","at","messageProblem","peopleProblem","whenProblem","now","sendProblem"],"sources":["../../../src/v2/send/sendModel.ts"],"sourcesContent":["/**\n * Send a notification (BOFF-16785, C2b; the mockup's `sendnotif`): what the dialog sends, as plain\n * functions. One message, to the people chosen, by each channel ticked: one notification per\n * person and channel, through today's batch send (`useSendNotification().sendBatch`), now or at a\n * time. Starting from a template copies its words; its details (`[First name]`) get one value each,\n * the same for everyone, as today's template send renders them once for all.\n */\nimport type { CreateNotificationInput, RecipientInput } from '../../hooks/useSendNotification';\nimport { toStored, usedDetailNames, type TemplateDetail } from '../admin/templateText';\nimport type { TemplateKind } from '../admin/words';\n\n/** The inbox's search parameter that opens the dialog (`/notifications?send=1`). */\nexport const SEND_PARAM = 'send';\n\nexport const SEND_CHANNELS = ['IN_APP', 'EMAIL', 'PUSH'] as const;\nexport type SendChannel = (typeof SEND_CHANNELS)[number];\n\nexport function isSendChannel(value: string): value is SendChannel {\n return SEND_CHANNELS.some((channel) => channel === value);\n}\n\nexport type SendTab = 'message' | 'people' | 'when';\n\nexport interface SendPerson {\n id: string;\n name: string;\n email: string;\n}\n\nexport interface SendValues {\n title: string;\n message: string;\n kind: TemplateKind;\n channels: readonly SendChannel[];\n people: readonly SendPerson[];\n topicId: string | null;\n /** The details of the template it started from; none for a blank message. */\n details: readonly TemplateDetail[];\n /** A value per detail name, the same for everyone. */\n values: Readonly<Record<string, string>>;\n later: boolean;\n /** `YYYY-MM-DD` and `HH:mm`, on this device's clock. */\n date: string | null;\n time: string | null;\n}\n\n/** The template's details the title or message still uses, in order. */\nexport function detailsInUse(\n title: string,\n message: string,\n details: readonly TemplateDetail[]\n): TemplateDetail[] {\n const used = new Set(\n usedDetailNames(`${toStored(title, details)}\\n${toStored(message, details)}`)\n );\n return details.filter((detail) => used.has(detail.name));\n}\n\n/** The words as sent: each `[Label]` of a detail replaced by its value. */\nexport function finalText(\n text: string,\n details: readonly TemplateDetail[],\n values: Readonly<Record<string, string>>\n): string {\n const known = new Set(details.map((detail) => detail.name));\n return toStored(text, details).replace(\n /\\{\\{\\s*([A-Za-z_][\\w.]*)\\s*\\}\\}/g,\n (match, name: string) => (known.has(name) ? (values[name] ?? '').trim() : match)\n );\n}\n\n/** Who a channel's notification goes to: the person, and for email their address (as today). */\nexport function recipientFor(channel: SendChannel, person: SendPerson): RecipientInput {\n return channel === 'IN_APP' ? { userId: person.id } : { userId: person.id, email: person.email };\n}\n\n/** One notification per person and channel; the title is each one's subject, as today. */\nexport function buildSendBatch(values: SendValues): CreateNotificationInput[] {\n const subject = finalText(values.title, values.details, values.values).trim();\n const body = finalText(values.message, values.details, values.values).trim();\n return values.people.flatMap((person) =>\n values.channels.map((channel) => ({\n channel,\n recipient: recipientFor(channel, person),\n subject,\n body,\n type: values.kind,\n priority: 'MEDIUM' as const,\n ...(values.topicId ? { topicId: values.topicId } : {}),\n }))\n );\n}\n\n/** The chosen day and time on this device's clock, or null when either is missing. */\nexport function scheduledAt(date: string | null, time: string | null): Date | null {\n if (!date || !time) return null;\n const at = new Date(`${date}T${time}:00`);\n return Number.isNaN(at.getTime()) ? null : at;\n}\n\nexport interface SendProblem {\n tab: SendTab;\n key: string;\n fallback: string;\n}\n\nfunction messageProblem(values: SendValues): SendProblem | null {\n if (!values.title.trim()) {\n return {\n tab: 'message',\n key: 'notifications.v3.send.needTitle',\n fallback: 'Add a title.',\n };\n }\n if (!values.message.trim()) {\n return {\n tab: 'message',\n key: 'notifications.v3.send.needMessage',\n fallback: 'Write the message.',\n };\n }\n const empty = detailsInUse(values.title, values.message, values.details).some(\n (detail) => !(values.values[detail.name] ?? '').trim()\n );\n if (empty) {\n return {\n tab: 'message',\n key: 'notifications.v3.send.needDetails',\n fallback: 'Fill in every detail in brackets.',\n };\n }\n if (values.channels.length === 0) {\n return {\n tab: 'message',\n key: 'notifications.v3.send.needChannel',\n fallback: 'Pick at least one way to send it.',\n };\n }\n return null;\n}\n\nfunction peopleProblem(values: SendValues): SendProblem | null {\n if (values.people.length === 0) {\n return {\n tab: 'people',\n key: 'notifications.v3.send.needPeople',\n fallback: 'Choose who gets it.',\n };\n }\n if (values.kind === 'MARKETING' && !values.topicId) {\n return {\n tab: 'people',\n key: 'notifications.v3.send.needTopic',\n fallback: 'Marketing messages need a topic, so people can turn them off.',\n };\n }\n return null;\n}\n\nfunction whenProblem(values: SendValues, now: Date): SendProblem | null {\n if (!values.later) return null;\n const at = scheduledAt(values.date, values.time);\n if (!at) {\n return {\n tab: 'when',\n key: 'notifications.v3.send.needWhen',\n fallback: 'Pick a day and a time.',\n };\n }\n if (at.getTime() <= now.getTime()) {\n return {\n tab: 'when',\n key: 'notifications.v3.send.needFuture',\n fallback: 'Pick a time that hasn’t passed.',\n };\n }\n return null;\n}\n\n/** The first thing to fix before sending, and the tab it's on; null when it's ready. */\nexport function sendProblem(values: SendValues, now: Date): SendProblem | null {\n return messageProblem(values) ?? peopleProblem(values) ?? whenProblem(values, now);\n}\n"],"mappings":";;AAYA,IAAaA,IAAa,QAEbC,IAAgB;CAAC;CAAU;CAAS;AAAM;AAGvD,SAAgBC,EAAc,GAAqC;CACjE,OAAOD,EAAc,MAAM,MAAYE,MAAYC,CAAK;AAC1D;AA4BA,SAAgBC,EACd,GACA,GACA,GACkB;CAClB,IAAMC,IAAO,IAAI,IACfC,EAAgB,GAAGC,EAASC,GAAOC,CAAO,EAAE,IAAIF,EAASG,GAASD,CAAO,GAAG,CAC9E;CACA,OAAOA,EAAQ,QAAQ,MAAWJ,EAAK,IAAIM,EAAO,IAAI,CAAC;AACzD;AAGA,SAAgBC,EACd,GACA,GACA,GACQ;CACR,IAAMC,IAAQ,IAAI,IAAIJ,EAAQ,KAAK,MAAWE,EAAO,IAAI,CAAC;CAC1D,OA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,UAAU;CACZ,IAEK,OAvBE;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ,IAXO;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ;AA2BJ;AAEA,SAASY,EAAc,GAAwC;CAe7D,OAdIZ,EAAO,OAAO,WAAW,IACpB;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ,IAEEA,EAAO,SAAS,eAAe,CAACA,EAAO,UAClC;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ,IAEK;AACT;AAEA,SAASa,EAAY,GAAoB,GAA+B;CACtE,IAAI,CAACb,EAAO,OAAO,OAAO;CAC1B,IAAMU,IAAKH,EAAYP,EAAO,MAAMA,EAAO,IAAI;CAe/C,OAdKU,IAODA,EAAG,QAAQ,KAAKI,EAAI,QAAQ,IACvB;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ,IAEK,OAbE;EACL,KAAK;EACL,KAAK;EACL,UAAU;CACZ;AAUJ;AAGA,SAAgBC,EAAY,GAAoB,GAA+B;CAC7E,OAAOJ,EAAeX,CAAM,KAAKY,EAAcZ,CAAM,KAAKa,EAAYb,GAAQc,CAAG;AACnF"}
@@ -0,0 +1,24 @@
1
+ import { BackendNotificationTemplate } from '../../hooks/useNotificationTemplates';
2
+ import { SendChannel, SendPerson, SendTab, SendValues } from './sendModel';
3
+ export declare function useSendDraft(onSent: () => void): {
4
+ draft: SendValues;
5
+ templateId: string | null;
6
+ startFrom: (template: BackendNotificationTemplate | null) => void;
7
+ setTitle: import('react').Dispatch<import('react').SetStateAction<string>>;
8
+ setMessage: import('react').Dispatch<import('react').SetStateAction<string>>;
9
+ setKind: import('react').Dispatch<import('react').SetStateAction<"TRANSACTIONAL" | "MARKETING" | "SYSTEM" | "ALERT">>;
10
+ toggleChannel: (channel: SendChannel) => void;
11
+ addPerson: (person: SendPerson) => void;
12
+ removePerson: (id: string) => void;
13
+ setTopicId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
14
+ setValue: (name: string, value: string) => void;
15
+ setLater: import('react').Dispatch<import('react').SetStateAction<boolean>>;
16
+ setDate: import('react').Dispatch<import('react').SetStateAction<string | null>>;
17
+ setTime: import('react').Dispatch<import('react').SetStateAction<string | null>>;
18
+ tab: SendTab;
19
+ setTab: import('react').Dispatch<import('react').SetStateAction<SendTab>>;
20
+ problem: string | null;
21
+ sending: boolean;
22
+ send: () => Promise<void>;
23
+ };
24
+ export type SendDraft = ReturnType<typeof useSendDraft>;
@@ -0,0 +1,120 @@
1
+ import { useSendNotification as e } from "../../hooks/useSendNotification.js";
2
+ import { useNotificationAnalytics as t } from "../../hooks/useNotificationAnalytics.js";
3
+ import { useTr as n } from "../../shared/hooks/useTr.js";
4
+ import { isPermissionError as r } from "../../utils/index.js";
5
+ import { readDetails as i, toReadable as a } from "../admin/templateText.js";
6
+ import { isKind as o } from "../admin/words.js";
7
+ import { buildSendBatch as s, isSendChannel as c, scheduledAt as l, sendProblem as u } from "./sendModel.js";
8
+ import { useState as d } from "react";
9
+ import { usePermissions as f } from "@burdenoff/fe-libs/shared/providers/shell";
10
+ import { useNotify as p, useWhenLabels as m } from "@burdenoff/fe-libs/ui";
11
+ // src/v2/send/useSendDraft.ts
12
+ function h(h) {
13
+ let g = n(), _ = p(), v = m(), { refreshPermissions: y } = f(), { sendBatch: b, isSending: x } = e(), { trackNotificationSent: S } = t(), [C, w] = d(null), [T, E] = d(""), [D, O] = d(""), [k, A] = d("SYSTEM"), [j, M] = d(["IN_APP", "EMAIL"]), [N, P] = d([]), [F, I] = d(null), [L, R] = d([]), [z, B] = d({}), [V, H] = d(!1), [U, ee] = d(null), [W, G] = d(null), [K, q] = d("message"), [J, Y] = d(!1), [X, Z] = d(null), Q = {
14
+ title: T,
15
+ message: D,
16
+ kind: k,
17
+ channels: j,
18
+ people: N,
19
+ topicId: F,
20
+ details: L,
21
+ values: z,
22
+ later: V,
23
+ date: U,
24
+ time: W
25
+ }, $ = J ? u(Q, /* @__PURE__ */ new Date()) : null, te = $ ? g($.key, $.fallback) : X, ne = (e) => {
26
+ if (w(e?.id ?? null), !e) {
27
+ R([]), B({}), E(""), O("");
28
+ return;
29
+ }
30
+ let t = i(e.variables);
31
+ R(t), B(Object.fromEntries(t.map((e) => [e.name, e.defaultValue]))), E(a(e.subject ?? "", t)), O(a(e.bodyTemplate, t)), o(e.type) && A(e.type), c(e.channel) && M([e.channel]);
32
+ }, re = (e) => M((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]), ie = (e) => P((t) => t.some((t) => t.id === e.id) ? t : [...t, e]), ae = (e) => P((t) => t.filter((t) => t.id !== e)), oe = (e, t) => B((n) => ({
33
+ ...n,
34
+ [e]: t
35
+ })), se = (e, t, n) => {
36
+ S({
37
+ mode: C ? "template" : "compose",
38
+ channel: j.find((e) => e !== "IN_APP") ?? "IN_APP",
39
+ type: k,
40
+ priority: "MEDIUM",
41
+ recipientSource: "directory",
42
+ recipientCount: N.length,
43
+ successCount: e,
44
+ failedCount: t,
45
+ scheduled: !!n,
46
+ includeInApp: j.includes("IN_APP"),
47
+ hasActions: !1,
48
+ hasMedia: !1
49
+ });
50
+ }, ce = (e) => {
51
+ r(e) ? (Z(g("notifications.v3.send.noPermission", "You don’t have permission to send this.")), y().catch(() => void 0)) : Z(e instanceof Error && e.message ? g("notifications.v3.send.failedWhy", "Couldn’t send it: {{reason}}", { reason: e.message }) : g("notifications.v3.send.failed", "Couldn’t send it. Try again."));
52
+ }, le = async () => {
53
+ Y(!0), Z(null);
54
+ let e = u(Q, /* @__PURE__ */ new Date());
55
+ if (e) {
56
+ q(e.tab);
57
+ return;
58
+ }
59
+ let t = V ? l(U, W) : null;
60
+ try {
61
+ let e = await b({
62
+ notifications: s(Q),
63
+ ...t ? {
64
+ scheduledFor: t.toISOString(),
65
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
66
+ } : {}
67
+ });
68
+ if (!e) {
69
+ Z(g("notifications.v3.send.failed", "Couldn’t send it. Try again."));
70
+ return;
71
+ }
72
+ if (!t && e.totalTriggered === 0 && e.totalFailed > 0) {
73
+ Z(g("notifications.v3.send.noneSent", "None of them could be sent. The Delivery log says why."));
74
+ return;
75
+ }
76
+ se(e.totalTriggered, e.totalFailed, t), _(ue(e.totalTriggered, e.totalRequested, t)), h();
77
+ } catch (e) {
78
+ ce(e);
79
+ }
80
+ }, ue = (e, t, n) => n ? {
81
+ title: g("notifications.v3.send.scheduled", "Scheduled for {{day}} at {{time}}", {
82
+ day: v.day(n),
83
+ time: v.time(n)
84
+ }),
85
+ tone: "success"
86
+ } : e < t ? {
87
+ title: g("notifications.v3.send.someSent", "Sent {{sent}} of {{total}}. The Delivery log says why the rest didn’t go.", {
88
+ sent: e,
89
+ total: t
90
+ }),
91
+ tone: "warning"
92
+ } : {
93
+ title: N.length === 1 ? g("notifications.v3.send.sentOne", "Sent to {{name}}", { name: N[0].name }) : g("notifications.v3.send.sentMany", "Sent to {{count}} people", { count: N.length }),
94
+ tone: "success"
95
+ };
96
+ return {
97
+ draft: Q,
98
+ templateId: C,
99
+ startFrom: ne,
100
+ setTitle: E,
101
+ setMessage: O,
102
+ setKind: A,
103
+ toggleChannel: re,
104
+ addPerson: ie,
105
+ removePerson: ae,
106
+ setTopicId: I,
107
+ setValue: oe,
108
+ setLater: H,
109
+ setDate: ee,
110
+ setTime: G,
111
+ tab: K,
112
+ setTab: q,
113
+ problem: te,
114
+ sending: x,
115
+ send: le
116
+ };
117
+ }
118
+ export { h as useSendDraft };
119
+
120
+ //# sourceMappingURL=useSendDraft.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSendDraft.js","names":["useSendDraft","tr","useTr","notify","useNotify","when","useWhenLabels","usePermissions","useSendNotification","useNotificationAnalytics","templateId","setTemplateId","useState","title","setTitle","message","setMessage","kind","setKind","channels","setChannels","people","setPeople","topicId","setTopicId","details","setDetails","values","setValues","later","setLater","date","setDate","time","setTime","tab","setTab","attempted","setAttempted","failure","setFailure","draft","missing","sendProblem","problem","startFrom","template","next","readDetails","detail","toReadable","isKind","isSendChannel","toggleChannel","current","channel","one","addPerson","person","removePerson","id","setValue","name","value","reportSent","triggered","failed","at","isPermissionError","error","refreshPermissions","send","issue","scheduledAt","result","sendBatch","buildSendBatch","sentToast","onSent","requested","isSending"],"sources":["../../../src/v2/send/useSendDraft.ts"],"sourcesContent":["/**\n * The send dialog's draft (BOFF-16785, C2b): the message, who gets it and when, and Send through\n * today's batch send (`useSendNotification().sendBatch`). Nothing is sent until Send; the first\n * thing to fix opens its tab instead.\n */\nimport { useState } from 'react';\nimport { useNotify, useWhenLabels } from '@burdenoff/fe-libs/ui';\nimport { usePermissions } from '@burdenoff/fe-libs/shared/providers/shell';\nimport { useSendNotification } from '../../hooks/useSendNotification';\nimport { useNotificationAnalytics } from '../../hooks/useNotificationAnalytics';\nimport type { BackendNotificationTemplate } from '../../hooks/useNotificationTemplates';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { isPermissionError } from '../../utils';\nimport { readDetails, toReadable, type TemplateDetail } from '../admin/templateText';\nimport { isKind, type TemplateKind } from '../admin/words';\nimport {\n buildSendBatch,\n isSendChannel,\n scheduledAt,\n sendProblem,\n type SendChannel,\n type SendPerson,\n type SendTab,\n type SendValues,\n} from './sendModel';\n\nexport function useSendDraft(onSent: () => void) {\n const tr = useTr();\n const notify = useNotify();\n const when = useWhenLabels();\n const { refreshPermissions } = usePermissions();\n const { sendBatch, isSending } = useSendNotification();\n const { trackNotificationSent } = useNotificationAnalytics();\n const [templateId, setTemplateId] = useState<string | null>(null);\n const [title, setTitle] = useState('');\n const [message, setMessage] = useState('');\n const [kind, setKind] = useState<TemplateKind>('SYSTEM');\n const [channels, setChannels] = useState<SendChannel[]>(['IN_APP', 'EMAIL']);\n const [people, setPeople] = useState<SendPerson[]>([]);\n const [topicId, setTopicId] = useState<string | null>(null);\n const [details, setDetails] = useState<TemplateDetail[]>([]);\n const [values, setValues] = useState<Record<string, string>>({});\n const [later, setLater] = useState(false);\n const [date, setDate] = useState<string | null>(null);\n const [time, setTime] = useState<string | null>(null);\n const [tab, setTab] = useState<SendTab>('message');\n // After a first Send, what's still missing shows (and updates) until it's fixed.\n const [attempted, setAttempted] = useState(false);\n const [failure, setFailure] = useState<string | null>(null);\n\n const draft: SendValues = {\n title,\n message,\n kind,\n channels,\n people,\n topicId,\n details,\n values,\n later,\n date,\n time,\n };\n\n const missing = attempted ? sendProblem(draft, new Date()) : null;\n const problem = missing ? tr(missing.key, missing.fallback) : failure;\n\n /** Start from a template's words, or from a blank message (null). */\n const startFrom = (template: BackendNotificationTemplate | null) => {\n setTemplateId(template?.id ?? null);\n if (!template) {\n setDetails([]);\n setValues({});\n setTitle('');\n setMessage('');\n return;\n }\n const next = readDetails(template.variables);\n setDetails(next);\n setValues(Object.fromEntries(next.map((detail) => [detail.name, detail.defaultValue])));\n setTitle(toReadable(template.subject ?? '', next));\n setMessage(toReadable(template.bodyTemplate, next));\n if (isKind(template.type)) setKind(template.type);\n if (isSendChannel(template.channel)) setChannels([template.channel]);\n };\n\n const toggleChannel = (channel: SendChannel) =>\n setChannels((current) =>\n current.includes(channel) ? current.filter((one) => one !== channel) : [...current, channel]\n );\n\n const addPerson = (person: SendPerson) =>\n setPeople((current) =>\n current.some((one) => one.id === person.id) ? current : [...current, person]\n );\n const removePerson = (id: string) =>\n setPeople((current) => current.filter((one) => one.id !== id));\n\n const setValue = (name: string, value: string) =>\n setValues((current) => ({ ...current, [name]: value }));\n\n const reportSent = (triggered: number, failed: number, at: Date | null) => {\n trackNotificationSent({\n mode: templateId ? 'template' : 'compose',\n channel: channels.find((one) => one !== 'IN_APP') ?? 'IN_APP',\n type: kind,\n priority: 'MEDIUM',\n recipientSource: 'directory',\n recipientCount: people.length,\n successCount: triggered,\n failedCount: failed,\n scheduled: Boolean(at),\n includeInApp: channels.includes('IN_APP'),\n hasActions: false,\n hasMedia: false,\n });\n };\n\n const failed = (error: unknown) => {\n if (isPermissionError(error)) {\n setFailure(\n tr('notifications.v3.send.noPermission', 'You don’t have permission to send this.')\n );\n void refreshPermissions().catch(() => undefined);\n return;\n }\n setFailure(\n error instanceof Error && error.message\n ? tr('notifications.v3.send.failedWhy', 'Couldn’t send it: {{reason}}', {\n reason: error.message,\n })\n : tr('notifications.v3.send.failed', 'Couldn’t send it. Try again.')\n );\n };\n\n const send = async () => {\n setAttempted(true);\n setFailure(null);\n const issue = sendProblem(draft, new Date());\n if (issue) {\n setTab(issue.tab);\n return;\n }\n const at = later ? scheduledAt(date, time) : null;\n try {\n const result = await sendBatch({\n notifications: buildSendBatch(draft),\n ...(at\n ? {\n scheduledFor: at.toISOString(),\n timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n }\n : {}),\n });\n if (!result) {\n setFailure(tr('notifications.v3.send.failed', 'Couldn’t send it. Try again.'));\n return;\n }\n if (!at && result.totalTriggered === 0 && result.totalFailed > 0) {\n setFailure(\n tr(\n 'notifications.v3.send.noneSent',\n 'None of them could be sent. The Delivery log says why.'\n )\n );\n return;\n }\n reportSent(result.totalTriggered, result.totalFailed, at);\n notify(sentToast(result.totalTriggered, result.totalRequested, at));\n onSent();\n } catch (error) {\n failed(error);\n }\n };\n\n const sentToast = (triggered: number, requested: number, at: Date | null) => {\n if (at) {\n return {\n title: tr('notifications.v3.send.scheduled', 'Scheduled for {{day}} at {{time}}', {\n day: when.day(at),\n time: when.time(at),\n }),\n tone: 'success' as const,\n };\n }\n if (triggered < requested) {\n return {\n title: tr(\n 'notifications.v3.send.someSent',\n 'Sent {{sent}} of {{total}}. The Delivery log says why the rest didn’t go.',\n { sent: triggered, total: requested }\n ),\n tone: 'warning' as const,\n };\n }\n return {\n title:\n people.length === 1\n ? tr('notifications.v3.send.sentOne', 'Sent to {{name}}', { name: people[0].name })\n : tr('notifications.v3.send.sentMany', 'Sent to {{count}} people', {\n count: people.length,\n }),\n tone: 'success' as const,\n };\n };\n\n return {\n draft,\n templateId,\n startFrom,\n setTitle,\n setMessage,\n setKind,\n toggleChannel,\n addPerson,\n removePerson,\n setTopicId,\n setValue,\n setLater,\n setDate,\n setTime,\n tab,\n setTab,\n problem,\n sending: isSending,\n send,\n };\n}\n\nexport type SendDraft = ReturnType<typeof useSendDraft>;\n"],"mappings":";;;;;;;;;;;AA0BA,SAAgBA,EAAa,GAAoB;CAC/C,IAAMC,IAAKC,EAAM,GACXC,IAASC,EAAU,GACnBC,IAAOC,EAAc,GACrB,EAAE,0BAAuBC,EAAe,GACxC,EAAE,cAAW,iBAAcC,EAAoB,GAC/C,EAAE,6BAA0BC,EAAyB,GACrD,CAACC,GAAYC,KAAiBC,EAAwB,IAAI,GAC1D,CAACC,GAAOC,KAAYF,EAAS,EAAE,GAC/B,CAACG,GAASC,KAAcJ,EAAS,EAAE,GACnC,CAACK,GAAMC,KAAWN,EAAuB,QAAQ,GACjD,CAACO,GAAUC,KAAeR,EAAwB,CAAC,UAAU,OAAO,CAAC,GACrE,CAACS,GAAQC,KAAaV,EAAuB,CAAC,CAAC,GAC/C,CAACW,GAASC,KAAcZ,EAAwB,IAAI,GACpD,CAACa,GAASC,KAAcd,EAA2B,CAAC,CAAC,GACrD,CAACe,GAAQC,KAAahB,EAAiC,CAAC,CAAC,GACzD,CAACiB,GAAOC,KAAYlB,EAAS,EAAK,GAClC,CAACmB,GAAMC,MAAWpB,EAAwB,IAAI,GAC9C,CAACqB,GAAMC,KAAWtB,EAAwB,IAAI,GAC9C,CAACuB,GAAKC,KAAUxB,EAAkB,SAAS,GAE3C,CAACyB,GAAWC,KAAgB1B,EAAS,EAAK,GAC1C,CAAC2B,GAASC,KAAc5B,EAAwB,IAAI,GAEpD6B,IAAoB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,GAEMC,IAAUL,IAAYM,EAAYF,mBAAO,IAAI,KAAK,CAAC,IAAI,MACvDG,KAAUF,IAAUzC,EAAGyC,EAAQ,KAAKA,EAAQ,QAAQ,IAAIH,GAGxDM,MAAa,MAAiD;EAElE,IADAlC,EAAcmC,GAAU,MAAM,IAAI,GAC9B,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,KAAK8D,CAAE;EACpB,CAAC;EACD,MAAM;CACR,IAEEF,IAAYc,IACP;EACL,OAAO9E,EACL,kCACA,6EACA;GAAE,MAAMgE;GAAW,OAAOc;EAAU,CACtC;EACA,MAAM;CACR,IAEK;EACL,OACE1D,EAAO,WAAW,IACdpB,EAAG,iCAAiC,oBAAoB,EAAE,MAAMoB,EAAO,EAAE,CAAC,KAAK,CAAC,IAChFpB,EAAG,kCAAkC,4BAA4B,EAC/D,OAAOoB,EAAO,OAChB,CAAC;EACP,MAAM;CACR;CAGF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,SAAS2D;EACT;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-notification",
3
- "version": "2026.1129.2",
3
+ "version": "2026.1130.1",
4
4
  "description": "Notification microfrontend for multi-channel notification management",
5
5
  "type": "module",
6
6
  "imports": {