@burdenoff/microfe-notification 2026.1202.1 → 2026.1203.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.
@@ -1,117 +1,118 @@
1
1
  import { useNotificationTemplates as e } from "../../hooks/useNotificationTemplates.js";
2
2
  import { useTr as t } from "../../shared/hooks/useTr.js";
3
- import { useNotificationPaths as n } from "../../navigation-v2/paths.js";
4
- import { detailLabel as r, readDetails as i, templateSlug as a, toReadable as o, toStored as s, writeDetails as c } from "./templateText.js";
5
- import { isChannel as l, isKind as u } from "./words.js";
6
- import { useMemo as d, useRef as f, useState as p } from "react";
7
- import { useNavigate as m } from "react-router";
8
- import { useConfirm as h, useNotify as g } from "@burdenoff/fe-libs/ui";
3
+ import { useConnectionGate as n } from "../useNeedsConnection.js";
4
+ import { useNotificationPaths as r } from "../../navigation-v2/paths.js";
5
+ import { detailLabel as i, readDetails as a, templateSlug as o, toReadable as s, toStored as c, writeDetails as l } from "./templateText.js";
6
+ import { isChannel as u, isKind as d } from "./words.js";
7
+ import { useMemo as f, useRef as p, useState as m } from "react";
8
+ import { useNavigate as h } from "react-router";
9
+ import { useConfirm as g, useNotify as _ } from "@burdenoff/fe-libs/ui";
9
10
  // src/v2/admin/useTemplateDraft.ts
10
- function _(_, v, y, b) {
11
- let x = t(), S = m(), C = g(), w = h(), T = n(), E = e(), [D, O] = p(() => i(_?.variables)), [k, A] = p(_?.name ?? ""), [j, M] = p(_ && u(_.type) ? _.type : "TRANSACTIONAL"), [N, P] = p(_ && l(_.channel) ? _.channel : "IN_APP"), [F, I] = p(() => o(_?.subject ?? "", D)), [L, R] = p(() => o(_?.bodyTemplate ?? "", D)), [z, B] = p(null), V = f("message"), H = d(() => ({
12
- title: s(F, D),
13
- message: s(L, D)
11
+ function v(v, y, b, x) {
12
+ let S = t(), C = h(), w = _(), T = g(), E = n(), D = r(), O = e(), [k, A] = m(() => a(v?.variables)), [j, M] = m(v?.name ?? ""), [N, P] = m(v && d(v.type) ? v.type : "TRANSACTIONAL"), [F, I] = m(v && u(v.channel) ? v.channel : "IN_APP"), [L, R] = m(() => s(v?.subject ?? "", k)), [z, B] = m(() => s(v?.bodyTemplate ?? "", k)), [V, H] = m(null), U = p("message"), W = f(() => ({
13
+ title: c(L, k),
14
+ message: c(z, k)
14
15
  }), [
15
- D,
16
- L,
17
- F
18
- ]), U = E.isCreating || E.isUpdating, W = k.trim().length > 1 && L.trim().length > 0, G = (e) => {
19
- D.some((t) => t.name === e.name) || O([...D, e]);
20
- let t = V.current, n = t === "title" ? v.current : y.current, i = `[${r(e.name)}]`, a = t === "title" ? F : L, o = n?.selectionStart ?? a.length, s = n?.selectionEnd ?? a.length, c = a.slice(0, o) + i + a.slice(s);
21
- t === "title" ? I(c) : R(c), requestAnimationFrame(() => {
22
- n?.focus(), n?.setSelectionRange(o + i.length, o + i.length);
16
+ k,
17
+ z,
18
+ L
19
+ ]), G = O.isCreating || O.isUpdating, K = j.trim().length > 1 && z.trim().length > 0, q = (e) => {
20
+ k.some((t) => t.name === e.name) || A([...k, e]);
21
+ let t = U.current, n = t === "title" ? y.current : b.current, r = `[${i(e.name)}]`, a = t === "title" ? L : z, o = n?.selectionStart ?? a.length, s = n?.selectionEnd ?? a.length, c = a.slice(0, o) + r + a.slice(s);
22
+ t === "title" ? R(c) : B(c), requestAnimationFrame(() => {
23
+ n?.focus(), n?.setSelectionRange(o + r.length, o + r.length);
23
24
  });
24
25
  };
25
26
  return {
26
- details: D,
27
- name: k,
28
- setName: A,
29
- kind: j,
30
- setKind: M,
31
- channel: N,
32
- setChannel: P,
33
- title: F,
34
- setTitle: I,
35
- message: L,
36
- setMessage: R,
37
- problem: z,
27
+ details: k,
28
+ name: j,
29
+ setName: M,
30
+ kind: N,
31
+ setKind: P,
32
+ channel: F,
33
+ setChannel: I,
34
+ title: L,
35
+ setTitle: R,
36
+ message: z,
37
+ setMessage: B,
38
+ problem: V,
38
39
  rememberField: (e) => {
39
- V.current = e;
40
+ U.current = e;
40
41
  },
41
- stored: H,
42
- saving: U,
43
- ready: W,
42
+ stored: W,
43
+ saving: G,
44
+ ready: K,
44
45
  insertInto: (e, t) => {
45
- V.current = e, G(t);
46
+ U.current = e, q(t);
46
47
  },
47
48
  save: async () => {
48
- B(null);
49
- let e = c(D);
49
+ H(null);
50
+ let e = l(k);
50
51
  try {
51
- if (_) {
52
- await E.updateTemplate(_.id, {
53
- name: k.trim(),
54
- subject: H.title.trim() || void 0,
55
- bodyTemplate: H.message,
52
+ if (v) {
53
+ await O.updateTemplate(v.id, {
54
+ name: j.trim(),
55
+ subject: W.title.trim() || void 0,
56
+ bodyTemplate: W.message,
56
57
  variables: e
57
- }), C({
58
- title: x("notifications.v3.template.saved", "Saved. It’s used from the next message."),
58
+ }), w({
59
+ title: S("notifications.v3.template.saved", "Saved. It’s used from the next message."),
59
60
  tone: "success"
60
61
  });
61
62
  return;
62
63
  }
63
- let t = a(k), n = await E.createTemplate({
64
+ let t = o(j), n = await O.createTemplate({
64
65
  slug: t,
65
- name: k.trim(),
66
- type: j,
67
- channel: N,
66
+ name: j.trim(),
67
+ type: N,
68
+ channel: F,
68
69
  locale: "en",
69
- subject: H.title.trim() || void 0,
70
- bodyTemplate: H.message,
70
+ subject: W.title.trim() || void 0,
71
+ bodyTemplate: W.message,
71
72
  variables: e
72
73
  });
73
- C({
74
- title: x("notifications.v3.template.created", "{{name}} is ready to send", { name: n.name }),
74
+ w({
75
+ title: S("notifications.v3.template.created", "{{name}} is ready to send", { name: n.name }),
75
76
  tone: "success"
76
- }), S(T.template(n.slug), { replace: !0 });
77
+ }), C(D.template(n.slug), { replace: !0 });
77
78
  } catch (e) {
78
- B(e instanceof Error && e.message ? e.message : x("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."));
79
+ H(e instanceof Error && e.message ? e.message : S("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."));
79
80
  }
80
81
  },
81
82
  remove: async () => {
82
- if (_ && await w({
83
- title: x("notifications.v3.templates.deleteTitle", "Delete {{name}}?", { name: _.name }),
84
- description: x("notifications.v3.templates.deleteBody", "Anything that sends this template stops sending it. Messages already sent stay as they are."),
85
- confirmLabel: x("notifications.v3.templates.delete", "Delete"),
83
+ if (v && await T({
84
+ title: S("notifications.v3.templates.deleteTitle", "Delete {{name}}?", { name: v.name }),
85
+ description: S("notifications.v3.templates.deleteBody", "Anything that sends this template stops sending it. Messages already sent stay as they are."),
86
+ confirmLabel: S("notifications.v3.templates.delete", "Delete"),
86
87
  tone: "danger",
87
- typeToConfirm: _.name
88
- })) try {
89
- await E.deleteTemplate(_.id), C({
90
- title: x("notifications.v3.templates.deleted", "Deleted {{name}}", { name: _.name }),
88
+ typeToConfirm: v.name
89
+ }) && !E()) try {
90
+ await O.deleteTemplate(v.id), w({
91
+ title: S("notifications.v3.templates.deleted", "Deleted {{name}}", { name: v.name }),
91
92
  tone: "success"
92
- }), S(T.templates, { replace: !0 });
93
+ }), C(D.templates, { replace: !0 });
93
94
  } catch {
94
- C({
95
- title: x("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
95
+ w({
96
+ title: S("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
96
97
  tone: "error"
97
98
  });
98
99
  }
99
100
  },
100
101
  toggle: async () => {
101
- if (_) try {
102
- await E.updateTemplate(_.id, { enabled: !_.enabled }), C({
103
- title: _.enabled ? x("notifications.v3.templates.turnedOff", "{{name}} is off", { name: _.name }) : x("notifications.v3.templates.turnedOn", "{{name}} is on", { name: _.name }),
102
+ if (v) try {
103
+ await O.updateTemplate(v.id, { enabled: !v.enabled }), w({
104
+ title: v.enabled ? S("notifications.v3.templates.turnedOff", "{{name}} is off", { name: v.name }) : S("notifications.v3.templates.turnedOn", "{{name}} is on", { name: v.name }),
104
105
  tone: "success"
105
- }), b?.();
106
+ }), x?.();
106
107
  } catch {
107
- C({
108
- title: x("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
108
+ w({
109
+ title: S("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
109
110
  tone: "error"
110
111
  });
111
112
  }
112
113
  }
113
114
  };
114
115
  }
115
- export { _ as useTemplateDraft };
116
+ export { v as useTemplateDraft };
116
117
 
117
118
  //# sourceMappingURL=useTemplateDraft.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTemplateDraft.js","names":["useTemplateDraft","tr","useTr","navigate","useNavigate","notify","useNotify","confirm","useConfirm","paths","useNotificationPaths","templates","useNotificationTemplates","details","setDetails","useState","readDetails","template","name","setName","kind","setKind","isKind","channel","setChannel","isChannel","title","setTitle","toReadable","message","setMessage","problem","setProblem","lastField","useRef","stored","useMemo","toStored","saving","ready","insert","known","detail","field","element","titleRef","messageRef","token","detailLabel","value","start","end","next","variables","writeDetails","slug","templateSlug","created","failure","onChanged"],"sources":["../../../src/v2/admin/useTemplateDraft.ts"],"sourcesContent":["/**\n * A template being edited (BOFF-16785, C2): its fields as people read them, Insert, and Save,\n * Turn off or on and Delete with today's hook (`useNotificationTemplates`). Saving stores today's\n * text (`{{firstName}}`) and the details as today's `variables`.\n */\nimport { useMemo, useRef, useState, type RefObject } from 'react';\nimport { useNavigate } from 'react-router';\nimport { useConfirm, useNotify } 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 {\n detailLabel,\n readDetails,\n templateSlug,\n toReadable,\n toStored,\n writeDetails,\n type TemplateDetail,\n} from './templateText';\nimport { isChannel, isKind, type TemplateChannel, type TemplateKind } from './words';\n\nexport type DraftField = 'title' | 'message';\n\nexport function useTemplateDraft(\n template: BackendNotificationTemplate | null,\n /** The title and message boxes, so Insert can put a detail at the cursor. */\n titleRef: RefObject<HTMLInputElement | null>,\n messageRef: RefObject<HTMLTextAreaElement | null>,\n onChanged?: () => void\n) {\n const tr = useTr();\n const navigate = useNavigate();\n const notify = useNotify();\n const confirm = useConfirm();\n const paths = useNotificationPaths();\n const templates = useNotificationTemplates();\n const [details, setDetails] = useState<TemplateDetail[]>(() => readDetails(template?.variables));\n const [name, setName] = useState(template?.name ?? '');\n const [kind, setKind] = useState<TemplateKind>(\n template && isKind(template.type) ? template.type : 'TRANSACTIONAL'\n );\n const [channel, setChannel] = useState<TemplateChannel>(\n template && isChannel(template.channel) ? template.channel : 'IN_APP'\n );\n const [title, setTitle] = useState(() => toReadable(template?.subject ?? '', details));\n const [message, setMessage] = useState(() => toReadable(template?.bodyTemplate ?? '', details));\n const [problem, setProblem] = useState<string | null>(null);\n const lastField = useRef<DraftField>('message');\n const stored = useMemo(\n () => ({ title: toStored(title, details), message: toStored(message, details) }),\n [details, message, title]\n );\n const saving = templates.isCreating || templates.isUpdating;\n const ready = name.trim().length > 1 && message.trim().length > 0;\n\n const insert = (detail: TemplateDetail) => {\n if (!details.some((known) => known.name === detail.name)) setDetails([...details, detail]);\n const field = lastField.current;\n const element = field === 'title' ? titleRef.current : messageRef.current;\n const token = `[${detailLabel(detail.name)}]`;\n const value = field === 'title' ? title : message;\n const start = element?.selectionStart ?? value.length;\n const end = element?.selectionEnd ?? value.length;\n const next = value.slice(0, start) + token + value.slice(end);\n if (field === 'title') setTitle(next);\n else setMessage(next);\n requestAnimationFrame(() => {\n element?.focus();\n element?.setSelectionRange(start + token.length, start + token.length);\n });\n };\n\n const save = async () => {\n setProblem(null);\n const variables = writeDetails(details);\n try {\n if (template) {\n await templates.updateTemplate(template.id, {\n name: name.trim(),\n subject: stored.title.trim() || undefined,\n bodyTemplate: stored.message,\n variables,\n });\n notify({\n title: tr('notifications.v3.template.saved', 'Saved. It’s used from the next message.'),\n tone: 'success',\n });\n return;\n }\n const slug = templateSlug(name);\n const created = await templates.createTemplate({\n slug,\n name: name.trim(),\n type: kind,\n channel,\n locale: 'en',\n subject: stored.title.trim() || undefined,\n bodyTemplate: stored.message,\n variables,\n });\n notify({\n title: tr('notifications.v3.template.created', '{{name}} is ready to send', {\n name: created.name,\n }),\n tone: 'success',\n });\n navigate(paths.template(created.slug), { replace: true });\n } catch (failure) {\n setProblem(\n failure instanceof Error && failure.message\n ? failure.message\n : tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.')\n );\n }\n };\n\n const remove = async () => {\n if (!template) return;\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 navigate(paths.templates, { replace: true });\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 /** Remember which box Insert should write into. */\n const rememberField = (field: DraftField) => {\n lastField.current = field;\n };\n\n /** Put a detail where the cursor was in the title or the message. */\n const insertInto = (field: DraftField, detail: TemplateDetail) => {\n lastField.current = field;\n insert(detail);\n };\n\n const toggle = async () => {\n if (!template) return;\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 onChanged?.();\n } catch {\n notify({\n title: tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.'),\n tone: 'error',\n });\n }\n };\n\n return {\n details,\n name,\n setName,\n kind,\n setKind,\n channel,\n setChannel,\n title,\n setTitle,\n message,\n setMessage,\n problem,\n rememberField,\n stored,\n saving,\n ready,\n insertInto,\n save,\n remove,\n toggle,\n };\n}\n\nexport type TemplateD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M,SAASgD,EAAQ,IAAI,GAAG,EAAE,SAAS,GAAK,CAAC;GAC1D,SAASC,GAAS;IAChB,EACEA,aAAmB,SAASA,EAAQ,UAChCA,EAAQ,UACRzD,EAAG,yCAAyC,2BAA2B,CAC7E;GACF;EACF;EAmFE,oBAjFyB;GACzB,IAAKgB,KAaA,MAZaV,EAAQ;IACxB,OAAON,EAAG,0CAA0C,oBAAoB,EACtE,MAAMgB,EAAS,KACjB,CAAC;IACD,aAAahB,EACX,yCACA,6FACF;IACA,cAAcA,EAAG,qCAAqC,QAAQ;IAC9D,MAAM;IACN,eAAegB,EAAS;GAC1B,CAAC,GAED,IAAI;IAQF,AAPA,MAAMN,EAAU,eAAeM,EAAS,EAAE,GAC1CZ,EAAO;KACL,OAAOJ,EAAG,sCAAsC,oBAAoB,EAClE,MAAMgB,EAAS,KACjB,CAAC;KACD,MAAM;IACR,CAAC,GACDd,EAASM,EAAM,WAAW,EAAE,SAAS,GAAK,CAAC;GAC7C,QAAQ;IACN,EAAO;KACL,OAAOR,EAAG,2CAA2C,gCAAgC;KACrF,MAAM;IACR,CAAC;GACH;EACF;EAoDE,oBAvCyB;GACzB,IAAKgB,GACL,IAAI;IAQF,AAPA,MAAMN,EAAU,eAAeM,EAAS,IAAI,EAAE,SAAS,CAACA,EAAS,QAAQ,CAAC,GAC1EZ,EAAO;KACL,OAAOY,EAAS,UACZhB,EAAG,wCAAwC,mBAAmB,EAAE,MAAMgB,EAAS,KAAK,CAAC,IACrFhB,EAAG,uCAAuC,kBAAkB,EAAE,MAAMgB,EAAS,KAAK,CAAC;KACvF,MAAM;IACR,CAAC,GACD0C,IAAY;GACd,QAAQ;IACN,EAAO;KACL,OAAO1D,EAAG,yCAAyC,2BAA2B;KAC9E,MAAM;IACR,CAAC;GACH;EACF;CAuBA;AACF"}
1
+ {"version":3,"file":"useTemplateDraft.js","names":["useTemplateDraft","tr","useTr","navigate","useNavigate","notify","useNotify","confirm","useConfirm","gate","useConnectionGate","paths","useNotificationPaths","templates","useNotificationTemplates","details","setDetails","useState","readDetails","template","name","setName","kind","setKind","isKind","channel","setChannel","isChannel","title","setTitle","toReadable","message","setMessage","problem","setProblem","lastField","useRef","stored","useMemo","toStored","saving","ready","insert","known","detail","field","element","titleRef","messageRef","token","detailLabel","value","start","end","next","variables","writeDetails","slug","templateSlug","created","failure","onChanged"],"sources":["../../../src/v2/admin/useTemplateDraft.ts"],"sourcesContent":["/**\n * A template being edited (BOFF-16785, C2): its fields as people read them, Insert, and Save,\n * Turn off or on and Delete with today's hook (`useNotificationTemplates`). Saving stores today's\n * text (`{{firstName}}`) and the details as today's `variables`.\n */\nimport { useMemo, useRef, useState, type RefObject } from 'react';\nimport { useNavigate } from 'react-router';\nimport { useConfirm, useNotify } from '@burdenoff/fe-libs/ui';\nimport {\n useNotificationTemplates,\n type BackendNotificationTemplate,\n} from '../../hooks/useNotificationTemplates';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useConnectionGate } from '../useNeedsConnection';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport {\n detailLabel,\n readDetails,\n templateSlug,\n toReadable,\n toStored,\n writeDetails,\n type TemplateDetail,\n} from './templateText';\nimport { isChannel, isKind, type TemplateChannel, type TemplateKind } from './words';\n\nexport type DraftField = 'title' | 'message';\n\nexport function useTemplateDraft(\n template: BackendNotificationTemplate | null,\n /** The title and message boxes, so Insert can put a detail at the cursor. */\n titleRef: RefObject<HTMLInputElement | null>,\n messageRef: RefObject<HTMLTextAreaElement | null>,\n onChanged?: () => void\n) {\n const tr = useTr();\n const navigate = useNavigate();\n const notify = useNotify();\n const confirm = useConfirm();\n const gate = useConnectionGate();\n const paths = useNotificationPaths();\n const templates = useNotificationTemplates();\n const [details, setDetails] = useState<TemplateDetail[]>(() => readDetails(template?.variables));\n const [name, setName] = useState(template?.name ?? '');\n const [kind, setKind] = useState<TemplateKind>(\n template && isKind(template.type) ? template.type : 'TRANSACTIONAL'\n );\n const [channel, setChannel] = useState<TemplateChannel>(\n template && isChannel(template.channel) ? template.channel : 'IN_APP'\n );\n const [title, setTitle] = useState(() => toReadable(template?.subject ?? '', details));\n const [message, setMessage] = useState(() => toReadable(template?.bodyTemplate ?? '', details));\n const [problem, setProblem] = useState<string | null>(null);\n const lastField = useRef<DraftField>('message');\n const stored = useMemo(\n () => ({ title: toStored(title, details), message: toStored(message, details) }),\n [details, message, title]\n );\n const saving = templates.isCreating || templates.isUpdating;\n const ready = name.trim().length > 1 && message.trim().length > 0;\n\n const insert = (detail: TemplateDetail) => {\n if (!details.some((known) => known.name === detail.name)) setDetails([...details, detail]);\n const field = lastField.current;\n const element = field === 'title' ? titleRef.current : messageRef.current;\n const token = `[${detailLabel(detail.name)}]`;\n const value = field === 'title' ? title : message;\n const start = element?.selectionStart ?? value.length;\n const end = element?.selectionEnd ?? value.length;\n const next = value.slice(0, start) + token + value.slice(end);\n if (field === 'title') setTitle(next);\n else setMessage(next);\n requestAnimationFrame(() => {\n element?.focus();\n element?.setSelectionRange(start + token.length, start + token.length);\n });\n };\n\n const save = async () => {\n setProblem(null);\n const variables = writeDetails(details);\n try {\n if (template) {\n await templates.updateTemplate(template.id, {\n name: name.trim(),\n subject: stored.title.trim() || undefined,\n bodyTemplate: stored.message,\n variables,\n });\n notify({\n title: tr('notifications.v3.template.saved', 'Saved. It’s used from the next message.'),\n tone: 'success',\n });\n return;\n }\n const slug = templateSlug(name);\n const created = await templates.createTemplate({\n slug,\n name: name.trim(),\n type: kind,\n channel,\n locale: 'en',\n subject: stored.title.trim() || undefined,\n bodyTemplate: stored.message,\n variables,\n });\n notify({\n title: tr('notifications.v3.template.created', '{{name}} is ready to send', {\n name: created.name,\n }),\n tone: 'success',\n });\n navigate(paths.template(created.slug), { replace: true });\n } catch (failure) {\n setProblem(\n failure instanceof Error && failure.message\n ? failure.message\n : tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.')\n );\n }\n };\n\n const remove = async () => {\n if (!template) return;\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 // The connection may have dropped while the question was open (BOFF-18043).\n if (!yes || gate()) 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 navigate(paths.templates, { replace: true });\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 /** Remember which box Insert should write into. */\n const rememberField = (field: DraftField) => {\n lastField.current = field;\n };\n\n /** Put a detail where the cursor was in the title or the message. */\n const insertInto = (field: DraftField, detail: TemplateDetail) => {\n lastField.current = field;\n insert(detail);\n };\n\n const toggle = async () => {\n if (!template) return;\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 onChanged?.();\n } catch {\n notify({\n title: tr('notifications.v3.templates.saveFailed', 'Couldn’t save. Try again.'),\n tone: 'error',\n });\n }\n };\n\n return {\n details,\n name,\n setName,\n kind,\n setKind,\n channel,\n setChannel,\n title,\n setTitle,\n message,\n setMessage,\n problem,\n rememberField,\n stored,\n saving,\n ready,\n insertInto,\n save,\n remove,\n toggle,\n };\n}\n\nexport type TemplateDraft = ReturnType<typeof useTemplateDraft>;\n"],"mappings":";;;;;;;;;;AA4BA,SAAgBA,EACd,GAEA,GACA,GACA,GACA;CACA,IAAMC,IAAKC,EAAM,GACXC,IAAWC,EAAY,GACvBC,IAASC,EAAU,GACnBC,IAAUC,EAAW,GACrBC,IAAOC,EAAkB,GAC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BAlFyB;GACzB,IAAKkB,KAcA,MAbaZ,EAAQ;IACxB,OAAON,EAAG,0CAA0C,oBAAoB,EACtE,MAAMkB,EAAS,KACjB,CAAC;IACD,aAAalB,EACX,yCACA,6FACF;IACA,cAAcA,EAAG,qCAAqC,QAAQ;IAC9D,MAAM;IACN,eAAekB,EAAS;GAC1B,CAAC,KAEW,GAAK,GACjB,IAAI;IAQF,AAPA,MAAMN,EAAU,eAAeM,EAAS,EAAE,GAC1Cd,EAAO;KACL,OAAOJ,EAAG,sCAAsC,oBAAoB,EAClE,MAAMkB,EAAS,KACjB,CAAC;KACD,MAAM;IACR,CAAC,GACDhB,EAASQ,EAAM,WAAW,EAAE,SAAS,GAAK,CAAC;GAC7C,QAAQ;IACN,EAAO;KACL,OAAOV,EAAG,2CAA2C,gCAAgC;KACrF,MAAM;IACR,CAAC;GACH;EACF;EAoDE,oBAvCyB;GACzB,IAAKkB,GACL,IAAI;IAQF,AAPA,MAAMN,EAAU,eAAeM,EAAS,IAAI,EAAE,SAAS,CAACA,EAAS,QAAQ,CAAC,GAC1Ed,EAAO;KACL,OAAOc,EAAS,UACZlB,EAAG,wCAAwC,mBAAmB,EAAE,MAAMkB,EAAS,KAAK,CAAC,IACrFlB,EAAG,uCAAuC,kBAAkB,EAAE,MAAMkB,EAAS,KAAK,CAAC;KACvF,MAAM;IACR,CAAC,GACD0C,IAAY;GACd,QAAQ;IACN,EAAO;KACL,OAAO5D,EAAG,yCAAyC,2BAA2B;KAC9E,MAAM;IACR,CAAC;GACH;EACF;CAuBA;AACF"}
@@ -1,98 +1,100 @@
1
1
  import { useTr as e } from "../../shared/hooks/useTr.js";
2
- import { MessageTab as t } from "./MessageTab.js";
3
- import { PeopleTab as n } from "./PeopleTab.js";
4
- import { WhenTab as r } from "./WhenTab.js";
5
- import { useSendDraft as i } from "./useSendDraft.js";
6
- import { Clock as a, Pencil as o, Send as s, Users as c } from "lucide-react";
7
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
8
- import { Button as d, IconTile as f, Notice as p, TabbedDialog as m, TabbedDialogContent as h, TabbedDialogFooter as g, TabbedDialogHeader as _, TabbedDialogTabs as v } from "@burdenoff/fe-libs/ui";
2
+ import { useNeedsConnection as t, waitingButton as n } from "../useNeedsConnection.js";
3
+ import { MessageTab as r } from "./MessageTab.js";
4
+ import { PeopleTab as i } from "./PeopleTab.js";
5
+ import { WhenTab as a } from "./WhenTab.js";
6
+ import { useSendDraft as o } from "./useSendDraft.js";
7
+ import { Clock as s, Pencil as c, Send as l, Users as u } from "lucide-react";
8
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
9
+ import { Button as p, IconTile as m, Notice as h, TabbedDialog as g, TabbedDialogContent as _, TabbedDialogFooter as v, TabbedDialogHeader as y, TabbedDialogTabs as b } from "@burdenoff/fe-libs/ui";
9
10
  // src/v2/send/SendNotificationDialog.tsx
10
- function y({ open: e, onClose: t }) {
11
- return /* @__PURE__ */ l(m, {
11
+ function x({ open: e, onClose: t }) {
12
+ return /* @__PURE__ */ d(g, {
12
13
  open: e,
13
14
  onOpenChange: (e) => e ? void 0 : t(),
14
- children: e ? /* @__PURE__ */ l(x, { onClose: t }) : null
15
+ children: e ? /* @__PURE__ */ d(C, { onClose: t }) : null
15
16
  });
16
17
  }
17
- function b({ draft: t, onClose: n }) {
18
- let r = e(), i = t.draft.people.length;
19
- return /* @__PURE__ */ u(g, { children: [
20
- /* @__PURE__ */ u("span", {
18
+ function S({ draft: r, onClose: i }) {
19
+ let a = e(), o = t(), s = r.draft.people.length;
20
+ return /* @__PURE__ */ f(v, { children: [
21
+ /* @__PURE__ */ f("span", {
21
22
  className: "me-auto text-sm text-text-secondary",
22
23
  "data-testid": "send-summary",
23
24
  children: [
24
- i === 0 ? r("notifications.v3.send.toNobody", "Nobody chosen yet") : null,
25
- i === 1 ? r("notifications.v3.send.toOne", "To 1 person") : null,
26
- i > 1 ? r("notifications.v3.send.toMany", "To {{count}} people", { count: i }) : null
25
+ s === 0 ? a("notifications.v3.send.toNobody", "Nobody chosen yet") : null,
26
+ s === 1 ? a("notifications.v3.send.toOne", "To 1 person") : null,
27
+ s > 1 ? a("notifications.v3.send.toMany", "To {{count}} people", { count: s }) : null
27
28
  ]
28
29
  }),
29
- /* @__PURE__ */ l(d, {
30
+ /* @__PURE__ */ d(p, {
30
31
  variant: "ghost",
31
- onClick: n,
32
- children: r("notifications.v3.cancel", "Cancel")
32
+ onClick: i,
33
+ children: a("notifications.v3.cancel", "Cancel")
33
34
  }),
34
- /* @__PURE__ */ l(d, {
35
- busy: t.sending,
36
- onClick: () => void t.send(),
35
+ /* @__PURE__ */ d(p, {
36
+ busy: r.sending,
37
+ ...n(o),
38
+ onClick: () => void r.send(),
37
39
  "data-testid": "send-submit",
38
- children: t.draft.later ? r("notifications.v3.send.schedule", "Schedule") : r("notifications.v3.send.send", "Send")
40
+ children: r.draft.later ? a("notifications.v3.send.schedule", "Schedule") : a("notifications.v3.send.send", "Send")
39
41
  })
40
42
  ] });
41
43
  }
42
- function x({ onClose: d }) {
43
- let m = e(), g = i(d), y = [
44
+ function C({ onClose: t }) {
45
+ let n = e(), p = o(t), g = [
44
46
  {
45
47
  value: "message",
46
- label: m("notifications.v3.send.tabMessage", "Message"),
47
- icon: o
48
+ label: n("notifications.v3.send.tabMessage", "Message"),
49
+ icon: c
48
50
  },
49
51
  {
50
52
  value: "people",
51
- label: m("notifications.v3.send.tabPeople", "Who gets it"),
52
- icon: c
53
+ label: n("notifications.v3.send.tabPeople", "Who gets it"),
54
+ icon: u
53
55
  },
54
56
  {
55
57
  value: "when",
56
- label: m("notifications.v3.send.tabWhen", "When"),
57
- icon: a
58
+ label: n("notifications.v3.send.tabWhen", "When"),
59
+ icon: s
58
60
  }
59
61
  ];
60
- return /* @__PURE__ */ u(h, {
62
+ return /* @__PURE__ */ f(_, {
61
63
  "data-testid": "send-dialog",
62
64
  children: [
63
- /* @__PURE__ */ l(_, {
64
- title: m("notifications.v3.send.title", "Send a notification"),
65
- description: m("notifications.v3.send.purpose", "A one-off message to people in your organization."),
66
- icon: /* @__PURE__ */ l(f, {
65
+ /* @__PURE__ */ d(y, {
66
+ title: n("notifications.v3.send.title", "Send a notification"),
67
+ description: n("notifications.v3.send.purpose", "A one-off message to people in your organization."),
68
+ icon: /* @__PURE__ */ d(m, {
67
69
  size: "md",
68
- children: /* @__PURE__ */ l(s, { "aria-hidden": "true" })
70
+ children: /* @__PURE__ */ d(l, { "aria-hidden": "true" })
69
71
  })
70
72
  }),
71
- /* @__PURE__ */ l(v, {
72
- tabs: y,
73
- value: g.tab,
74
- onValueChange: g.setTab,
75
- renderPanel: (e) => l(e === "people" ? n : e === "when" ? r : t, { draft: g }),
76
- "aria-label": m("notifications.v3.send.title", "Send a notification"),
73
+ /* @__PURE__ */ d(b, {
74
+ tabs: g,
75
+ value: p.tab,
76
+ onValueChange: p.setTab,
77
+ renderPanel: (e) => d(e === "people" ? i : e === "when" ? a : r, { draft: p }),
78
+ "aria-label": n("notifications.v3.send.title", "Send a notification"),
77
79
  listTestId: "send-tabs",
78
80
  panelTestId: "send-panel"
79
81
  }),
80
- g.problem ? /* @__PURE__ */ l("div", {
82
+ p.problem ? /* @__PURE__ */ d("div", {
81
83
  className: "px-5 pb-3",
82
- children: /* @__PURE__ */ l(p, {
84
+ children: /* @__PURE__ */ d(h, {
83
85
  tone: "bad",
84
86
  role: "alert",
85
87
  "data-testid": "send-problem",
86
- children: g.problem
88
+ children: p.problem
87
89
  })
88
90
  }) : null,
89
- /* @__PURE__ */ l(b, {
90
- draft: g,
91
- onClose: d
91
+ /* @__PURE__ */ d(S, {
92
+ draft: p,
93
+ onClose: t
92
94
  })
93
95
  ]
94
96
  });
95
97
  }
96
- export { y as SendNotificationDialog };
98
+ export { x as SendNotificationDialog };
97
99
 
98
100
  //# sourceMappingURL=SendNotificationDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SendNotificationDialog.js","names":["SendNotificationDialog","TabbedDialog","next","onClose","open","SendForm","SendFooter","tr","useTr","count","draft","TabbedDialogFooter","Button","useSendDraft","tabs","Pencil","Users","Clock","TabbedDialogContent","TabbedDialogHeader","IconTile","Send","TabbedDialogTabs","jsx","tab","PeopleTab","WhenTab","MessageTab","Notice"],"sources":["../../../src/v2/send/SendNotificationDialog.tsx"],"sourcesContent":["/**\n * Send a notification (BOFF-16785, C2b; the mockup's `sendnotif`), from Notifications ⋯ for\n * admins: a one-off message to people in the organization, in three tabs (Message · Who gets it ·\n * When). It replaces today's full Send page under fe-libs' `accountPagesV2`; `/notifications/create`\n * opens it over the inbox.\n */\nimport { Clock, Pencil, Send, Users } from 'lucide-react';\nimport {\n Button,\n IconTile,\n Notice,\n TabbedDialog,\n TabbedDialogContent,\n TabbedDialogFooter,\n TabbedDialogHeader,\n TabbedDialogTabs,\n} from '@burdenoff/fe-libs/ui';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { MessageTab } from './MessageTab';\nimport { PeopleTab } from './PeopleTab';\nimport { WhenTab } from './WhenTab';\nimport type { SendTab } from './sendModel';\nimport { useSendDraft, type SendDraft } from './useSendDraft';\n\nexport function SendNotificationDialog({ open, onClose }: { open: boolean; onClose: () => void }) {\n return (\n <TabbedDialog open={open} onOpenChange={(next) => (next ? undefined : onClose())}>\n {open ? <SendForm onClose={onClose} /> : null}\n </TabbedDialog>\n );\n}\n\nfunction SendFooter({ draft, onClose }: { draft: SendDraft; onClose: () => void }) {\n const tr = useTr();\n const count = draft.draft.people.length;\n return (\n <TabbedDialogFooter>\n <span className=\"me-auto text-sm text-text-secondary\" data-testid=\"send-summary\">\n {count === 0 ? tr('notifications.v3.send.toNobody', 'Nobody chosen yet') : null}\n {count === 1 ? tr('notifications.v3.send.toOne', 'To 1 person') : null}\n {count > 1 ? tr('notifications.v3.send.toMany', 'To {{count}} people', { count }) : null}\n </span>\n <Button variant=\"ghost\" onClick={onClose}>\n {tr('notifications.v3.cancel', 'Cancel')}\n </Button>\n <Button busy={draft.sending} onClick={() => void draft.send()} data-testid=\"send-submit\">\n {draft.draft.later\n ? tr('notifications.v3.send.schedule', 'Schedule')\n : tr('notifications.v3.send.send', 'Send')}\n </Button>\n </TabbedDialogFooter>\n );\n}\n\nfunction SendForm({ onClose }: { onClose: () => void }) {\n const tr = useTr();\n const draft = useSendDraft(onClose);\n const tabs = [\n {\n value: 'message' as const,\n label: tr('notifications.v3.send.tabMessage', 'Message'),\n icon: Pencil,\n },\n {\n value: 'people' as const,\n label: tr('notifications.v3.send.tabPeople', 'Who gets it'),\n icon: Users,\n },\n { value: 'when' as const, label: tr('notifications.v3.send.tabWhen', 'When'), icon: Clock },\n ];\n const panel = (tab: SendTab) => {\n if (tab === 'people') return <PeopleTab draft={draft} />;\n if (tab === 'when') return <WhenTab draft={draft} />;\n return <MessageTab draft={draft} />;\n };\n return (\n <TabbedDialogContent data-testid=\"send-dialog\">\n <TabbedDialogHeader\n title={tr('notifications.v3.send.title', 'Send a notification')}\n description={tr(\n 'notifications.v3.send.purpose',\n 'A one-off message to people in your organization.'\n )}\n icon={\n <IconTile size=\"md\">\n <Send aria-hidden=\"true\" />\n </IconTile>\n }\n />\n <TabbedDialogTabs<SendTab>\n tabs={tabs}\n value={draft.tab}\n onValueChange={draft.setTab}\n renderPanel={panel}\n aria-label={tr('notifications.v3.send.title', 'Send a notification')}\n listTestId=\"send-tabs\"\n panelTestId=\"send-panel\"\n />\n {draft.problem ? (\n <div className=\"px-5 pb-3\">\n <Notice tone=\"bad\" role=\"alert\" data-testid=\"send-problem\">\n {draft.problem}\n </Notice>\n </div>\n ) : null}\n <SendFooter draft={draft} onClose={onClose} />\n </TabbedDialogContent>\n );\n}\n"],"mappings":";;;;;;;;;AAwBA,SAAgBA,EAAuB,EAAE,SAAM,cAAmD;CAChG,OACE,kBAACC,GAAD;EAAoB;EAAM,eAAe,MAAUC,IAAO,KAAA,IAAYC,EAAQ;EAC3E,UAAAC,IAAO,kBAACC,GAAD,EAAmB,WAAU,CAAA,IAAI;CAC7B,CAAA;AAElB;AAEA,SAASC,EA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M;IACb,eAAeA,EAAM;IACrB,cAvBS,MACgBa,EAAzBC,MAAQ,WAAkBC,IAC1BD,MAAQ,SAAgBE,IACpBC,GAFqB,EAAkB,SAAQ,CAAA;IAuBnD,cAAYpB,EAAG,+BAA+B,qBAAqB;IACnE,YAAW;IACX,aAAY;GACb,CAAA;GACAG,EAAM,UACL,kBAAC,OAAD;IAAK,WAAU;IACb,UAAA,kBAACkB,GAAD;KAAQ,MAAK;KAAM,MAAK;KAAQ,eAAY;KACzC,UAAAlB,EAAM;IACD,CAAA;GACL,CAAA,IACH;GACJ,kBAACJ,GAAD;IAAmB;IAAgB;GAAU,CAAA;EAC1B;;AAEzB"}
1
+ {"version":3,"file":"SendNotificationDialog.js","names":["SendNotificationDialog","TabbedDialog","next","onClose","open","SendForm","SendFooter","tr","useTr","connection","useNeedsConnection","count","draft","TabbedDialogFooter","Button","waitingButton","useSendDraft","tabs","Pencil","Users","Clock","TabbedDialogContent","TabbedDialogHeader","IconTile","Send","TabbedDialogTabs","jsx","tab","PeopleTab","WhenTab","MessageTab","Notice"],"sources":["../../../src/v2/send/SendNotificationDialog.tsx"],"sourcesContent":["/**\n * Send a notification (BOFF-16785, C2b; the mockup's `sendnotif`), from Notifications ⋯ for\n * admins: a one-off message to people in the organization, in three tabs (Message · Who gets it ·\n * When). It replaces today's full Send page under fe-libs' `accountPagesV2`; `/notifications/create`\n * opens it over the inbox.\n */\nimport { Clock, Pencil, Send, Users } from 'lucide-react';\nimport {\n Button,\n IconTile,\n Notice,\n TabbedDialog,\n TabbedDialogContent,\n TabbedDialogFooter,\n TabbedDialogHeader,\n TabbedDialogTabs,\n} from '@burdenoff/fe-libs/ui';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useNeedsConnection, waitingButton } from '../useNeedsConnection';\nimport { MessageTab } from './MessageTab';\nimport { PeopleTab } from './PeopleTab';\nimport { WhenTab } from './WhenTab';\nimport type { SendTab } from './sendModel';\nimport { useSendDraft, type SendDraft } from './useSendDraft';\n\nexport function SendNotificationDialog({ open, onClose }: { open: boolean; onClose: () => void }) {\n return (\n <TabbedDialog open={open} onOpenChange={(next) => (next ? undefined : onClose())}>\n {open ? <SendForm onClose={onClose} /> : null}\n </TabbedDialog>\n );\n}\n\nfunction SendFooter({ draft, onClose }: { draft: SendDraft; onClose: () => void }) {\n const tr = useTr();\n const connection = useNeedsConnection();\n const count = draft.draft.people.length;\n return (\n <TabbedDialogFooter>\n <span className=\"me-auto text-sm text-text-secondary\" data-testid=\"send-summary\">\n {count === 0 ? tr('notifications.v3.send.toNobody', 'Nobody chosen yet') : null}\n {count === 1 ? tr('notifications.v3.send.toOne', 'To 1 person') : null}\n {count > 1 ? tr('notifications.v3.send.toMany', 'To {{count}} people', { count }) : null}\n </span>\n <Button variant=\"ghost\" onClick={onClose}>\n {tr('notifications.v3.cancel', 'Cancel')}\n </Button>\n <Button\n busy={draft.sending}\n {...waitingButton(connection)}\n onClick={() => void draft.send()}\n data-testid=\"send-submit\"\n >\n {draft.draft.later\n ? tr('notifications.v3.send.schedule', 'Schedule')\n : tr('notifications.v3.send.send', 'Send')}\n </Button>\n </TabbedDialogFooter>\n );\n}\n\nfunction SendForm({ onClose }: { onClose: () => void }) {\n const tr = useTr();\n const draft = useSendDraft(onClose);\n const tabs = [\n {\n value: 'message' as const,\n label: tr('notifications.v3.send.tabMessage', 'Message'),\n icon: Pencil,\n },\n {\n value: 'people' as const,\n label: tr('notifications.v3.send.tabPeople', 'Who gets it'),\n icon: Users,\n },\n { value: 'when' as const, label: tr('notifications.v3.send.tabWhen', 'When'), icon: Clock },\n ];\n const panel = (tab: SendTab) => {\n if (tab === 'people') return <PeopleTab draft={draft} />;\n if (tab === 'when') return <WhenTab draft={draft} />;\n return <MessageTab draft={draft} />;\n };\n return (\n <TabbedDialogContent data-testid=\"send-dialog\">\n <TabbedDialogHeader\n title={tr('notifications.v3.send.title', 'Send a notification')}\n description={tr(\n 'notifications.v3.send.purpose',\n 'A one-off message to people in your organization.'\n )}\n icon={\n <IconTile size=\"md\">\n <Send aria-hidden=\"true\" />\n </IconTile>\n }\n />\n <TabbedDialogTabs<SendTab>\n tabs={tabs}\n value={draft.tab}\n onValueChange={draft.setTab}\n renderPanel={panel}\n aria-label={tr('notifications.v3.send.title', 'Send a notification')}\n listTestId=\"send-tabs\"\n panelTestId=\"send-panel\"\n />\n {draft.problem ? (\n <div className=\"px-5 pb-3\">\n <Notice tone=\"bad\" role=\"alert\" data-testid=\"send-problem\">\n {draft.problem}\n </Notice>\n </div>\n ) : null}\n <SendFooter draft={draft} onClose={onClose} />\n </TabbedDialogContent>\n );\n}\n"],"mappings":";;;;;;;;;;AAyBA,SAAgBA,EAAuB,EAAE,SAAM,cAAmD;CAChG,OACE,kBAACC,GAAD;EAAoB;EAAM,eAAe,MAAUC,IAAO,KAAA,IAAYC,EAAQ;EAC3E,UAAAC,IAAO,kBAACC,GAAD,EAAmB,WAAU,CAAA,IAAI;CAC7B,CAAA;AAElB;AAEA,SAASC,EAAW,EAAE,UAAO,cAAsD;CACjF,IAAMC,IAAKC,EAAM,GACXC,IAAaC,EAAmB,GAChCC,IAAQC,EAAM,MAAM,OAAO;CACjC,OACE,kBAACC,GAAD,EAAA,UAAA;EACE,kBAAC,QAAD;GAAM,WAAU;GAAsC,eAAY;GAAlE,UAAA;IACGF,MAAU,IAAIJ,EAAG,kCAAkC,mBAAmB,IAAI;IAC1EI,MAAU,IAAIJ,EAAG,+BAA+B,aAAa,IAAI;IACjEI,IAAQ,IAAIJ,EAAG,gCAAgC,uBAAuB,EAAE,SAAM,CAAC,IAAI;GAChF;;EACN,kBAACO,GAAD;GAAQ,SAAQ;GAAQ,SAASX;GAC9B,UAAAI,EAAG,2BAA2B,QAAQ;EACjC,CAAA;EACR,kBAACO,GAAD;GACE,MAAMF,EAAM;GACZ,GAAIG,EAAcN,CAAU;GAC5B,eAAe,KAAKG,EAAM,KAAK;GAC/B,eAAY;GAEX,UAAAA,EAAM,MAAM,QACTL,EAAG,kCAAkC,UAAU,IAC/CA,EAAG,8BAA8B,MAAM;EACrC,CAAA;CACU,EAAA,CAAA;AAExB;AAEA,SAASF,EAAS,EAAE,cAAoC;CACtD,IAAME,IAAKC,EAAM,GACXI,IAAQI,EAAab,CAAO,GAC5Bc,IAAO;EACX;GACE,OAAO;GACP,OAAOV,EAAG,oCAAoC,SAAS;GACvD,MAAMW;EACR;EACA;GACE,OAAO;GACP,OAAOX,EAAG,mCAAmC,aAAa;GAC1D,MAAMY;EACR;EACA;GAAE,OAAO;GAAiB,OAAOZ,EAAG,iCAAiC,MAAM;GAAG,MAAMa;EAAM;CAC5F;CAMA,OACE,kBAACC,GAAD;EAAqB,eAAY;EAAjC,UAAA;GACE,kBAACC,GAAD;IACE,OAAOf,EAAG,+BAA+B,qBAAqB;IAC9D,aAAaA,EACX,iCACA,mDACF;IACA,MACE,kBAACgB,GAAD;KAAU,MAAK;KACb,UAAA,kBAACC,GAAD,EAAM,eAAY,OAAQ,CAAA;IAClB,CAAA;GAEb,CAAA;GACD,kBAACC,GAAD;IACQ;IACN,OAAOb,EAAM;IACb,eAAeA,EAAM;IACrB,cAvBS,MACgBc,EAAzBC,MAAQ,WAAkBC,IAC1BD,MAAQ,SAAgBE,IACpBC,GAFqB,EAAkB,SAAQ,CAAA;IAuBnD,cAAYvB,EAAG,+BAA+B,qBAAqB;IACnE,YAAW;IACX,aAAY;GACb,CAAA;GACAK,EAAM,UACL,kBAAC,OAAD;IAAK,WAAU;IACb,UAAA,kBAACmB,GAAD;KAAQ,MAAK;KAAM,MAAK;KAAQ,eAAY;KACzC,UAAAnB,EAAM;IACD,CAAA;GACL,CAAA,IACH;GACJ,kBAACN,GAAD;IAAmB;IAAgB;GAAU,CAAA;EAC1B;;AAEzB"}
@@ -0,0 +1,29 @@
1
+ export interface NeedsConnection {
2
+ /** Under the opt-in and offline: the action waits for the connection. */
3
+ waiting: boolean;
4
+ /** "Needs a connection" while waiting, for the disabled button's `title`; else undefined. */
5
+ title: string | undefined;
6
+ }
7
+ export declare function useNeedsConnection(): NeedsConnection;
8
+ /**
9
+ * A button that writes: disabled while waiting, with why as its title. `otherwise`: it is
10
+ * disabled for another reason already (then it says nothing about the connection).
11
+ */
12
+ export declare function waitingButton(connection: NeedsConnection, otherwise?: boolean): {
13
+ disabled: boolean;
14
+ title: string | undefined;
15
+ };
16
+ /** An action-menu item that writes: disabled while waiting, with why as its second line. */
17
+ export declare function waitingItem(connection: NeedsConnection, otherwise?: boolean): {
18
+ disabled: boolean;
19
+ description: string | undefined;
20
+ };
21
+ /**
22
+ * For a write that runs after a question, or from a toast's Undo: the connection is checked again
23
+ * at the moment of the write, not only when the button was pressed (it may drop while the
24
+ * question or the toast is open). Returns a check that is true, and says so ("Needs a connection.
25
+ * Nothing changed. Try again when you're back online."), when the write must wait; the caller then
26
+ * sends nothing. Under the opt-in only: the page's signal, or the browser's own flag if the page
27
+ * hasn't caught up yet. Without the opt-in it is always false and says nothing.
28
+ */
29
+ export declare function useConnectionGate(): () => boolean;
@@ -0,0 +1,51 @@
1
+ import { useTr as e } from "../shared/hooks/useTr.js";
2
+ import { useCallback as t, useEffect as n, useRef as r } from "react";
3
+ import { useAccountPagesV2 as i, useNotify as a, useStaleSince as o } from "@burdenoff/fe-libs/ui";
4
+ // src/v2/useNeedsConnection.ts
5
+ function s() {
6
+ let t = i(), { offline: n } = o(null), r = e(), a = t && n;
7
+ return {
8
+ waiting: a,
9
+ title: a ? r("notifications.v3.offline.needsConnection", "Needs a connection") : void 0
10
+ };
11
+ }
12
+ function c(e, t = !1) {
13
+ return {
14
+ disabled: t || e.waiting,
15
+ title: t ? void 0 : e.title
16
+ };
17
+ }
18
+ function l(e, t = !1) {
19
+ return {
20
+ disabled: t || e.waiting,
21
+ description: t ? void 0 : e.title
22
+ };
23
+ }
24
+ function u() {
25
+ let o = i(), { waiting: c, title: l } = s(), u = a(), d = e(), f = r({
26
+ v2: o,
27
+ waiting: c,
28
+ title: l
29
+ });
30
+ return n(() => {
31
+ f.current = {
32
+ v2: o,
33
+ waiting: c,
34
+ title: l
35
+ };
36
+ }, [
37
+ o,
38
+ c,
39
+ l
40
+ ]), t(() => {
41
+ let e = f.current;
42
+ return e.waiting || e.v2 && typeof navigator < "u" && navigator.onLine === !1 ? (u({
43
+ tone: "warning",
44
+ title: e.title ?? d("notifications.v3.offline.needsConnection", "Needs a connection"),
45
+ description: d("notifications.v3.offline.nothingChanged", "Nothing changed. Try again when you’re back online.")
46
+ }), !0) : !1;
47
+ }, [u, d]);
48
+ }
49
+ export { u as useConnectionGate, s as useNeedsConnection, c as waitingButton, l as waitingItem };
50
+
51
+ //# sourceMappingURL=useNeedsConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNeedsConnection.js","names":["useNeedsConnection","v2","useAccountPagesV2","useStaleSince","tr","useTr","waiting","offline","waitingButton","otherwise","connection","waitingItem","useConnectionGate","notify","useNotify","latest","useRef","useEffect","title","useCallback","now"],"sources":["../../src/v2/useNeedsConnection.ts"],"sourcesContent":["/**\n * Buttons that need a connection wait until the app is back (BOFF-18043). The stale-data line\n * (BOFF-16786) says \"Buttons that need a connection wait until you're back.\"; this is what keeps\n * that promise. Under the Account & platform opt-in, while offline, the redesigned Notifications\n * pages disable the actions that write or call the server (mark read, archive, send, save, turn\n * off, delete), with \"Needs a connection\" as their title, as the mockup's \"Download all\". Moving\n * around, reading and opening a form stay as they are.\n *\n * The online signal is the stale-data line's own (fe-libs `useStaleSince`, which reads\n * `useNetworkStatus`), so the line and the buttons always agree. Online, or without the opt-in,\n * `waiting` is false and `title` undefined: the markup is today's.\n */\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useAccountPagesV2, useNotify, useStaleSince } from '@burdenoff/fe-libs/ui';\nimport { useTr } from '../shared/hooks/useTr';\n\nexport interface NeedsConnection {\n /** Under the opt-in and offline: the action waits for the connection. */\n waiting: boolean;\n /** \"Needs a connection\" while waiting, for the disabled button's `title`; else undefined. */\n title: string | undefined;\n}\n\nexport function useNeedsConnection(): NeedsConnection {\n const v2 = useAccountPagesV2();\n // Nothing loaded is passed on purpose: only the connection is wanted, not the line.\n const { offline } = useStaleSince(null);\n const tr = useTr();\n const waiting = v2 && offline;\n return {\n waiting,\n title: waiting\n ? tr('notifications.v3.offline.needsConnection', 'Needs a connection')\n : undefined,\n };\n}\n\n/**\n * A button that writes: disabled while waiting, with why as its title. `otherwise`: it is\n * disabled for another reason already (then it says nothing about the connection).\n */\nexport function waitingButton(\n connection: NeedsConnection,\n otherwise = false\n): { disabled: boolean; title: string | undefined } {\n return {\n disabled: otherwise || connection.waiting,\n title: otherwise ? undefined : connection.title,\n };\n}\n\n/** An action-menu item that writes: disabled while waiting, with why as its second line. */\nexport function waitingItem(\n connection: NeedsConnection,\n otherwise = false\n): { disabled: boolean; description: string | undefined } {\n return {\n disabled: otherwise || connection.waiting,\n description: otherwise ? undefined : connection.title,\n };\n}\n\n/**\n * For a write that runs after a question, or from a toast's Undo: the connection is checked again\n * at the moment of the write, not only when the button was pressed (it may drop while the\n * question or the toast is open). Returns a check that is true, and says so (\"Needs a connection.\n * Nothing changed. Try again when you're back online.\"), when the write must wait; the caller then\n * sends nothing. Under the opt-in only: the page's signal, or the browser's own flag if the page\n * hasn't caught up yet. Without the opt-in it is always false and says nothing.\n */\nexport function useConnectionGate(): () => boolean {\n const v2 = useAccountPagesV2();\n const { waiting, title } = useNeedsConnection();\n const notify = useNotify();\n const tr = useTr();\n const latest = useRef({ v2, waiting, title });\n useEffect(() => {\n latest.current = { v2, waiting, title };\n }, [v2, waiting, title]);\n return useCallback(() => {\n const now = latest.current;\n const offline =\n now.waiting || (now.v2 && typeof navigator !== 'undefined' && navigator.onLine === false);\n if (!offline) return false;\n notify({\n tone: 'warning',\n title: now.title ?? tr('notifications.v3.offline.needsConnection', 'Needs a connection'),\n description: tr(\n 'notifications.v3.offline.nothingChanged',\n 'Nothing changed. Try again when you’re back online.'\n ),\n });\n return true;\n }, [notify, tr]);\n}\n"],"mappings":";;;;AAuBA,SAAgBA,IAAsC;CACpD,IAAMC,IAAKC,EAAkB,GAEvB,EAAE,eAAYC,EAAc,IAAI,GAChCC,IAAKC,EAAM,GACXC,IAAUL,KAAMM;CACtB,OAAO;EACL;EACA,OAAOD,IACHF,EAAG,4CAA4C,oBAAoB,IACnE,KAAA;CACN;AACF;AAMA,SAAgBI,EACd,GACA,IAAY,IACsC;CAClD,OAAO;EACL,UAAUC,KAAaC,EAAW;EAClC,OAAOD,IAAY,KAAA,IAAYC,EAAW;CAC5C;AACF;AAGA,SAAgBC,EACd,GACA,IAAY,IAC4C;CACxD,OAAO;EACL,UAAUF,KAAaC,EAAW;EAClC,aAAaD,IAAY,KAAA,IAAYC,EAAW;CAClD;AACF;AAUA,SAAgBE,IAAmC;CACjD,IAAMX,IAAKC,EAAkB,GACvB,EAAE,YAAS,aAAUF,EAAmB,GACxCa,IAASC,EAAU,GACnBV,IAAKC,EAAM,GACXU,IAASC,EAAO;EAAE;EAAI;EAAS;CAAM,CAAC;CAI5C,OAHAC,QAAgB;EACd,EAAO,UAAU;GAAE;GAAI;GAAS;EAAM;CACxC,GAAG;EAAChB;EAAIK;EAASY;CAAK,CAAC,GAChBC,QAAkB;EACvB,IAAMC,IAAML,EAAO;EAYnB,OAVEK,EAAI,WAAYA,EAAI,MAAM,OAAO,YAAc,OAAe,UAAU,WAAW,MAErFP,EAAO;GACL,MAAM;GACN,OAAOO,EAAI,SAAShB,EAAG,4CAA4C,oBAAoB;GACvF,aAAaA,EACX,2CACA,qDACF;EACF,CAAC,GACM,MATc;CAUvB,GAAG,CAACS,GAAQT,CAAE,CAAC;AACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-notification",
3
- "version": "2026.1202.1",
3
+ "version": "2026.1203.1",
4
4
  "description": "Notification microfrontend for multi-channel notification management",
5
5
  "type": "module",
6
6
  "imports": {