@burdenoff/microfe-notification 2026.1201.1 → 2026.1202.2

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 (53) hide show
  1. package/dist/hooks/answeredAt.d.ts +8 -0
  2. package/dist/hooks/answeredAt.js +33 -0
  3. package/dist/hooks/answeredAt.js.map +1 -0
  4. package/dist/hooks/useNotificationAdmin.d.ts +2 -0
  5. package/dist/hooks/useNotificationAdmin.js +32 -31
  6. package/dist/hooks/useNotificationAdmin.js.map +1 -1
  7. package/dist/hooks/useNotificationPreferences.d.ts +2 -0
  8. package/dist/hooks/useNotificationPreferences.js +45 -43
  9. package/dist/hooks/useNotificationPreferences.js.map +1 -1
  10. package/dist/hooks/useNotificationTemplates.d.ts +2 -0
  11. package/dist/hooks/useNotificationTemplates.js +92 -88
  12. package/dist/hooks/useNotificationTemplates.js.map +1 -1
  13. package/dist/hooks/useNotificationTopics.d.ts +2 -0
  14. package/dist/hooks/useNotificationTopics.js +19 -18
  15. package/dist/hooks/useNotificationTopics.js.map +1 -1
  16. package/dist/hooks/useNotifications.d.ts +2 -0
  17. package/dist/hooks/useNotifications.js +69 -68
  18. package/dist/hooks/useNotifications.js.map +1 -1
  19. package/dist/hooks/usePreferenceToggles.d.ts +2 -0
  20. package/dist/hooks/usePreferenceToggles.js +19 -18
  21. package/dist/hooks/usePreferenceToggles.js.map +1 -1
  22. package/dist/v2/InboxPage.js +111 -107
  23. package/dist/v2/InboxPage.js.map +1 -1
  24. package/dist/v2/InboxRows.js +50 -45
  25. package/dist/v2/InboxRows.js.map +1 -1
  26. package/dist/v2/NotificationDetailPanel.js +97 -93
  27. package/dist/v2/NotificationDetailPanel.js.map +1 -1
  28. package/dist/v2/PreferencesPage.js +113 -106
  29. package/dist/v2/PreferencesPage.js.map +1 -1
  30. package/dist/v2/StaleHint.d.ts +4 -0
  31. package/dist/v2/StaleHint.js +18 -0
  32. package/dist/v2/StaleHint.js.map +1 -0
  33. package/dist/v2/admin/DeliveryLogPage.js +71 -69
  34. package/dist/v2/admin/DeliveryLogPage.js.map +1 -1
  35. package/dist/v2/admin/TemplateEditor.js +58 -55
  36. package/dist/v2/admin/TemplateEditor.js.map +1 -1
  37. package/dist/v2/admin/TemplatesPage.js +150 -142
  38. package/dist/v2/admin/TemplatesPage.js.map +1 -1
  39. package/dist/v2/admin/TopicDialog.js +66 -65
  40. package/dist/v2/admin/TopicDialog.js.map +1 -1
  41. package/dist/v2/admin/TopicsPage.js +85 -80
  42. package/dist/v2/admin/TopicsPage.js.map +1 -1
  43. package/dist/v2/admin/useTemplateDraft.js +73 -72
  44. package/dist/v2/admin/useTemplateDraft.js.map +1 -1
  45. package/dist/v2/model/loadedAt.d.ts +5 -0
  46. package/dist/v2/model/loadedAt.js +8 -0
  47. package/dist/v2/model/loadedAt.js.map +1 -0
  48. package/dist/v2/send/SendNotificationDialog.js +53 -51
  49. package/dist/v2/send/SendNotificationDialog.js.map +1 -1
  50. package/dist/v2/useNeedsConnection.d.ts +29 -0
  51. package/dist/v2/useNeedsConnection.js +51 -0
  52. package/dist/v2/useNeedsConnection.js.map +1 -0
  53. package/package.json +2 -2
@@ -1 +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","WorkspacePage","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 WorkspacePage,\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 <WorkspacePage>\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 </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAkCA,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,GAAA,CAAI,YAAY,CAAC,CAAC,SAASF,CAAK,CACzD,IALmBC;CAMrB,GAAG,CAACN,GAAQF,EAAU,YAAY,CAAC,GAE7BU,IAAS,OAAO,MAA0C;EAC9D,IAAI;GAQF,AAPA,MAAMV,EAAU,eAAeS,EAAS,IAAI,EAAE,SAAS,CAACA,EAAS,QAAQ,CAAC,GAC1Eb,EAAO;IACL,OAAOa,EAAS,UACZrB,EAAG,wCAAwC,mBAAmB,EAAE,MAAMqB,EAAS,KAAK,CAAC,IACrFrB,EAAG,uCAAuC,kBAAkB,EAAE,MAAMqB,EAAS,KAAK,CAAC;IACvF,MAAM;GACR,CAAC,GACD,MAAMT,EAAU,QAAQ;EAC1B,QAAQ;GACN,EAAO;IACL,OAAOZ,EAAG,yCAAyC,2BAA2B;IAC9E,MAAM;GACR,CAAC;EACH;CACF,GAEMuB,IAAS,OAAO,MAA0C;EAa9D,IAAK,MAZajB,EAAQ;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CAAqC,QAAQ;KACxD,OAAO,MAAaU,EAAK,OAAOW,EAAS,SAAS;IACpD;IACA;KACE,IAAI;KACJ,QAAQrB,EAAG,qCAAqC,QAAQ;KACxD,OAAO,MACLqB,EAAS,UACP,kBAACmB,GAAD;MAAY,QAAO;MAAM,UAAAxC,EAAG,uBAAuB,IAAI;KAAc,CAAA,IAErE,kBAACwC,GAAD;MAAY,QAAO;MAAU,UAAAxC,EAAG,wBAAwB,KAAK;KAAc,CAAA;IAEjF;GACF;GACA,UAAU,MACR,kBAACyC,GAAD;IACE,WAAU;IACV,OAAOzC,EAAG,yCAAyC,wBAAwB,EACzE,MAAMqB,EAAS,KACjB,CAAC;IACD,OAAO,CACL;KACE,IAAI;KACJ,OAAOA,EAAS,UACZrB,EAAG,sCAAsC,UAAU,IACnDA,EAAG,qCAAqC,SAAS;KACrD,gBAAgB,KAAKsB,EAAOD,CAAQ;IACtC,GACA;KACE,IAAI;KACJ,OAAOrB,EAAG,qCAAqC,QAAQ;KACvD,QAAQ;KACR,gBAAgB,KAAKuB,EAAOF,CAAQ;IACtC,CACF;GACD,CAAA;EAEJ,CAAA,CAEA;CACQ,CAAA,CAAA,EAAA,CAAA;AAEnB"}
1
+ {"version":3,"file":"TemplatesPage.js","names":["TemplatesPage","AdminPageV2","TemplatesList","tr","useTr","connection","useNeedsConnection","navigate","useNavigate","paths","useNotificationPaths","confirm","useConfirm","gate","useConnectionGate","notify","useNotify","when","useWhenLabels","templates","useNotificationTemplates","search","setSearch","useState","shown","useMemo","query","all","template","toggle","remove","WorkspacePage","PageHeader","Button","Plus","StaleHint","Search","Input","event","LoadError","EmptyState","DataRows","IconTile","Mail","toReadable","readDetails","kindWord","channelWord","StatusChip","ActionMenu","waitingItem"],"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 WorkspacePage,\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 { useConnectionGate, useNeedsConnection, waitingItem } from '../useNeedsConnection';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { channelWord, kindWord } from './words';\nimport { readDetails, toReadable } from './templateText';\nimport { StaleHint } from '../StaleHint';\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 connection = useNeedsConnection();\n const navigate = useNavigate();\n const paths = useNotificationPaths();\n const confirm = useConfirm();\n const gate = useConnectionGate();\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 // 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 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 <WorkspacePage>\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 <StaleHint loadedAt={templates.dataUpdatedAt} />\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 ...waitingItem(connection),\n onSelect: () => void toggle(template),\n },\n {\n id: 'delete',\n label: tr('notifications.v3.templates.delete', 'Delete'),\n danger: true,\n ...waitingItem(connection),\n onSelect: () => void remove(template),\n },\n ]}\n />\n )}\n />\n )}\n </div>\n </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoCA,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,IAAaC,EAAmB,GAChCC,IAAWC,EAAY,GACvBC,IAAQC,EAAqB,GAC7BC,IAAUC,EAAW,GACrBC,IAAOC,EAAkB,GACzBC,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,GAAA,CAAI,YAAY,CAAC,CAAC,SAASF,CAAK,CACzD,IALmBC;CAMrB,GAAG,CAACN,GAAQF,EAAU,YAAY,CAAC,GAE7BU,IAAS,OAAO,MAA0C;EAC9D,IAAI;GAQF,AAPA,MAAMV,EAAU,eAAeS,EAAS,IAAI,EAAE,SAAS,CAACA,EAAS,QAAQ,CAAC,GAC1Eb,EAAO;IACL,OAAOa,EAAS,UACZzB,EAAG,wCAAwC,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/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";
2
+ import { useNeedsConnection as t, waitingButton as n } from "../useNeedsConnection.js";
3
+ import { templateSlug as r } from "./templateText.js";
4
+ import { ChoiceSelect as i } from "./ChoiceSelect.js";
5
+ import { TEMPLATE_KINDS as a, isKind as o, kindWord as s } from "./words.js";
6
+ import { useId as c, useState as l } from "react";
7
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
8
+ import { Button as f, Input as p, Label as m, Notice as h, ResponsiveDialog as g, ResponsiveDialogContent as _, ResponsiveDialogDescription as v, ResponsiveDialogFooter as y, ResponsiveDialogHeader as b, ResponsiveDialogTitle as x, useNotify as S } from "@burdenoff/fe-libs/ui";
8
9
  // src/v2/admin/TopicDialog.tsx
9
- function x({ open: e, topic: t, onClose: n, onCreate: r, onUpdate: i }) {
10
- return /* @__PURE__ */ c(m, {
10
+ function C({ open: e, topic: t, onClose: n, onCreate: r, onUpdate: i }) {
11
+ return /* @__PURE__ */ u(g, {
11
12
  open: e,
12
13
  onOpenChange: (e) => e ? void 0 : n(),
13
- children: e ? /* @__PURE__ */ c(S, {
14
+ children: e ? /* @__PURE__ */ u(w, {
14
15
  topic: t,
15
16
  onClose: n,
16
17
  onCreate: r,
@@ -18,96 +19,96 @@ function x({ open: e, topic: t, onClose: n, onCreate: r, onUpdate: i }) {
18
19
  }, t?.id ?? "new") : null
19
20
  });
20
21
  }
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,
22
+ function w({ topic: g, onClose: C, onCreate: w, onUpdate: T }) {
23
+ let E = e(), D = t(), O = c(), k = S(), [A, j] = l(g?.name ?? ""), [M, N] = l(g?.description ?? ""), [P, F] = l(g && o(g.type) ? g.type : "MARKETING"), [I, L] = l(!1), [R, z] = l(!1), B = () => g ? T(g.id, {
24
+ name: A.trim(),
25
+ description: M.trim() || void 0
26
+ }) : w({
27
+ name: A.trim(),
28
+ slug: r(A),
29
+ description: M.trim() || void 0,
30
+ type: P,
30
31
  isActive: !0
31
- }), R = async () => {
32
- P(!0), I(!1);
32
+ }), V = async () => {
33
+ L(!0), z(!1);
33
34
  let e = null;
34
35
  try {
35
- e = await L();
36
+ e = await B();
36
37
  } catch {
37
38
  e = null;
38
39
  } finally {
39
- P(!1);
40
+ L(!1);
40
41
  }
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 }),
42
+ e ? (k({
43
+ title: g ? E("notifications.v3.topics.saved", "Saved {{name}}", { name: e.name }) : E("notifications.v3.topics.created", "{{name}} is ready", { name: e.name }),
43
44
  tone: "success"
44
- }), x()) : I(!0);
45
+ }), C()) : z(!0);
45
46
  };
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
+ return /* @__PURE__ */ d(_, { children: [/* @__PURE__ */ d(b, { children: [/* @__PURE__ */ u(x, { children: g ? E("notifications.v3.topics.editTitle", "Edit topic") : E("notifications.v3.topics.new", "New topic") }), /* @__PURE__ */ u(v, { children: E("notifications.v3.topics.dialogHelp", "People see its name and line in their notification settings.") })] }), /* @__PURE__ */ d("form", {
47
48
  className: "flex flex-col gap-4",
48
49
  onSubmit: (e) => {
49
- e.preventDefault(), D.trim().length > 1 && !N && R();
50
+ e.preventDefault(), A.trim().length > 1 && !I && V();
50
51
  },
51
52
  children: [
52
- /* @__PURE__ */ l("div", {
53
+ /* @__PURE__ */ d("div", {
53
54
  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`,
55
+ children: [/* @__PURE__ */ u(m, {
56
+ htmlFor: `${O}-name`,
57
+ children: E("notifications.v3.template.name", "Name")
58
+ }), /* @__PURE__ */ u(p, {
59
+ id: `${O}-name`,
59
60
  autoFocus: !0,
60
- value: D,
61
- placeholder: w("notifications.v3.topics.namePlaceholder", "For example: Product news"),
62
- onChange: (e) => O(e.target.value),
61
+ value: A,
62
+ placeholder: E("notifications.v3.topics.namePlaceholder", "For example: Product news"),
63
+ onChange: (e) => j(e.target.value),
63
64
  "data-testid": "topic-name"
64
65
  })]
65
66
  }),
66
- /* @__PURE__ */ l("div", {
67
+ /* @__PURE__ */ d("div", {
67
68
  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)
69
+ children: [/* @__PURE__ */ u(m, {
70
+ htmlFor: `${O}-about`,
71
+ children: E("notifications.v3.topics.about", "One line about it (optional)")
72
+ }), /* @__PURE__ */ u(p, {
73
+ id: `${O}-about`,
74
+ value: M,
75
+ onChange: (e) => N(e.target.value)
75
76
  })]
76
77
  }),
77
- /* @__PURE__ */ l("div", {
78
+ /* @__PURE__ */ d("div", {
78
79
  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
80
+ children: [/* @__PURE__ */ u(m, {
81
+ htmlFor: `${O}-kind`,
82
+ children: E("notifications.v3.template.kind", "About")
83
+ }), /* @__PURE__ */ u(i, {
84
+ id: `${O}-kind`,
85
+ value: P,
86
+ options: a,
87
+ word: (e) => s(e, E),
88
+ onChange: F,
89
+ disabled: !!g
89
90
  })]
90
91
  }),
91
- F ? /* @__PURE__ */ c(p, {
92
+ R ? /* @__PURE__ */ u(h, {
92
93
  tone: "bad",
93
94
  role: "alert",
94
- children: w("notifications.v3.templates.saveFailed", "Couldn’t save. Try again.")
95
+ children: E("notifications.v3.templates.saveFailed", "Couldn’t save. Try again.")
95
96
  }) : null,
96
- /* @__PURE__ */ l(_, { children: [/* @__PURE__ */ c(u, {
97
+ /* @__PURE__ */ d(y, { children: [/* @__PURE__ */ u(f, {
97
98
  type: "button",
98
99
  variant: "ghost",
99
- onClick: x,
100
- children: w("notifications.v3.cancel", "Cancel")
101
- }), /* @__PURE__ */ c(u, {
100
+ onClick: C,
101
+ children: E("notifications.v3.cancel", "Cancel")
102
+ }), /* @__PURE__ */ u(f, {
102
103
  type: "submit",
103
- busy: N,
104
- disabled: D.trim().length < 2,
104
+ busy: I,
105
+ ...n(D, A.trim().length < 2),
105
106
  "data-testid": "topic-save",
106
- children: m ? w("notifications.v3.template.save", "Save") : w("notifications.v3.topics.create", "Create topic")
107
+ children: g ? E("notifications.v3.template.save", "Save") : E("notifications.v3.topics.create", "Create topic")
107
108
  })] })
108
109
  ]
109
110
  })] });
110
111
  }
111
- export { x as TopicDialog };
112
+ export { C as TopicDialog };
112
113
 
113
114
  //# sourceMappingURL=TopicDialog.js.map
@@ -1 +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 </ResponsiveDialogFooter>\n </form>\n </ResponsiveDialogContent>\n );\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgBA,EAAY,EAC1B,SACA,UACA,YACA,aACA,eAOC;CACD,OACE,kBAACC,GAAD;EAAwB;EAAM,eAAe,MAAUC,IAAO,KAAA,IAAYC,EAAQ;EAC/E,UAAAC,IACC,kBAACC,GAAD;GAES;GACE;GACC;GACA;EACX,GALMC,GAAO,MAAM,KAKnB,IACC;CACY,CAAA;AAEtB;AAEA,SAASD,EAAU,EACjB,UACA,YACA,aACA,eAMC;CACD,IAAME,IAAKC,EAAM,GACXC,I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R,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"}
1
+ {"version":3,"file":"TopicDialog.js","names":["TopicDialog","ResponsiveDialog","next","onClose","open","TopicForm","topic","tr","useTr","connection","useNeedsConnection","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","waitingButton"],"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 { useNeedsConnection, waitingButton } from '../useNeedsConnection';\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 connection = useNeedsConnection();\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 {...waitingButton(connection, 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 </ResponsiveDialogFooter>\n </form>\n </ResponsiveDialogContent>\n );\n}\n"],"mappings":";;;;;;;;;AA4BA,SAAgBA,EAAY,EAC1B,SACA,UACA,YACA,aACA,eAOC;CACD,OACE,kBAACC,GAAD;EAAwB;EAAM,eAAe,MAAUC,IAAO,KAAA,IAAYC,EAAQ;EAC/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AAK;IACrB,UAAArC,EAAG,yCAAyC,2BAA2B;GAClE,CAAA,IACN;GACJ,kBAACsC,GAAD,EAAA,UAAA,CACE,kBAACC,GAAD;IAAQ,MAAK;IAAS,SAAQ;IAAQ,SAAS3C;IAC5C,UAAAI,EAAG,2BAA2B,QAAQ;GACjC,CAAA,GACR,kBAACuC,GAAD;IACE,MAAK;IACC;IACN,GAAIC,EAActC,GAAYM,EAAK,KAAK,CAAC,CAAC,SAAS,CAAC;IACpD,eAAY;IAEX,UAAAT,IACGC,EAAG,kCAAkC,MAAM,IAC3CA,EAAG,kCAAkC,cAAc;GACjD,CAAA,CACc,EAAA,CAAA;EACpB;CACiB,CAAA,CAAA,EAAA,CAAA;AAE7B"}
@@ -1,148 +1,153 @@
1
1
  import { useNotificationTopics as e } from "../../hooks/useNotificationTopics.js";
2
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, WorkspacePage as y, useConfirm as b, useNotify as x } from "@burdenoff/fe-libs/ui";
3
+ import { useConnectionGate as n, useNeedsConnection as r, waitingItem as i } from "../useNeedsConnection.js";
4
+ import { useNotificationPaths as a } from "../../navigation-v2/paths.js";
5
+ import { AdminPageV2 as o } from "../../navigation-v2/AdminPageV2.js";
6
+ import { kindWord as s } from "./words.js";
7
+ import { TopicDialog as c } from "./TopicDialog.js";
8
+ import { StaleHint as l } from "../StaleHint.js";
9
+ import { useState as u } from "react";
10
+ import { Plus as d, Tag as f } from "lucide-react";
11
+ import { jsx as p, jsxs as m } from "react/jsx-runtime";
12
+ import { PageHeader as h } from "@burdenoff/fe-libs/chrome";
13
+ import { ActionMenu as g, Button as _, DataRows as v, EmptyState as y, IconTile as b, LoadError as x, StatusChip as S, WorkspacePage as C, useConfirm as w, useNotify as T } from "@burdenoff/fe-libs/ui";
12
14
  // src/v2/admin/TopicsPage.tsx
13
- var S = new Intl.NumberFormat();
14
- function C() {
15
- return /* @__PURE__ */ l(r, {
15
+ var E = new Intl.NumberFormat();
16
+ function D() {
17
+ return /* @__PURE__ */ p(o, {
16
18
  tool: "topics",
17
19
  back: !1,
18
- children: /* @__PURE__ */ l(w, {})
20
+ children: /* @__PURE__ */ p(O, {})
19
21
  });
20
22
  }
21
- function w() {
22
- let r = t(), C = n(), w = b(), T = x(), E = e(), [D, O] = o(null), k = async (e) => {
23
- let t = await E.updateTopic(e.id, { isActive: !e.isActive });
24
- T(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 }),
23
+ function O() {
24
+ let o = t(), D = r(), O = a(), k = w(), A = n(), j = T(), M = e(), [N, P] = u(null), F = async (e) => {
25
+ let t = await M.updateTopic(e.id, { isActive: !e.isActive });
26
+ j(t ? {
27
+ title: e.isActive ? o("notifications.v3.topics.turnedOff", "{{name}} is off", { name: e.name }) : o("notifications.v3.topics.turnedOn", "{{name}} is on", { name: e.name }),
26
28
  tone: "success"
27
29
  } : {
28
- title: r("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
30
+ title: o("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
29
31
  tone: "error"
30
32
  });
31
- }, A = async (e) => {
32
- if (!await w({
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"),
33
+ }, I = async (e) => {
34
+ if (!await k({
35
+ title: o("notifications.v3.topics.deleteTitle", "Delete {{name}}?", { name: e.name }),
36
+ description: o("notifications.v3.topics.deleteBody", "People stop being able to choose it in their settings."),
37
+ confirmLabel: o("notifications.v3.templates.delete", "Delete"),
36
38
  tone: "danger",
37
39
  typeToConfirm: e.name
38
- })) return;
39
- let t = await E.deleteTopic(e.id);
40
- T(t ? {
41
- title: r("notifications.v3.templates.deleted", "Deleted {{name}}", { name: e.name }),
40
+ }) || A()) return;
41
+ let t = await M.deleteTopic(e.id);
42
+ j(t ? {
43
+ title: o("notifications.v3.templates.deleted", "Deleted {{name}}", { name: e.name }),
42
44
  tone: "success"
43
45
  } : {
44
- title: r("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
46
+ title: o("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
45
47
  tone: "error"
46
48
  });
47
49
  };
48
- return /* @__PURE__ */ u(y, { children: [
49
- /* @__PURE__ */ l(d, {
50
+ return /* @__PURE__ */ m(C, { children: [
51
+ /* @__PURE__ */ p(h, {
50
52
  variant: "compact",
51
- title: r("notifications.v3.topics.title", "Topics"),
52
- description: r("notifications.v3.topics.purpose", "Groups of notifications people can turn on or off."),
53
+ title: o("notifications.v3.topics.title", "Topics"),
54
+ description: o("notifications.v3.topics.purpose", "Groups of notifications people can turn on or off."),
53
55
  back: {
54
- label: r("notifications.v3.title", "Notifications"),
55
- to: C.inbox
56
+ label: o("notifications.v3.title", "Notifications"),
57
+ to: O.inbox
56
58
  },
57
- primary: /* @__PURE__ */ u(p, {
58
- onClick: () => O("new"),
59
+ primary: /* @__PURE__ */ m(_, {
60
+ onClick: () => P("new"),
59
61
  "data-testid": "topics-new",
60
- children: [/* @__PURE__ */ l(s, { "aria-hidden": "true" }), r("notifications.v3.topics.new", "New topic")]
62
+ children: [/* @__PURE__ */ p(d, { "aria-hidden": "true" }), o("notifications.v3.topics.new", "New topic")]
61
63
  })
62
64
  }),
63
- E.error && E.topics.length === 0 ? /* @__PURE__ */ l(_, {
64
- what: r("notifications.v3.topics.title", "Topics"),
65
- error: E.error,
66
- onRetry: () => void E.refetch()
67
- }) : !E.isLoading && E.topics.length === 0 ? /* @__PURE__ */ l(h, {
65
+ /* @__PURE__ */ p(l, { loadedAt: M.dataUpdatedAt }),
66
+ M.error && M.topics.length === 0 ? /* @__PURE__ */ p(x, {
67
+ what: o("notifications.v3.topics.title", "Topics"),
68
+ error: M.error,
69
+ onRetry: () => void M.refetch()
70
+ }) : !M.isLoading && M.topics.length === 0 ? /* @__PURE__ */ p(y, {
68
71
  kind: "first-use",
69
- title: r("notifications.v3.topics.emptyTitle", "No topics yet"),
70
- description: r("notifications.v3.topics.emptyBody", "Topics let people choose what they hear about, like “Billing” or “Product news”."),
71
- action: /* @__PURE__ */ l(p, {
72
- onClick: () => O("new"),
73
- children: r("notifications.v3.topics.new", "New topic")
72
+ title: o("notifications.v3.topics.emptyTitle", "No topics yet"),
73
+ description: o("notifications.v3.topics.emptyBody", "Topics let people choose what they hear about, like “Billing” or “Product news”."),
74
+ action: /* @__PURE__ */ p(_, {
75
+ onClick: () => P("new"),
76
+ children: o("notifications.v3.topics.new", "New topic")
74
77
  })
75
- }) : /* @__PURE__ */ l(m, {
76
- items: E.topics,
77
- loading: E.isLoading && E.topics.length === 0,
78
+ }) : /* @__PURE__ */ p(v, {
79
+ items: M.topics,
80
+ loading: M.isLoading && M.topics.length === 0,
78
81
  skeletonRows: 4,
79
82
  getId: (e) => e.id,
80
- label: r("notifications.v3.topics.title", "Topics"),
83
+ label: o("notifications.v3.topics.title", "Topics"),
81
84
  lead: {
82
- header: r("notifications.v3.topics.topic", "Topic"),
83
- media: () => /* @__PURE__ */ l(g, {
85
+ header: o("notifications.v3.topics.topic", "Topic"),
86
+ media: () => /* @__PURE__ */ p(b, {
84
87
  size: "sm",
85
- children: /* @__PURE__ */ l(c, { "aria-hidden": "true" })
88
+ children: /* @__PURE__ */ p(f, { "aria-hidden": "true" })
86
89
  }),
87
90
  title: (e) => e.name,
88
91
  subtitle: (e) => e.description || void 0,
89
- onOpen: (e) => O(e)
92
+ onOpen: (e) => P(e)
90
93
  },
91
94
  columns: [
92
95
  {
93
96
  id: "people",
94
- header: r("notifications.v3.topics.people", "Following"),
95
- cell: (e) => S.format(e.subscriberCount ?? 0)
97
+ header: o("notifications.v3.topics.people", "Following"),
98
+ cell: (e) => E.format(e.subscriberCount ?? 0)
96
99
  },
97
100
  {
98
101
  id: "kind",
99
- header: r("notifications.v3.templates.kind", "About"),
100
- cell: (e) => i(e.type, r)
102
+ header: o("notifications.v3.templates.kind", "About"),
103
+ cell: (e) => s(e.type, o)
101
104
  },
102
105
  {
103
106
  id: "status",
104
- header: r("notifications.v3.templates.status", "Status"),
105
- cell: (e) => e.isActive ? /* @__PURE__ */ l(v, {
107
+ header: o("notifications.v3.templates.status", "Status"),
108
+ cell: (e) => e.isActive ? /* @__PURE__ */ p(S, {
106
109
  status: "ok",
107
- children: r("notifications.v3.on", "On")
108
- }) : /* @__PURE__ */ l(v, {
110
+ children: o("notifications.v3.on", "On")
111
+ }) : /* @__PURE__ */ p(S, {
109
112
  status: "paused",
110
- children: r("notifications.v3.off", "Off")
113
+ children: o("notifications.v3.off", "Off")
111
114
  })
112
115
  }
113
116
  ],
114
- actions: (e) => /* @__PURE__ */ l(f, {
117
+ actions: (e) => /* @__PURE__ */ p(g, {
115
118
  placement: "row",
116
- label: r("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
119
+ label: o("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
117
120
  items: [
118
121
  {
119
122
  id: "edit",
120
- label: r("notifications.v3.topics.edit", "Edit"),
121
- onSelect: () => O(e)
123
+ label: o("notifications.v3.topics.edit", "Edit"),
124
+ onSelect: () => P(e)
122
125
  },
123
126
  {
124
127
  id: "toggle",
125
- label: e.isActive ? r("notifications.v3.templates.turnOff", "Turn off") : r("notifications.v3.templates.turnOn", "Turn on"),
126
- onSelect: () => void k(e)
128
+ label: e.isActive ? o("notifications.v3.templates.turnOff", "Turn off") : o("notifications.v3.templates.turnOn", "Turn on"),
129
+ ...i(D),
130
+ onSelect: () => void F(e)
127
131
  },
128
132
  {
129
133
  id: "delete",
130
- label: r("notifications.v3.templates.delete", "Delete"),
134
+ label: o("notifications.v3.templates.delete", "Delete"),
131
135
  danger: !0,
132
- onSelect: () => void A(e)
136
+ ...i(D),
137
+ onSelect: () => void I(e)
133
138
  }
134
139
  ]
135
140
  })
136
141
  }),
137
- /* @__PURE__ */ l(a, {
138
- open: D !== null,
139
- topic: D === "new" ? null : D,
140
- onClose: () => O(null),
141
- onCreate: E.createTopic,
142
- onUpdate: E.updateTopic
142
+ /* @__PURE__ */ p(c, {
143
+ open: N !== null,
144
+ topic: N === "new" ? null : N,
145
+ onClose: () => P(null),
146
+ onCreate: M.createTopic,
147
+ onUpdate: M.updateTopic
143
148
  })
144
149
  ] });
145
150
  }
146
- export { C as TopicsPage };
151
+ export { D as TopicsPage };
147
152
 
148
153
  //# sourceMappingURL=TopicsPage.js.map
@@ -1 +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","WorkspacePage","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 WorkspacePage,\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 <WorkspacePage>\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 </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;AA6BA,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;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G,qCAAqC,SAAS;MACrD,gBAAgB,KAAKa,EAAOE,CAAK;KACnC;KACA;MACE,IAAI;MACJ,OAAOf,EAAG,qCAAqC,QAAQ;MACvD,QAAQ;MACR,gBAAgB,KAAKgB,EAAOD,CAAK;KACnC;IACF;GACD,CAAA;EAEJ,CAAA;EAEH,kBAACe,GAAD;GACE,MAAMpB,MAAY;GAClB,OAAOA,MAAY,QAAQ,OAAOA;GAClC,eAAeC,EAAW,IAAI;GAC9B,UAAUH,EAAO;GACjB,UAAUA,EAAO;EAClB,CAAA;CACY,EAAA,CAAA;AAEnB"}
1
+ {"version":3,"file":"TopicsPage.js","names":["COUNT","TopicsPage","AdminPageV2","TopicsList","tr","useTr","connection","useNeedsConnection","paths","useNotificationPaths","confirm","useConfirm","gate","useConnectionGate","notify","useNotify","topics","useNotificationTopics","editing","setEditing","useState","toggle","result","topic","remove","done","WorkspacePage","PageHeader","Button","Plus","StaleHint","LoadError","EmptyState","DataRows","IconTile","Tag","kindWord","StatusChip","ActionMenu","waitingItem","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 WorkspacePage,\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 { useConnectionGate, useNeedsConnection, waitingItem } from '../useNeedsConnection';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { kindWord } from './words';\nimport { TopicDialog } from './TopicDialog';\nimport { StaleHint } from '../StaleHint';\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 connection = useNeedsConnection();\n const paths = useNotificationPaths();\n const confirm = useConfirm();\n const gate = useConnectionGate();\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 // The connection may have dropped while the question was open (BOFF-18043).\n if (!yes || gate()) 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 <WorkspacePage>\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 <StaleHint loadedAt={topics.dataUpdatedAt} />\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 ...waitingItem(connection),\n onSelect: () => void toggle(topic),\n },\n {\n id: 'delete',\n label: tr('notifications.v3.templates.delete', 'Delete'),\n danger: true,\n ...waitingItem(connection),\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 </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA+BA,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,IAAaC,EAAmB,GAChCC,IAAQC,EAAqB,GAC7BC,IAAUC,EAAW,GACrBC,IAAOC,EAAkB,GACzBC,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,WACTnB,EAAG,qCAAqC,mBAAmB,EAAE,MAAMmB,EAAM,KAAK,CAAC,IAC/EnB,EAAG,oCAAoC,kBAAkB,EAAE,MAAMmB,EAAM,KAAK,CAAC;GACj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