@burdenoff/microfe-notification 2026.1130.2 → 2026.1202.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) 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 +100 -98
  23. package/dist/v2/InboxPage.js.map +1 -1
  24. package/dist/v2/PreferencesPage.js +98 -92
  25. package/dist/v2/PreferencesPage.js.map +1 -1
  26. package/dist/v2/StaleHint.d.ts +4 -0
  27. package/dist/v2/StaleHint.js +18 -0
  28. package/dist/v2/StaleHint.js.map +1 -0
  29. package/dist/v2/admin/DeliveryLogPage.js +71 -69
  30. package/dist/v2/admin/DeliveryLogPage.js.map +1 -1
  31. package/dist/v2/admin/TemplatesPage.js +135 -130
  32. package/dist/v2/admin/TemplatesPage.js.map +1 -1
  33. package/dist/v2/admin/TopicsPage.js +51 -49
  34. package/dist/v2/admin/TopicsPage.js.map +1 -1
  35. package/dist/v2/model/loadedAt.d.ts +5 -0
  36. package/dist/v2/model/loadedAt.js +8 -0
  37. package/dist/v2/model/loadedAt.js.map +1 -0
  38. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"DeliveryLogPage.js","names":["TONE_ICON","CheckCircle2","XCircle","Clock","COUNT","TONE_TEXT","DeliveryLogPage","details","useFeatureFlagDetails","paths","useNotificationPaths","on","AdminPageV2","DeliveryLog","Navigate","recipientOf","notification","tr","DeliveryCounts","useTr","StatusChip","counts","Segmented","tone","onTone","DeliveryLine","when","useWhenLabels","item","Icon","state","onOpen","channelWord","DeliveryDays","groupByDay","items","group","DeliveryEmpty","EmptyState","filtered","DeliveryLoading","Skeleton","index","admin","useNotificationAdmin","setTone","useState","openId","setOpenId","withState","useMemo","deliveryState","out","shown","empty","body","LoadError","WorkspacePage","PageHeader","NotificationDetailPanel"],"sources":["../../../src/v2/admin/DeliveryLogPage.tsx"],"sourcesContent":["/**\n * The delivery log (BOFF-16785, C2; the mockup's `ndelivery`), under fe-libs' `accountPagesV2`:\n * every notification sent, and whether it arrived. Counts first (delivered, didn't arrive, waiting),\n * then a line each, grouped by day: what was sent to whom, how, and what happened, with an icon and a\n * word. A line opens the notification's panel, read-only. Admins only (`AdminPageV2`), behind the\n * same flag as today (`notification.history`). Today's hook (`useNotificationAdmin`).\n */\nimport { useMemo, useState } from 'react';\nimport { Navigate } from 'react-router';\nimport { CheckCircle2, Clock, XCircle } from 'lucide-react';\nimport { useFeatureFlagDetails } from '@burdenoff/fe-libs/shared/feature-flags';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport {\n EmptyState,\n LoadError,\n Segmented,\n Skeleton,\n StatusChip,\n WorkspacePage,\n useWhenLabels,\n} from '@burdenoff/fe-libs/ui';\nimport { useNotificationAdmin } from '../../hooks/useNotificationAdmin';\nimport type { Notification } from '../../types';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { NotificationDetailPanel } from '../NotificationDetailPanel';\nimport { groupByDay } from '../model/days';\nimport { channelWord, deliveryState, type DeliveryTone } from './words';\n\ntype ToneFilter = 'any' | DeliveryTone;\n\nconst TONE_ICON = { ok: CheckCircle2, bad: XCircle, waiting: Clock } as const;\nconst COUNT = new Intl.NumberFormat();\nconst TONE_TEXT: Record<DeliveryTone, string> = {\n ok: 'text-status-success-text',\n bad: 'text-status-error-text',\n waiting: 'text-status-warning-text',\n};\n\nexport function DeliveryLogPage() {\n const details = useFeatureFlagDetails('notification.history');\n const paths = useNotificationPaths();\n const on = details ? Boolean(details.value) : false;\n // Someone without the permission sees the lock, whatever the flag says (alpha check BOFF-17355:\n // a member got today's inbox here). An admin while `notification.history` is off goes to the\n // inbox, as today, but the redesigned one, never today's page.\n return (\n <AdminPageV2 tool=\"deliveryLog\" back={false}>\n {on ? <DeliveryLog /> : <Navigate to={paths.inbox} replace />}\n </AdminPageV2>\n );\n}\n\nfunction recipientOf(\n notification: Notification,\n tr: (key: string, fallback: string) => string\n): string {\n return (\n notification.recipientEmail ||\n notification.recipientPhone ||\n tr('notifications.v3.log.inApp', 'someone in the app')\n );\n}\n\ntype LogItem = {\n notification: Notification;\n state: ReturnType<typeof deliveryState>;\n createdAt: string;\n};\n\nfunction DeliveryCounts({\n counts,\n tone,\n onTone,\n}: {\n counts: Record<DeliveryTone, number>;\n tone: ToneFilter;\n onTone: (tone: ToneFilter) => void;\n}) {\n const tr = useTr();\n return (\n <div className=\"flex flex-wrap items-center gap-2\" data-testid=\"log-counts\">\n <StatusChip status=\"ok\">\n {tr('notifications.v3.log.delivered', '{{count}} delivered', {\n count: COUNT.format(counts.ok),\n })}\n </StatusChip>\n <StatusChip status=\"bad\">\n {tr('notifications.v3.log.failed', '{{count}} didn’t arrive', {\n count: COUNT.format(counts.bad),\n })}\n </StatusChip>\n <StatusChip status=\"waiting\">\n {tr('notifications.v3.log.waiting', '{{count}} waiting', {\n count: COUNT.format(counts.waiting),\n })}\n </StatusChip>\n <span className=\"flex-1\" />\n <Segmented<ToneFilter>\n aria-label={tr('notifications.v3.log.show', 'Show')}\n value={tone}\n onValueChange={onTone}\n options={[\n { value: 'any', label: tr('notifications.v3.log.any', 'All') },\n { value: 'ok', label: tr('notifications.v3.delivery.delivered', 'Delivered') },\n { value: 'bad', label: tr('notifications.v3.delivery.failed', 'Didn’t arrive') },\n { value: 'waiting', label: tr('notifications.v3.log.waitingShort', 'Waiting') },\n ]}\n />\n </div>\n );\n}\n\nfunction DeliveryLine({ item, onOpen }: { item: LogItem; onOpen: (id: string) => void }) {\n const tr = useTr();\n const when = useWhenLabels();\n const { notification, state } = item;\n const Icon = TONE_ICON[state.tone];\n return (\n <li data-row-id={notification.id}>\n <button\n type=\"button\"\n className=\"flex w-full cursor-pointer items-center gap-3 border-0 bg-transparent px-3 py-2.5 text-left\"\n onClick={() => onOpen(notification.id)}\n >\n <Icon className={`size-4 shrink-0 ${TONE_TEXT[state.tone]}`} aria-hidden=\"true\" />\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-sm text-text-primary\">\n {tr('notifications.v3.log.line', '{{title}} → {{who}}', {\n title: notification.title,\n who: recipientOf(notification, tr),\n })}\n </span>\n <span className=\"block truncate text-xs text-text-secondary\">\n {channelWord(notification.channel, tr)} · {state.word}\n </span>\n </span>\n <time className=\"shrink-0 text-xs text-text-muted\" dateTime={notification.createdAt}>\n {when.moment(notification.createdAt)}\n </time>\n </button>\n </li>\n );\n}\n\nfunction DeliveryDays({ items, onOpen }: { items: LogItem[]; onOpen: (id: string) => void }) {\n const tr = useTr();\n return (\n <div className=\"flex flex-col gap-4\" data-testid=\"log-rows\">\n {groupByDay(items, tr).map((group) => (\n <section key={group.key} aria-label={group.label} className=\"flex flex-col gap-1\">\n <h2 className=\"m-0 px-1 text-xs font-medium text-text-muted\">{group.label}</h2>\n <ul className=\"m-0 flex list-none flex-col divide-y divide-border-subtle overflow-hidden rounded-lg border border-border-subtle bg-bg-surface p-0\">\n {group.items.map((item) => (\n <DeliveryLine key={item.notification.id} item={item} onOpen={onOpen} />\n ))}\n </ul>\n </section>\n ))}\n </div>\n );\n}\n\nfunction DeliveryEmpty({ filtered }: { filtered: boolean }) {\n const tr = useTr();\n return (\n <EmptyState\n kind={filtered ? 'filtered' : 'first-use'}\n title={\n filtered\n ? tr('notifications.v3.log.noneTitle', 'Nothing here')\n : tr('notifications.v3.log.emptyTitle', 'Nothing sent yet')\n }\n description={tr(\n 'notifications.v3.log.emptyBody',\n 'Each notification sent is listed here with what happened to it.'\n )}\n />\n );\n}\n\nfunction DeliveryLoading() {\n return (\n <div className=\"flex flex-col gap-2\" aria-busy=\"true\">\n {Array.from({ length: 6 }, (_, index) => (\n <Skeleton key={index} className=\"h-12 w-full rounded-lg\" />\n ))}\n </div>\n );\n}\n\nfunction DeliveryLog() {\n const tr = useTr();\n const paths = useNotificationPaths();\n const admin = useNotificationAdmin();\n const [tone, setTone] = useState<ToneFilter>('any');\n const [openId, setOpenId] = useState<string | null>(null);\n const withState = useMemo<LogItem[]>(\n () =>\n admin.notifications.map((notification) => ({\n notification,\n state: deliveryState(notification.deliveryStatus, tr),\n createdAt: notification.createdAt,\n })),\n [admin.notifications, tr]\n );\n const counts = useMemo(() => {\n const out = { ok: 0, bad: 0, waiting: 0 };\n for (const item of withState) out[item.state.tone] += 1;\n return out;\n }, [withState]);\n const shown = tone === 'any' ? withState : withState.filter((item) => item.state.tone === tone);\n const empty = withState.length === 0;\n\n let body = <DeliveryDays items={shown} onOpen={setOpenId} />;\n if (admin.error && empty) {\n body = (\n <LoadError\n what={tr('notifications.v3.log.title', 'Delivery log')}\n error={admin.error}\n onRetry={() => void admin.refetch()}\n />\n );\n } else if (admin.isLoading && empty) {\n body = <DeliveryLoading />;\n } else if (shown.length === 0) {\n body = <DeliveryEmpty filtered={tone !== 'any'} />;\n }\n\n return (\n <WorkspacePage>\n <PageHeader\n variant=\"compact\"\n title={tr('notifications.v3.log.title', 'Delivery log')}\n description={tr(\n 'notifications.v3.log.purpose',\n 'Every notification sent, and whether it arrived.'\n )}\n back={{ label: tr('notifications.v3.title', 'Notifications'), to: paths.inbox }}\n />\n <div className=\"flex flex-col gap-3\">\n <DeliveryCounts counts={counts} tone={tone} onTone={setTone} />\n {body}\n </div>\n <NotificationDetailPanel id={openId} onClose={() => setOpenId(null)} />\n </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgCA,IAAMA,IAAY;CAAE,IAAIC;CAAc,KAAKC;CAAS,SAASC;AAAM,GAC7DC,IAAQ,IAAI,KAAK,aAAa,GAC9BC,IAA0C;CAC9C,IAAI;CACJ,KAAK;CACL,SAAS;AACX;AAEA,SAAgBC,IAAkB;CAChC,IAAMC,IAAUC,EAAsB,sBAAsB,GACtDC,IAAQC,EAAqB,GAC7BC,IAAKJ,IAAU,EAAQA,EAAQ,QAAS;CAI9C,OACE,kBAACK,GAAD;EAAa,MAAK;EAAc,MAAM;EACnC,UAAAD,IAAK,kBAACE,GAAD,CAAc,CAAA,IAAI,kBAACC,GAAD;GAAU,IAAIL,EAAM;GAAO,SAAA;EAAS,CAAA;CACjD,CAAA;AAEjB;AAEA,SAASM,EACP,GACA,GACQ;CACR,OACEC,EAAa,kBACbA,EAAa,kBACbC,EAAG,8BAA8B,oBAAoB;AAEzD;AAQA,SAASC,EAAe,EACtB,WACA,SACA,aAKC;CACD,IAAMD,IAAKE,EAAM;CACjB,OACE,kBAAC,OAAD;EAAK,WAAU;EAAoC,eAAY;EAA/D,UAAA;GACE,kBAACC,GAAD;IAAY,QAAO;IAChB,UAAAH,EAAG,kCAAkC,uBAAuB,EAC3D,OAAOb,EAAM,OAAOiB,EAAO,EAAE,EAC/B,CAAC;GACS,CAAA;GACZ,kBAACD,GAAD;IAAY,QAAO;IAChB,UAAAH,EA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AAeC,EAAU,IAAI;EAAI,CAAA;CACzD,EAAA,CAAA;AAEnB"}
1
+ {"version":3,"file":"DeliveryLogPage.js","names":["TONE_ICON","CheckCircle2","XCircle","Clock","COUNT","TONE_TEXT","DeliveryLogPage","details","useFeatureFlagDetails","paths","useNotificationPaths","on","AdminPageV2","DeliveryLog","Navigate","recipientOf","notification","tr","DeliveryCounts","useTr","StatusChip","counts","Segmented","tone","onTone","DeliveryLine","when","useWhenLabels","item","Icon","state","onOpen","channelWord","DeliveryDays","groupByDay","items","group","DeliveryEmpty","EmptyState","filtered","DeliveryLoading","Skeleton","index","admin","useNotificationAdmin","setTone","useState","openId","setOpenId","withState","useMemo","deliveryState","out","shown","empty","body","LoadError","WorkspacePage","PageHeader","StaleHint","NotificationDetailPanel"],"sources":["../../../src/v2/admin/DeliveryLogPage.tsx"],"sourcesContent":["/**\n * The delivery log (BOFF-16785, C2; the mockup's `ndelivery`), under fe-libs' `accountPagesV2`:\n * every notification sent, and whether it arrived. Counts first (delivered, didn't arrive, waiting),\n * then a line each, grouped by day: what was sent to whom, how, and what happened, with an icon and a\n * word. A line opens the notification's panel, read-only. Admins only (`AdminPageV2`), behind the\n * same flag as today (`notification.history`). Today's hook (`useNotificationAdmin`).\n */\nimport { useMemo, useState } from 'react';\nimport { Navigate } from 'react-router';\nimport { CheckCircle2, Clock, XCircle } from 'lucide-react';\nimport { useFeatureFlagDetails } from '@burdenoff/fe-libs/shared/feature-flags';\nimport { PageHeader } from '@burdenoff/fe-libs/chrome';\nimport {\n EmptyState,\n LoadError,\n Segmented,\n Skeleton,\n StatusChip,\n WorkspacePage,\n useWhenLabels,\n} from '@burdenoff/fe-libs/ui';\nimport { useNotificationAdmin } from '../../hooks/useNotificationAdmin';\nimport type { Notification } from '../../types';\nimport { useTr } from '../../shared/hooks/useTr';\nimport { useNotificationPaths } from '../../navigation-v2/paths';\nimport { AdminPageV2 } from '../../navigation-v2/AdminPageV2';\nimport { NotificationDetailPanel } from '../NotificationDetailPanel';\nimport { groupByDay } from '../model/days';\nimport { channelWord, deliveryState, type DeliveryTone } from './words';\nimport { StaleHint } from '../StaleHint';\n\ntype ToneFilter = 'any' | DeliveryTone;\n\nconst TONE_ICON = { ok: CheckCircle2, bad: XCircle, waiting: Clock } as const;\nconst COUNT = new Intl.NumberFormat();\nconst TONE_TEXT: Record<DeliveryTone, string> = {\n ok: 'text-status-success-text',\n bad: 'text-status-error-text',\n waiting: 'text-status-warning-text',\n};\n\nexport function DeliveryLogPage() {\n const details = useFeatureFlagDetails('notification.history');\n const paths = useNotificationPaths();\n const on = details ? Boolean(details.value) : false;\n // Someone without the permission sees the lock, whatever the flag says (alpha check BOFF-17355:\n // a member got today's inbox here). An admin while `notification.history` is off goes to the\n // inbox, as today, but the redesigned one, never today's page.\n return (\n <AdminPageV2 tool=\"deliveryLog\" back={false}>\n {on ? <DeliveryLog /> : <Navigate to={paths.inbox} replace />}\n </AdminPageV2>\n );\n}\n\nfunction recipientOf(\n notification: Notification,\n tr: (key: string, fallback: string) => string\n): string {\n return (\n notification.recipientEmail ||\n notification.recipientPhone ||\n tr('notifications.v3.log.inApp', 'someone in the app')\n );\n}\n\ntype LogItem = {\n notification: Notification;\n state: ReturnType<typeof deliveryState>;\n createdAt: string;\n};\n\nfunction DeliveryCounts({\n counts,\n tone,\n onTone,\n}: {\n counts: Record<DeliveryTone, number>;\n tone: ToneFilter;\n onTone: (tone: ToneFilter) => void;\n}) {\n const tr = useTr();\n return (\n <div className=\"flex flex-wrap items-center gap-2\" data-testid=\"log-counts\">\n <StatusChip status=\"ok\">\n {tr('notifications.v3.log.delivered', '{{count}} delivered', {\n count: COUNT.format(counts.ok),\n })}\n </StatusChip>\n <StatusChip status=\"bad\">\n {tr('notifications.v3.log.failed', '{{count}} didn’t arrive', {\n count: COUNT.format(counts.bad),\n })}\n </StatusChip>\n <StatusChip status=\"waiting\">\n {tr('notifications.v3.log.waiting', '{{count}} waiting', {\n count: COUNT.format(counts.waiting),\n })}\n </StatusChip>\n <span className=\"flex-1\" />\n <Segmented<ToneFilter>\n aria-label={tr('notifications.v3.log.show', 'Show')}\n value={tone}\n onValueChange={onTone}\n options={[\n { value: 'any', label: tr('notifications.v3.log.any', 'All') },\n { value: 'ok', label: tr('notifications.v3.delivery.delivered', 'Delivered') },\n { value: 'bad', label: tr('notifications.v3.delivery.failed', 'Didn’t arrive') },\n { value: 'waiting', label: tr('notifications.v3.log.waitingShort', 'Waiting') },\n ]}\n />\n </div>\n );\n}\n\nfunction DeliveryLine({ item, onOpen }: { item: LogItem; onOpen: (id: string) => void }) {\n const tr = useTr();\n const when = useWhenLabels();\n const { notification, state } = item;\n const Icon = TONE_ICON[state.tone];\n return (\n <li data-row-id={notification.id}>\n <button\n type=\"button\"\n className=\"flex w-full cursor-pointer items-center gap-3 border-0 bg-transparent px-3 py-2.5 text-left\"\n onClick={() => onOpen(notification.id)}\n >\n <Icon className={`size-4 shrink-0 ${TONE_TEXT[state.tone]}`} aria-hidden=\"true\" />\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-sm text-text-primary\">\n {tr('notifications.v3.log.line', '{{title}} → {{who}}', {\n title: notification.title,\n who: recipientOf(notification, tr),\n })}\n </span>\n <span className=\"block truncate text-xs text-text-secondary\">\n {channelWord(notification.channel, tr)} · {state.word}\n </span>\n </span>\n <time className=\"shrink-0 text-xs text-text-muted\" dateTime={notification.createdAt}>\n {when.moment(notification.createdAt)}\n </time>\n </button>\n </li>\n );\n}\n\nfunction DeliveryDays({ items, onOpen }: { items: LogItem[]; onOpen: (id: string) => void }) {\n const tr = useTr();\n return (\n <div className=\"flex flex-col gap-4\" data-testid=\"log-rows\">\n {groupByDay(items, tr).map((group) => (\n <section key={group.key} aria-label={group.label} className=\"flex flex-col gap-1\">\n <h2 className=\"m-0 px-1 text-xs font-medium text-text-muted\">{group.label}</h2>\n <ul className=\"m-0 flex list-none flex-col divide-y divide-border-subtle overflow-hidden rounded-lg border border-border-subtle bg-bg-surface p-0\">\n {group.items.map((item) => (\n <DeliveryLine key={item.notification.id} item={item} onOpen={onOpen} />\n ))}\n </ul>\n </section>\n ))}\n </div>\n );\n}\n\nfunction DeliveryEmpty({ filtered }: { filtered: boolean }) {\n const tr = useTr();\n return (\n <EmptyState\n kind={filtered ? 'filtered' : 'first-use'}\n title={\n filtered\n ? tr('notifications.v3.log.noneTitle', 'Nothing here')\n : tr('notifications.v3.log.emptyTitle', 'Nothing sent yet')\n }\n description={tr(\n 'notifications.v3.log.emptyBody',\n 'Each notification sent is listed here with what happened to it.'\n )}\n />\n );\n}\n\nfunction DeliveryLoading() {\n return (\n <div className=\"flex flex-col gap-2\" aria-busy=\"true\">\n {Array.from({ length: 6 }, (_, index) => (\n <Skeleton key={index} className=\"h-12 w-full rounded-lg\" />\n ))}\n </div>\n );\n}\n\nfunction DeliveryLog() {\n const tr = useTr();\n const paths = useNotificationPaths();\n const admin = useNotificationAdmin();\n const [tone, setTone] = useState<ToneFilter>('any');\n const [openId, setOpenId] = useState<string | null>(null);\n const withState = useMemo<LogItem[]>(\n () =>\n admin.notifications.map((notification) => ({\n notification,\n state: deliveryState(notification.deliveryStatus, tr),\n createdAt: notification.createdAt,\n })),\n [admin.notifications, tr]\n );\n const counts = useMemo(() => {\n const out = { ok: 0, bad: 0, waiting: 0 };\n for (const item of withState) out[item.state.tone] += 1;\n return out;\n }, [withState]);\n const shown = tone === 'any' ? withState : withState.filter((item) => item.state.tone === tone);\n const empty = withState.length === 0;\n\n let body = <DeliveryDays items={shown} onOpen={setOpenId} />;\n if (admin.error && empty) {\n body = (\n <LoadError\n what={tr('notifications.v3.log.title', 'Delivery log')}\n error={admin.error}\n onRetry={() => void admin.refetch()}\n />\n );\n } else if (admin.isLoading && empty) {\n body = <DeliveryLoading />;\n } else if (shown.length === 0) {\n body = <DeliveryEmpty filtered={tone !== 'any'} />;\n }\n\n return (\n <WorkspacePage>\n <PageHeader\n variant=\"compact\"\n title={tr('notifications.v3.log.title', 'Delivery log')}\n description={tr(\n 'notifications.v3.log.purpose',\n 'Every notification sent, and whether it arrived.'\n )}\n back={{ label: tr('notifications.v3.title', 'Notifications'), to: paths.inbox }}\n />\n <StaleHint loadedAt={admin.dataUpdatedAt} />\n <div className=\"flex flex-col gap-3\">\n <DeliveryCounts counts={counts} tone={tone} onTone={setTone} />\n {body}\n </div>\n <NotificationDetailPanel id={openId} onClose={() => setOpenId(null)} />\n </WorkspacePage>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiCA,IAAMA,IAAY;CAAE,IAAIC;CAAc,KAAKC;CAAS,SAASC;AAAM,GAC7DC,IAAQ,IAAI,KAAK,aAAa,GAC9BC,IAA0C;CAC9C,IAAI;CACJ,KAAK;CACL,SAAS;AACX;AAEA,SAAgBC,IAAkB;CAChC,IAAMC,IAAUC,EAAsB,sBAAsB,GACtDC,IAAQC,EAAqB,GAC7BC,IAAKJ,IAAU,EAAQA,EAAQ,QAAS;CAI9C,OACE,kBAACK,GAAD;EAAa,MAAK;EAAc,MAAM;EACnC,UAAAD,IAAK,kBAACE,GAAD,CAAc,CAAA,IAAI,kBAACC,GAAD;GAAU,IAAIL,EAAM;GAAO,SAAA;EAAS,CAAA;CACjD,CAAA;AAEjB;AAEA,SAASM,EACP,GACA,GACQ;CACR,OACEC,EAAa,kBACbA,EAAa,kBACbC,EAAG,8BAA8B,oBAAoB;AAEzD;AAQA,SAASC,EAAe,EACtB,WACA,SACA,aAKC;CACD,IAAMD,IAAKE,EAAM;CACjB,OACE,kBAAC,OAAD;EAAK,WAAU;EAAoC,eAAY;EAA/D,UAAA;GACE,kBAACC,GAAD;IAAY,QAAO;IAChB,UAAAH,EAAG,kCAAkC,uBAAuB,EAC3D,OAAOb,EAAM,OAAOiB,EAAO,EAAE,EAC/B,CAAC;GACS,CAAA;GACZ,kBAACD,GAAD;IAAY,QAAO;IAChB,UAAAH,EAAG,+BAA+B,2BAA2B,EAC5D,OAAOb,EAAM,OAAOiB,EAAO,GAAG,EAChC,CAAC;GACS,CAAA;GACZ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zD,EAAA,CAAA;AAEnB"}
@@ -4,166 +4,171 @@ import { useNotificationPaths as n } from "../../navigation-v2/paths.js";
4
4
  import { AdminPageV2 as r } from "../../navigation-v2/AdminPageV2.js";
5
5
  import { channelWord as i, kindWord as a } from "./words.js";
6
6
  import { readDetails as o, toReadable as s } from "./templateText.js";
7
- import { useMemo as c, useState as l } from "react";
8
- import { Mail as u, Plus as d, Search as f } from "lucide-react";
9
- import { useNavigate as p } from "react-router";
10
- import { jsx as m, jsxs as h } from "react/jsx-runtime";
11
- import { PageHeader as g } from "@burdenoff/fe-libs/chrome";
12
- import { ActionMenu as _, Button as v, DataRows as y, EmptyState as b, IconTile as x, Input as S, LoadError as C, StatusChip as w, WorkspacePage as T, useConfirm as E, useNotify as D, useWhenLabels as O } from "@burdenoff/fe-libs/ui";
7
+ import { StaleHint as c } from "../StaleHint.js";
8
+ import { useMemo as l, useState as u } from "react";
9
+ import { Mail as d, Plus as f, Search as p } from "lucide-react";
10
+ import { useNavigate as m } from "react-router";
11
+ import { jsx as h, jsxs as g } from "react/jsx-runtime";
12
+ import { PageHeader as _ } from "@burdenoff/fe-libs/chrome";
13
+ import { ActionMenu as v, Button as y, DataRows as b, EmptyState as x, IconTile as S, Input as C, LoadError as w, StatusChip as T, WorkspacePage as E, useConfirm as D, useNotify as O, useWhenLabels as k } from "@burdenoff/fe-libs/ui";
13
14
  // src/v2/admin/TemplatesPage.tsx
14
- function k() {
15
- return /* @__PURE__ */ m(r, {
15
+ function A() {
16
+ return /* @__PURE__ */ h(r, {
16
17
  tool: "templates",
17
18
  back: !1,
18
- children: /* @__PURE__ */ m(A, {})
19
+ children: /* @__PURE__ */ h(j, {})
19
20
  });
20
21
  }
21
- function A() {
22
- let r = t(), k = p(), A = n(), j = E(), M = D(), N = O(), P = e(), [F, I] = l(""), L = c(() => {
23
- let e = F.trim().toLowerCase(), t = P.allTemplates;
22
+ function j() {
23
+ let r = t(), A = m(), j = n(), M = D(), N = O(), P = k(), F = e(), [I, L] = u(""), R = l(() => {
24
+ let e = I.trim().toLowerCase(), t = F.allTemplates;
24
25
  return e ? t.filter((t) => t.name.toLowerCase().includes(e) || (t.subject ?? "").toLowerCase().includes(e)) : t;
25
- }, [F, P.allTemplates]), R = async (e) => {
26
+ }, [I, F.allTemplates]), z = async (e) => {
26
27
  try {
27
- await P.updateTemplate(e.id, { enabled: !e.enabled }), M({
28
+ await F.updateTemplate(e.id, { enabled: !e.enabled }), N({
28
29
  title: e.enabled ? r("notifications.v3.templates.turnedOff", "{{name}} is off", { name: e.name }) : r("notifications.v3.templates.turnedOn", "{{name}} is on", { name: e.name }),
29
30
  tone: "success"
30
- }), await P.refetch();
31
+ }), await F.refetch();
31
32
  } catch {
32
- M({
33
+ N({
33
34
  title: r("notifications.v3.templates.saveFailed", "Couldn’t save. Try again."),
34
35
  tone: "error"
35
36
  });
36
37
  }
37
- }, z = async (e) => {
38
- if (await j({
38
+ }, B = async (e) => {
39
+ if (await M({
39
40
  title: r("notifications.v3.templates.deleteTitle", "Delete {{name}}?", { name: e.name }),
40
41
  description: r("notifications.v3.templates.deleteBody", "Anything that sends this template stops sending it. Messages already sent stay as they are."),
41
42
  confirmLabel: r("notifications.v3.templates.delete", "Delete"),
42
43
  tone: "danger",
43
44
  typeToConfirm: e.name
44
45
  })) try {
45
- await P.deleteTemplate(e.id), M({
46
+ await F.deleteTemplate(e.id), N({
46
47
  title: r("notifications.v3.templates.deleted", "Deleted {{name}}", { name: e.name }),
47
48
  tone: "success"
48
- }), await P.refetch();
49
+ }), await F.refetch();
49
50
  } catch {
50
- M({
51
+ N({
51
52
  title: r("notifications.v3.templates.deleteFailed", "Couldn’t delete it. Try again."),
52
53
  tone: "error"
53
54
  });
54
55
  }
55
56
  };
56
- return /* @__PURE__ */ h(T, { children: [/* @__PURE__ */ m(g, {
57
- variant: "compact",
58
- title: r("notifications.v3.templates.title", "Templates"),
59
- description: r("notifications.v3.templates.purpose", "Messages written once and sent many times: what they say, and how they’re sent."),
60
- back: {
61
- label: r("notifications.v3.title", "Notifications"),
62
- to: A.inbox
63
- },
64
- primary: /* @__PURE__ */ h(v, {
65
- onClick: () => k(A.newTemplate),
66
- "data-testid": "templates-new",
67
- children: [/* @__PURE__ */ m(d, { "aria-hidden": "true" }), r("notifications.v3.templates.new", "New template")]
68
- })
69
- }), /* @__PURE__ */ h("div", {
70
- className: "flex flex-col gap-3",
71
- children: [/* @__PURE__ */ h("label", {
72
- className: "relative block max-w-md",
73
- children: [
74
- /* @__PURE__ */ m("span", {
75
- className: "sr-only",
76
- children: r("notifications.v3.templates.search", "Search templates")
77
- }),
78
- /* @__PURE__ */ m(f, {
79
- className: "pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-text-muted",
80
- "aria-hidden": "true"
81
- }),
82
- /* @__PURE__ */ m(S, {
83
- type: "search",
84
- className: "pl-9",
85
- value: F,
86
- placeholder: r("notifications.v3.templates.search", "Search templates"),
87
- onChange: (e) => I(e.target.value)
88
- })
89
- ]
90
- }), P.error && L.length === 0 ? /* @__PURE__ */ m(C, {
91
- what: r("notifications.v3.templates.title", "Templates"),
92
- error: P.error,
93
- onRetry: () => void P.refetch()
94
- }) : !P.isLoading && L.length === 0 ? F.trim() ? /* @__PURE__ */ m(b, {
95
- kind: "no-results",
96
- title: r("notifications.v3.templates.noMatch", "No templates match"),
97
- description: r("notifications.v3.empty.searchBody", "Try other words.")
98
- }) : /* @__PURE__ */ m(b, {
99
- kind: "first-use",
100
- title: r("notifications.v3.templates.emptyTitle", "No templates yet"),
101
- description: r("notifications.v3.templates.emptyBody", "A template is a message you write once, like a welcome email, and send many times."),
102
- action: /* @__PURE__ */ m(v, {
103
- onClick: () => k(A.newTemplate),
104
- children: r("notifications.v3.templates.new", "New template")
105
- })
106
- }) : /* @__PURE__ */ m(y, {
107
- items: L,
108
- loading: P.isLoading && L.length === 0,
109
- skeletonRows: 5,
110
- getId: (e) => e.id,
111
- label: r("notifications.v3.templates.title", "Templates"),
112
- lead: {
113
- header: r("notifications.v3.templates.template", "Template"),
114
- media: () => /* @__PURE__ */ m(x, {
115
- size: "sm",
116
- children: /* @__PURE__ */ m(u, { "aria-hidden": "true" })
117
- }),
118
- title: (e) => e.name,
119
- subtitle: (e) => e.subject ? s(e.subject, o(e.variables)) : void 0,
120
- onOpen: (e) => k(A.template(e.slug))
57
+ return /* @__PURE__ */ g(E, { children: [
58
+ /* @__PURE__ */ h(_, {
59
+ variant: "compact",
60
+ title: r("notifications.v3.templates.title", "Templates"),
61
+ description: r("notifications.v3.templates.purpose", "Messages written once and sent many times: what they say, and how they’re sent."),
62
+ back: {
63
+ label: r("notifications.v3.title", "Notifications"),
64
+ to: j.inbox
121
65
  },
122
- columns: [
123
- {
124
- id: "kind",
125
- header: r("notifications.v3.templates.kind", "About"),
126
- cell: (e) => a(e.type, r)
127
- },
128
- {
129
- id: "channel",
130
- header: r("notifications.v3.templates.channel", "Sent by"),
131
- cell: (e) => i(e.channel, r)
132
- },
133
- {
134
- id: "edited",
135
- header: r("notifications.v3.templates.edited", "Edited"),
136
- cell: (e) => N.moment(e.updatedAt)
137
- },
138
- {
139
- id: "status",
140
- header: r("notifications.v3.templates.status", "Status"),
141
- cell: (e) => e.enabled ? /* @__PURE__ */ m(w, {
142
- status: "ok",
143
- children: r("notifications.v3.on", "On")
144
- }) : /* @__PURE__ */ m(w, {
145
- status: "paused",
146
- children: r("notifications.v3.off", "Off")
147
- })
148
- }
149
- ],
150
- actions: (e) => /* @__PURE__ */ m(_, {
151
- placement: "row",
152
- label: r("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
153
- items: [{
154
- id: "toggle",
155
- label: e.enabled ? r("notifications.v3.templates.turnOff", "Turn off") : r("notifications.v3.templates.turnOn", "Turn on"),
156
- onSelect: () => void R(e)
157
- }, {
158
- id: "delete",
159
- label: r("notifications.v3.templates.delete", "Delete"),
160
- danger: !0,
161
- onSelect: () => void z(e)
162
- }]
66
+ primary: /* @__PURE__ */ g(y, {
67
+ onClick: () => A(j.newTemplate),
68
+ "data-testid": "templates-new",
69
+ children: [/* @__PURE__ */ h(f, { "aria-hidden": "true" }), r("notifications.v3.templates.new", "New template")]
163
70
  })
164
- })]
165
- })] });
71
+ }),
72
+ /* @__PURE__ */ h(c, { loadedAt: F.dataUpdatedAt }),
73
+ /* @__PURE__ */ g("div", {
74
+ className: "flex flex-col gap-3",
75
+ children: [/* @__PURE__ */ g("label", {
76
+ className: "relative block max-w-md",
77
+ children: [
78
+ /* @__PURE__ */ h("span", {
79
+ className: "sr-only",
80
+ children: r("notifications.v3.templates.search", "Search templates")
81
+ }),
82
+ /* @__PURE__ */ h(p, {
83
+ className: "pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-text-muted",
84
+ "aria-hidden": "true"
85
+ }),
86
+ /* @__PURE__ */ h(C, {
87
+ type: "search",
88
+ className: "pl-9",
89
+ value: I,
90
+ placeholder: r("notifications.v3.templates.search", "Search templates"),
91
+ onChange: (e) => L(e.target.value)
92
+ })
93
+ ]
94
+ }), F.error && R.length === 0 ? /* @__PURE__ */ h(w, {
95
+ what: r("notifications.v3.templates.title", "Templates"),
96
+ error: F.error,
97
+ onRetry: () => void F.refetch()
98
+ }) : !F.isLoading && R.length === 0 ? I.trim() ? /* @__PURE__ */ h(x, {
99
+ kind: "no-results",
100
+ title: r("notifications.v3.templates.noMatch", "No templates match"),
101
+ description: r("notifications.v3.empty.searchBody", "Try other words.")
102
+ }) : /* @__PURE__ */ h(x, {
103
+ kind: "first-use",
104
+ title: r("notifications.v3.templates.emptyTitle", "No templates yet"),
105
+ description: r("notifications.v3.templates.emptyBody", "A template is a message you write once, like a welcome email, and send many times."),
106
+ action: /* @__PURE__ */ h(y, {
107
+ onClick: () => A(j.newTemplate),
108
+ children: r("notifications.v3.templates.new", "New template")
109
+ })
110
+ }) : /* @__PURE__ */ h(b, {
111
+ items: R,
112
+ loading: F.isLoading && R.length === 0,
113
+ skeletonRows: 5,
114
+ getId: (e) => e.id,
115
+ label: r("notifications.v3.templates.title", "Templates"),
116
+ lead: {
117
+ header: r("notifications.v3.templates.template", "Template"),
118
+ media: () => /* @__PURE__ */ h(S, {
119
+ size: "sm",
120
+ children: /* @__PURE__ */ h(d, { "aria-hidden": "true" })
121
+ }),
122
+ title: (e) => e.name,
123
+ subtitle: (e) => e.subject ? s(e.subject, o(e.variables)) : void 0,
124
+ onOpen: (e) => A(j.template(e.slug))
125
+ },
126
+ columns: [
127
+ {
128
+ id: "kind",
129
+ header: r("notifications.v3.templates.kind", "About"),
130
+ cell: (e) => a(e.type, r)
131
+ },
132
+ {
133
+ id: "channel",
134
+ header: r("notifications.v3.templates.channel", "Sent by"),
135
+ cell: (e) => i(e.channel, r)
136
+ },
137
+ {
138
+ id: "edited",
139
+ header: r("notifications.v3.templates.edited", "Edited"),
140
+ cell: (e) => P.moment(e.updatedAt)
141
+ },
142
+ {
143
+ id: "status",
144
+ header: r("notifications.v3.templates.status", "Status"),
145
+ cell: (e) => e.enabled ? /* @__PURE__ */ h(T, {
146
+ status: "ok",
147
+ children: r("notifications.v3.on", "On")
148
+ }) : /* @__PURE__ */ h(T, {
149
+ status: "paused",
150
+ children: r("notifications.v3.off", "Off")
151
+ })
152
+ }
153
+ ],
154
+ actions: (e) => /* @__PURE__ */ h(v, {
155
+ placement: "row",
156
+ label: r("notifications.v3.templates.actionsFor", "Actions for {{name}}", { name: e.name }),
157
+ items: [{
158
+ id: "toggle",
159
+ label: e.enabled ? r("notifications.v3.templates.turnOff", "Turn off") : r("notifications.v3.templates.turnOn", "Turn on"),
160
+ onSelect: () => void z(e)
161
+ }, {
162
+ id: "delete",
163
+ label: r("notifications.v3.templates.delete", "Delete"),
164
+ danger: !0,
165
+ onSelect: () => void B(e)
166
+ }]
167
+ })
168
+ })]
169
+ })
170
+ ] });
166
171
  }
167
- export { k as TemplatesPage };
172
+ export { A as TemplatesPage };
168
173
 
169
174
  //# sourceMappingURL=TemplatesPage.js.map
@@ -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,I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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","StaleHint","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';\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 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 <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 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":";;;;;;;;;;;;;;AAmCA,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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