@eifi1/ui-kit 0.45.0 → 0.46.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.
- package/README.md +26 -14
- package/dist/admin/admin-area-labels.d.ts +9 -0
- package/dist/admin/admin-area-labels.js +5 -1
- package/dist/admin/admin-area-labels.js.map +1 -1
- package/dist/admin/admin-overview.d.ts +16 -1
- package/dist/admin/admin-overview.js +12 -1
- package/dist/admin/admin-overview.js.map +1 -1
- package/dist/admin/mail-test-card.d.ts +3 -2
- package/dist/admin/mail-test-card.js +3 -1
- package/dist/admin/mail-test-card.js.map +1 -1
- package/dist/admin/user-roster.d.ts +6 -2
- package/dist/admin/user-roster.js +7 -3
- package/dist/admin/user-roster.js.map +1 -1
- package/dist/components/appearance-labels.d.ts +10 -0
- package/dist/components/appearance-labels.js +6 -1
- package/dist/components/appearance-labels.js.map +1 -1
- package/dist/components/data-table-column-settings.js +2 -2
- package/dist/components/data-table-column-settings.js.map +1 -1
- package/dist/components/data-table-head.js +2 -2
- package/dist/components/data-table-head.js.map +1 -1
- package/dist/components/data-table-row-actions.d.ts +35 -2
- package/dist/components/data-table-row-actions.js +98 -5
- package/dist/components/data-table-row-actions.js.map +1 -1
- package/dist/components/data-table-shared.js +9 -2
- package/dist/components/data-table-shared.js.map +1 -1
- package/dist/components/data-table.d.ts +58 -2
- package/dist/components/data-table.js +11 -4
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-format-setting.d.ts +29 -0
- package/dist/components/date-format-setting.js +36 -0
- package/dist/components/date-format-setting.js.map +1 -0
- package/dist/components/row-actions.d.ts +12 -5
- package/dist/components/row-actions.js +11 -4
- package/dist/components/row-actions.js.map +1 -1
- package/dist/components/swipeable-row.d.ts +8 -0
- package/dist/components/swipeable-row.js.map +1 -1
- package/dist/components/tabs.d.ts +3 -2
- package/dist/components/tabs.js +1 -1
- package/dist/components/tabs.js.map +1 -1
- package/dist/components/translation-review-editor.js +1 -0
- package/dist/components/translation-review-editor.js.map +1 -1
- package/dist/components/translation-review-labels.d.ts +5 -0
- package/dist/components/translation-review-labels.js +2 -0
- package/dist/components/translation-review-labels.js.map +1 -1
- package/dist/components/translation-review.d.ts +18 -8
- package/dist/components/translation-review.js +67 -8
- package/dist/components/translation-review.js.map +1 -1
- package/dist/components/write-lock-labels.js +2 -1
- package/dist/components/write-lock-labels.js.map +1 -1
- package/dist/components/write-lock.d.ts +33 -3
- package/dist/components/write-lock.js +9 -0
- package/dist/components/write-lock.js.map +1 -1
- package/dist/data-table.d.ts +2 -1
- package/dist/data-table.js +2 -0
- package/dist/data-table.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/feedback/feedback-row-detail.d.ts +4 -2
- package/dist/feedback/feedback-row-detail.js +17 -26
- package/dist/feedback/feedback-row-detail.js.map +1 -1
- package/dist/feedback/feedback-swipe.d.ts +18 -0
- package/dist/feedback/feedback-swipe.js +10 -1
- package/dist/feedback/feedback-swipe.js.map +1 -1
- package/dist/i18n/german.js +41 -5
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +12 -1
- package/dist/i18n/kit-labels.js +8 -2
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +40 -6
- package/dist/i18n/locales/en.js.map +2 -2
- package/dist/i18n/locales/es.js +41 -5
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +41 -5
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +41 -5
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +41 -5
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +41 -5
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +3 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.js +38 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/date-format.d.ts +81 -0
- package/dist/lib/date-format.js +56 -0
- package/dist/lib/date-format.js.map +1 -0
- package/dist/lib/format.d.ts +3 -0
- package/dist/lib/format.js +5 -4
- package/dist/lib/format.js.map +1 -1
- package/dist/notifications/device-zone-report.d.ts +34 -0
- package/dist/notifications/device-zone-report.js +31 -0
- package/dist/notifications/device-zone-report.js.map +1 -0
- package/dist/notifications/feedback-notification-types-labels.d.ts +7 -1
- package/dist/notifications/feedback-notification-types-labels.js +4 -1
- package/dist/notifications/feedback-notification-types-labels.js.map +1 -1
- package/dist/notifications/feedback-notification-types.d.ts +24 -5
- package/dist/notifications/feedback-notification-types.js +7 -2
- package/dist/notifications/feedback-notification-types.js.map +1 -1
- package/dist/notifications/notification-bell.d.ts +33 -0
- package/dist/notifications/notification-bell.js +74 -0
- package/dist/notifications/notification-bell.js.map +1 -0
- package/dist/notifications/notification-inbox.d.ts +86 -0
- package/dist/notifications/notification-inbox.js +206 -0
- package/dist/notifications/notification-inbox.js.map +1 -0
- package/dist/notifications/notification-types-setting.d.ts +6 -4
- package/dist/notifications/notification-types-setting.js +103 -45
- package/dist/notifications/notification-types-setting.js.map +1 -1
- package/dist/notifications/notification-types.d.ts +19 -7
- package/dist/notifications/notifications-labels.d.ts +44 -8
- package/dist/notifications/notifications-labels.js +18 -1
- package/dist/notifications/notifications-labels.js.map +1 -1
- package/dist/notifications/push-devices-setting.d.ts +20 -3
- package/dist/notifications/push-devices-setting.js +93 -33
- package/dist/notifications/push-devices-setting.js.map +1 -1
- package/dist/notifications/push-worker.d.ts +108 -0
- package/dist/notifications/push-worker.js +62 -0
- package/dist/notifications/push-worker.js.map +1 -0
- package/dist/notifications/quiet-hours-setting.d.ts +29 -17
- package/dist/notifications/quiet-hours-setting.js +9 -41
- package/dist/notifications/quiet-hours-setting.js.map +1 -1
- package/dist/notifications/time-zone-select.d.ts +8 -4
- package/dist/notifications/time-zone-select.js +2 -7
- package/dist/notifications/time-zone-select.js.map +1 -1
- package/dist/notifications/use-push-device.d.ts +4 -17
- package/dist/notifications/use-push-device.js +7 -15
- package/dist/notifications/use-push-device.js.map +1 -1
- package/dist/offline/local-first.d.ts +42 -0
- package/dist/offline/local-first.js +53 -0
- package/dist/offline/local-first.js.map +1 -0
- package/dist/offline/query-persistence.d.ts +26 -1
- package/dist/offline/query-persistence.js +27 -23
- package/dist/offline/query-persistence.js.map +1 -1
- package/dist/offline/service-worker-updates.d.ts +46 -0
- package/dist/offline/service-worker-updates.js +39 -0
- package/dist/offline/service-worker-updates.js.map +1 -0
- package/dist/offline.d.ts +5 -2
- package/dist/offline.js +12 -2
- package/dist/offline.js.map +1 -1
- package/dist/push-worker.d.ts +2 -0
- package/dist/push-worker.js +14 -0
- package/dist/push-worker.js.map +1 -0
- package/dist/shell/account-menu-text-size.d.ts +33 -0
- package/dist/shell/account-menu-text-size.js +51 -0
- package/dist/shell/account-menu-text-size.js.map +1 -0
- package/dist/shell/top-bar-actions.d.ts +6 -2
- package/dist/shell/top-bar-actions.js +1 -0
- package/dist/shell/top-bar-actions.js.map +1 -1
- package/dist/shell.d.ts +2 -0
- package/dist/shell.js +2 -0
- package/dist/shell.js.map +1 -1
- package/dist/sync/db.d.ts +93 -0
- package/dist/sync/db.js +33 -0
- package/dist/sync/db.js.map +1 -0
- package/dist/sync/engine.d.ts +126 -0
- package/dist/sync/engine.js +474 -0
- package/dist/sync/engine.js.map +1 -0
- package/dist/sync/hooks.d.ts +35 -0
- package/dist/sync/hooks.js +67 -0
- package/dist/sync/hooks.js.map +1 -0
- package/dist/sync/testing.d.ts +28 -0
- package/dist/sync/testing.js +41 -0
- package/dist/sync/testing.js.map +1 -0
- package/dist/sync/wire.d.ts +50 -0
- package/dist/sync/wire.js +2 -0
- package/dist/sync/wire.js.map +1 -0
- package/dist/sync.d.ts +7 -0
- package/dist/sync.js +25 -0
- package/dist/sync.js.map +1 -0
- package/dist/tour/tour-labels.js +1 -0
- package/dist/tour/tour-labels.js.map +1 -1
- package/dist/tour/tour.d.ts +30 -0
- package/dist/tour/tour.js +50 -6
- package/dist/tour/tour.js.map +1 -1
- package/package.json +19 -1
- package/src/admin/admin-area-labels.ts +13 -0
- package/src/admin/admin-overview.tsx +37 -2
- package/src/admin/mail-test-card.tsx +7 -3
- package/src/admin/user-roster.tsx +12 -3
- package/src/components/appearance-labels.ts +16 -0
- package/src/components/data-table-column-settings.tsx +2 -2
- package/src/components/data-table-head.tsx +2 -2
- package/src/components/data-table-row-actions.tsx +145 -5
- package/src/components/data-table-shared.tsx +21 -2
- package/src/components/data-table.tsx +68 -6
- package/src/components/date-format-setting.tsx +64 -0
- package/src/components/row-actions.tsx +33 -9
- package/src/components/swipeable-row.tsx +8 -0
- package/src/components/tabs.tsx +4 -3
- package/src/components/translation-review-editor.tsx +2 -0
- package/src/components/translation-review-labels.ts +7 -0
- package/src/components/translation-review.tsx +105 -15
- package/src/components/write-lock-labels.ts +1 -0
- package/src/components/write-lock.tsx +36 -3
- package/src/data-table.ts +4 -0
- package/src/feedback/feedback-row-detail.tsx +18 -23
- package/src/feedback/feedback-swipe.tsx +28 -1
- package/src/i18n/german.ts +44 -4
- package/src/i18n/kit-labels.tsx +18 -1
- package/src/i18n/locales/en.ts +1 -0
- package/src/i18n/locales/es.ts +44 -4
- package/src/i18n/locales/fr.ts +44 -4
- package/src/i18n/locales/hu.ts +44 -4
- package/src/i18n/locales/it.ts +44 -4
- package/src/i18n/locales/zh.ts +44 -2
- package/src/i18n/review.ts +3 -1
- package/src/index.ts +50 -1
- package/src/lib/date-format.ts +151 -0
- package/src/lib/format.ts +10 -4
- package/src/notifications/device-zone-report.ts +67 -0
- package/src/notifications/feedback-notification-types-labels.ts +10 -1
- package/src/notifications/feedback-notification-types.ts +30 -5
- package/src/notifications/notification-bell.tsx +116 -0
- package/src/notifications/notification-inbox.tsx +314 -0
- package/src/notifications/notification-types-setting.tsx +151 -55
- package/src/notifications/notification-types.ts +20 -8
- package/src/notifications/notifications-labels.ts +72 -12
- package/src/notifications/push-devices-setting.tsx +123 -34
- package/src/notifications/push-worker.ts +160 -0
- package/src/notifications/quiet-hours-setting.tsx +41 -58
- package/src/notifications/time-zone-select.tsx +9 -10
- package/src/notifications/use-push-device.ts +20 -33
- package/src/offline/local-first.ts +100 -0
- package/src/offline/query-persistence.ts +57 -24
- package/src/offline/service-worker-updates.ts +81 -0
- package/src/offline.ts +7 -1
- package/src/push-worker.ts +25 -0
- package/src/shell/account-menu-text-size.tsx +77 -0
- package/src/shell/top-bar-actions.tsx +6 -1
- package/src/shell.ts +3 -0
- package/src/sync/db.ts +125 -0
- package/src/sync/engine.ts +701 -0
- package/src/sync/hooks.ts +98 -0
- package/src/sync/testing.ts +73 -0
- package/src/sync/wire.ts +61 -0
- package/src/sync.ts +29 -0
- package/src/tour/tour-labels.ts +1 -0
- package/src/tour/tour.tsx +100 -7
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { Bell, CheckCheck, Trash2 } from "lucide-react";
|
|
5
|
+
import { useKitLabels } from "../i18n/kit-labels.js";
|
|
6
|
+
import { DEFAULT_COMMON_LABELS } from "../i18n/shared-labels.js";
|
|
7
|
+
import { cn } from "../lib/cn.js";
|
|
8
|
+
import { useKitFormat } from "../lib/format.js";
|
|
9
|
+
import { Button } from "../components/button.js";
|
|
10
|
+
import { Card } from "../components/card.js";
|
|
11
|
+
import { EmptyState } from "../components/empty-state.js";
|
|
12
|
+
import { IconButton } from "../components/icon-button.js";
|
|
13
|
+
import { List, ListItem } from "../components/list.js";
|
|
14
|
+
import { Skeleton } from "../components/skeleton.js";
|
|
15
|
+
import { COMMIT_EXCEPT_BILLING } from "../components/write-lock.js";
|
|
16
|
+
import { SettingsCardTitle } from "../settings/settings-heading.js";
|
|
17
|
+
import { settle, useMounted } from "../account/account-parts.js";
|
|
18
|
+
import { describeFailure, FailureLine, useNotificationsLabels } from "./notification-parts.js";
|
|
19
|
+
function NotificationInbox({
|
|
20
|
+
items,
|
|
21
|
+
unreadCount,
|
|
22
|
+
loading,
|
|
23
|
+
onMarkRead,
|
|
24
|
+
onClear,
|
|
25
|
+
onOpen,
|
|
26
|
+
icon,
|
|
27
|
+
hasMore = false,
|
|
28
|
+
onLoadMore,
|
|
29
|
+
loadingMore = false,
|
|
30
|
+
formatDate: formatDateProp,
|
|
31
|
+
title,
|
|
32
|
+
describeError,
|
|
33
|
+
labels: labelsProp,
|
|
34
|
+
className,
|
|
35
|
+
...rest
|
|
36
|
+
}) {
|
|
37
|
+
const labels = useNotificationsLabels(labelsProp);
|
|
38
|
+
const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
|
|
39
|
+
const { formatDate } = useKitFormat();
|
|
40
|
+
const [asking, setAsking] = useState(false);
|
|
41
|
+
const [busy, setBusy] = useState(null);
|
|
42
|
+
const [failure, setFailure] = useState(null);
|
|
43
|
+
const mounted = useMounted();
|
|
44
|
+
const headingId = useId();
|
|
45
|
+
const cancelRef = useRef(null);
|
|
46
|
+
const clearRef = useRef(null);
|
|
47
|
+
const [returning, setReturning] = useState(false);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (asking) cancelRef.current?.focus();
|
|
50
|
+
else if (returning) clearRef.current?.focus();
|
|
51
|
+
}, [asking, returning]);
|
|
52
|
+
const timeOf = (iso) => formatDateProp ? formatDateProp(iso) : formatDate(iso, "dateTime");
|
|
53
|
+
const iconOf = (type) => icon?.(type) ?? Bell;
|
|
54
|
+
const run = (which, call, after) => {
|
|
55
|
+
setBusy(which);
|
|
56
|
+
setFailure(null);
|
|
57
|
+
settle(call).then(
|
|
58
|
+
() => {
|
|
59
|
+
if (!mounted.current) return;
|
|
60
|
+
setBusy(null);
|
|
61
|
+
after?.();
|
|
62
|
+
},
|
|
63
|
+
(error) => {
|
|
64
|
+
if (!mounted.current) return;
|
|
65
|
+
setBusy(null);
|
|
66
|
+
setFailure(describeFailure(describeError?.(error, which === "read" ? "readAll" : "clear"), labels.failed));
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
const markOne = (item) => {
|
|
71
|
+
if (item.read_at !== null) return;
|
|
72
|
+
settle(() => onMarkRead([item.id])).catch((error) => {
|
|
73
|
+
if (mounted.current) setFailure(describeFailure(describeError?.(error, "read"), labels.failed));
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const leave = () => {
|
|
77
|
+
setReturning(true);
|
|
78
|
+
setAsking(false);
|
|
79
|
+
};
|
|
80
|
+
const escapeLeaves = (event) => {
|
|
81
|
+
if (event.key === "Escape") {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
leave();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const count = items?.length ?? 0;
|
|
88
|
+
const header = asking ? /* @__PURE__ */ jsxs("div", { className: "space-y-2 border-b border-subtle px-3 py-2", "data-inbox-confirm": "", children: [
|
|
89
|
+
/* @__PURE__ */ jsx("p", { role: "alert", className: "text-sm", children: labels.clearPrompt }),
|
|
90
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
Button,
|
|
93
|
+
{
|
|
94
|
+
type: "button",
|
|
95
|
+
size: "sm",
|
|
96
|
+
variant: "danger",
|
|
97
|
+
commit: COMMIT_EXCEPT_BILLING,
|
|
98
|
+
pending: busy === "clear",
|
|
99
|
+
onClick: () => run("clear", onClear, () => setAsking(false)),
|
|
100
|
+
onKeyDown: escapeLeaves,
|
|
101
|
+
children: labels.clearAll
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
/* @__PURE__ */ jsx(Button, { ref: cancelRef, type: "button", size: "sm", variant: "ghost", onClick: leave, onKeyDown: escapeLeaves, children: common.cancel })
|
|
105
|
+
] })
|
|
106
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-subtle px-3 py-2", children: [
|
|
107
|
+
/* @__PURE__ */ jsx(SettingsCardTitle, { id: headingId, children: title ?? labels.inboxTitle }),
|
|
108
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-0.5", children: [
|
|
109
|
+
/* @__PURE__ */ jsx(
|
|
110
|
+
IconButton,
|
|
111
|
+
{
|
|
112
|
+
type: "button",
|
|
113
|
+
size: "xs",
|
|
114
|
+
tone: "muted",
|
|
115
|
+
commit: COMMIT_EXCEPT_BILLING,
|
|
116
|
+
onClick: () => run("read", () => onMarkRead(null)),
|
|
117
|
+
disabled: unreadCount === 0 || busy !== null,
|
|
118
|
+
label: labels.markAllRead,
|
|
119
|
+
children: /* @__PURE__ */ jsx(CheckCheck, {})
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
IconButton,
|
|
124
|
+
{
|
|
125
|
+
ref: clearRef,
|
|
126
|
+
type: "button",
|
|
127
|
+
size: "xs",
|
|
128
|
+
tone: "danger",
|
|
129
|
+
commit: COMMIT_EXCEPT_BILLING,
|
|
130
|
+
onClick: () => {
|
|
131
|
+
setReturning(false);
|
|
132
|
+
setAsking(true);
|
|
133
|
+
},
|
|
134
|
+
disabled: count === 0 || busy !== null,
|
|
135
|
+
label: labels.clearAll,
|
|
136
|
+
children: /* @__PURE__ */ jsx(Trash2, {})
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
] })
|
|
140
|
+
] });
|
|
141
|
+
let body;
|
|
142
|
+
if (loading || items === void 0) {
|
|
143
|
+
body = /* @__PURE__ */ jsx(Skeleton, { lines: 3, label: labels.inboxLoading, className: "p-3" });
|
|
144
|
+
} else if (items.length === 0) {
|
|
145
|
+
body = /* @__PURE__ */ jsx(EmptyState, { variant: "inline", title: labels.inboxEmpty, className: "px-3 py-2" });
|
|
146
|
+
} else {
|
|
147
|
+
body = // Named by the heading — except while "Clear all" asks, when the heading is away.
|
|
148
|
+
/* @__PURE__ */ jsxs(List, { className: "p-1", "aria-labelledby": asking ? void 0 : headingId, "aria-label": asking ? labels.inboxTitle : void 0, children: [
|
|
149
|
+
items.map((item) => {
|
|
150
|
+
const row = {
|
|
151
|
+
title: item.title,
|
|
152
|
+
subtitle: item.body,
|
|
153
|
+
subtitleLines: 2,
|
|
154
|
+
overline: item.company ?? void 0,
|
|
155
|
+
meta: timeOf(item.created_at),
|
|
156
|
+
icon: iconOf(item.notification_type),
|
|
157
|
+
unread: item.read_at === null,
|
|
158
|
+
align: "start"
|
|
159
|
+
};
|
|
160
|
+
if (onOpen) {
|
|
161
|
+
return /* @__PURE__ */ jsx(
|
|
162
|
+
ListItem,
|
|
163
|
+
{
|
|
164
|
+
...row,
|
|
165
|
+
"data-inbox-item": String(item.id),
|
|
166
|
+
onClick: () => {
|
|
167
|
+
markOne(item);
|
|
168
|
+
onOpen(item);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
item.id
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (!item.url) {
|
|
175
|
+
return /* @__PURE__ */ jsx(ListItem, { ...row, "data-inbox-item": String(item.id), onClick: () => markOne(item) }, item.id);
|
|
176
|
+
}
|
|
177
|
+
return /* @__PURE__ */ jsx(
|
|
178
|
+
ListItem,
|
|
179
|
+
{
|
|
180
|
+
...row,
|
|
181
|
+
"data-inbox-item": String(item.id),
|
|
182
|
+
href: item.url,
|
|
183
|
+
external: !item.url.startsWith("/"),
|
|
184
|
+
onClick: () => markOne(item),
|
|
185
|
+
onAuxClick: (event) => {
|
|
186
|
+
if (event.button === 1) markOne(item);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
item.id
|
|
190
|
+
);
|
|
191
|
+
}),
|
|
192
|
+
hasMore && onLoadMore && /* @__PURE__ */ jsx("li", { className: "px-2 py-1", children: /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", pending: loadingMore, onClick: onLoadMore, className: "w-full", children: labels.showMore }) })
|
|
193
|
+
] });
|
|
194
|
+
}
|
|
195
|
+
return /* @__PURE__ */ jsxs(Card, { ...rest, className: cn("overflow-hidden p-0", className), children: [
|
|
196
|
+
header,
|
|
197
|
+
/* @__PURE__ */ jsx("div", { className: "max-h-[min(24rem,70vh)] overflow-y-auto overscroll-contain", children: body }),
|
|
198
|
+
failure !== null && /* @__PURE__ */ jsx("div", { className: "px-3 pb-3", children: /* @__PURE__ */ jsx(FailureLine, { children: failure }) })
|
|
199
|
+
] });
|
|
200
|
+
}
|
|
201
|
+
const INBOX_BADGE_INTERVAL = 6e4;
|
|
202
|
+
export {
|
|
203
|
+
INBOX_BADGE_INTERVAL,
|
|
204
|
+
NotificationInbox
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=notification-inbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/notifications/notification-inbox.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState } from \"react\";\nimport type { ComponentPropsWithRef, KeyboardEvent, ReactNode } from \"react\";\nimport { Bell, CheckCheck, Trash2 } from \"lucide-react\";\nimport type { LucideIcon } from \"lucide-react\";\n\nimport { useKitLabels, type LabelOverride } from \"../i18n/kit-labels\";\nimport { DEFAULT_COMMON_LABELS } from \"../i18n/shared-labels\";\nimport { cn } from \"../lib/cn\";\nimport { useKitFormat } from \"../lib/format\";\nimport { Button } from \"../components/button\";\nimport { Card } from \"../components/card\";\nimport { EmptyState } from \"../components/empty-state\";\nimport { IconButton } from \"../components/icon-button\";\nimport { List, ListItem } from \"../components/list\";\nimport { Skeleton } from \"../components/skeleton\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { SettingsCardTitle } from \"../settings/settings-heading\";\nimport { settle, useMounted } from \"../account/account-parts\";\nimport { describeFailure, FailureLine, useNotificationsLabels } from \"./notification-parts\";\nimport type { NotificationsLabels } from \"./notifications-labels\";\n\n/**\n * One inbox row as `GET /notifications/inbox` answers it (server-kit `InboxItem`, §3.7):\n * the title and body already in the recipient's language.\n */\nexport interface NotificationInboxItem<Id extends string | number = string | number> {\n id: Id;\n /** The type id, for the row's icon. */\n notification_type: string;\n title: string;\n body: string;\n /** A path in the app, an absolute URL, or `null` (nothing to open). */\n url: string | null;\n /** ISO date-time. */\n created_at: string;\n /** ISO date-time, or `null` while unread. */\n read_at: string | null;\n /** 0.46 (server-kit 0.16 `InboxItem.company`): the company the row is about, named on\n * the row — kastlan's inbox holds every company's rows. */\n company?: string | null;\n /** 0.46.1 (server-kit 0.16.1 `InboxItem.company_id`): the same company by its id, so\n * `onOpen` switches to it exactly (two companies may share a name). */\n company_id?: number | string | null;\n}\n\n/** The inbox request that failed, as `describeError` gets it (0.46.1): one row marked read,\n * \"Mark all as read\", or \"Clear all\". */\nexport type NotificationInboxAction = \"read\" | \"readAll\" | \"clear\";\n\nexport interface NotificationInboxProps<Id extends string | number = string | number>\n extends Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"title\"> {\n /** The rows, newest first; `undefined` while the first page loads. */\n items: readonly NotificationInboxItem<Id>[] | undefined;\n /** Every unread row of the account (`unread_count`), not only this page's. */\n unreadCount: number;\n loading?: boolean;\n /** `POST /notifications/inbox/read {ids}` — these rows, or `null` for all. */\n onMarkRead: (ids: Id[] | null) => Promise<unknown> | void;\n /** `DELETE /notifications/inbox`. Asked first, in the header. */\n onClear: () => Promise<unknown> | void;\n /**\n * Open a row: the kit marks it read first, then calls this, and the app routes to\n * `item.url` (kastlan switches the acting company, `item.company_id`, first). Every row is a button then.\n * Left out, a row with a `url` is a real link — an in-app path through the provider's\n * router link, an absolute URL in a new tab — that marks itself read on a click or a\n * middle click (keksdose #451), and a row without one marks itself read.\n */\n onOpen?: (item: NotificationInboxItem<Id>) => void;\n /** The row's glyph for a type — the app's map (keksdose's `TYPE_ICONS`). `undefined`,\n * or a type it does not know (a retired one), is the `Bell`. */\n icon?: (type: string) => LucideIcon | undefined;\n /** More rows than shown: a \"Show more\" row calls `onLoadMore` (the API pages by\n * `offset`). */\n hasMore?: boolean;\n onLoadMore?: () => void;\n /** The next page is loading. */\n loadingMore?: boolean;\n /** A row's time. Default: the provider's locale and `timeZone`, date and time. */\n formatDate?: (iso: string) => string;\n /** The heading. Default `labels.inboxTitle` (\"Inbox\"). */\n title?: ReactNode;\n /** The app's own words for a failed request, or `undefined` for the kit's `failed`.\n * `action` (0.46.1) says which request failed: `\"read\"` (one row), `\"readAll\"` (\"Mark\n * all as read\") or `\"clear\"` (\"Clear all\") — so a failed mark-read is not worded as a\n * failed clear. */\n describeError?: (error: unknown, action: NotificationInboxAction) => ReactNode | undefined;\n labels?: LabelOverride<NotificationsLabels>;\n}\n\n/**\n * The in-app inbox (0.46, docs/notifications-harmonization.md §10.1), keksdose's list\n * lifted: newest first, an icon per type (`Bell` for one the app does not map), the\n * title and two lines of body, the time, and — kastlan — the company the row is about.\n * Unread rows are bold with a dot. Props only: the app keeps the data (poll the badge\n * every {@link INBOX_BADGE_INTERVAL}, invalidate on its worker's push message).\n *\n * - **Opening a row marks it read** (see `onOpen`).\n * - **\"Mark all as read\"** while anything is unread; **\"Clear all\"** asks first, in the\n * header — no `ConfirmProvider` needed — with focus on Cancel.\n * - **\"Show more\"** with `hasMore`; the list scrolls inside a box of at most\n * `min(24rem, 70vh)`, so it never pushes the settings below it off the page.\n *\n * Under a write lock the header's actions are `commit` controls exempt from billing.\n */\nexport function NotificationInbox<Id extends string | number = string | number>({\n items,\n unreadCount,\n loading,\n onMarkRead,\n onClear,\n onOpen,\n icon,\n hasMore = false,\n onLoadMore,\n loadingMore = false,\n formatDate: formatDateProp,\n title,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: NotificationInboxProps<Id>) {\n const labels = useNotificationsLabels(labelsProp);\n const common = useKitLabels(\"common\", DEFAULT_COMMON_LABELS);\n const { formatDate } = useKitFormat();\n const [asking, setAsking] = useState(false);\n const [busy, setBusy] = useState<\"read\" | \"clear\" | null>(null);\n const [failure, setFailure] = useState<ReactNode>(null);\n const mounted = useMounted();\n const headingId = useId();\n const cancelRef = useRef<HTMLButtonElement>(null);\n const clearRef = useRef<HTMLButtonElement>(null);\n const [returning, setReturning] = useState(false);\n useEffect(() => {\n if (asking) cancelRef.current?.focus();\n else if (returning) clearRef.current?.focus();\n }, [asking, returning]);\n\n const timeOf = (iso: string) => (formatDateProp ? formatDateProp(iso) : formatDate(iso, \"dateTime\"));\n const iconOf = (type: string): LucideIcon => icon?.(type) ?? Bell;\n\n const run = (which: \"read\" | \"clear\", call: () => unknown, after?: () => void) => {\n setBusy(which);\n setFailure(null);\n settle(call).then(\n () => {\n if (!mounted.current) return;\n setBusy(null);\n after?.();\n },\n (error: unknown) => {\n if (!mounted.current) return;\n setBusy(null);\n setFailure(describeFailure(describeError?.(error, which === \"read\" ? \"readAll\" : \"clear\"), labels.failed));\n },\n );\n };\n\n /** Mark one row read; a failure is said under the list, the row stays as it is. */\n const markOne = (item: NotificationInboxItem<Id>) => {\n if (item.read_at !== null) return;\n settle(() => onMarkRead([item.id])).catch((error: unknown) => {\n if (mounted.current) setFailure(describeFailure(describeError?.(error, \"read\"), labels.failed));\n });\n };\n\n const leave = () => {\n setReturning(true);\n setAsking(false);\n };\n const escapeLeaves = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n leave();\n }\n };\n\n const count = items?.length ?? 0;\n\n const header = asking ? (\n <div className=\"space-y-2 border-b border-subtle px-3 py-2\" data-inbox-confirm=\"\">\n <p role=\"alert\" className=\"text-sm\">\n {labels.clearPrompt}\n </p>\n <div className=\"flex flex-wrap gap-2\">\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"danger\"\n commit={COMMIT_EXCEPT_BILLING}\n pending={busy === \"clear\"}\n onClick={() => run(\"clear\", onClear, () => setAsking(false))}\n onKeyDown={escapeLeaves}\n >\n {labels.clearAll}\n </Button>\n <Button ref={cancelRef} type=\"button\" size=\"sm\" variant=\"ghost\" onClick={leave} onKeyDown={escapeLeaves}>\n {common.cancel}\n </Button>\n </div>\n </div>\n ) : (\n <div className=\"flex items-center justify-between gap-2 border-b border-subtle px-3 py-2\">\n <SettingsCardTitle id={headingId}>{title ?? labels.inboxTitle}</SettingsCardTitle>\n <div className=\"flex items-center gap-0.5\">\n <IconButton\n type=\"button\"\n size=\"xs\"\n tone=\"muted\"\n commit={COMMIT_EXCEPT_BILLING}\n onClick={() => run(\"read\", () => onMarkRead(null))}\n disabled={unreadCount === 0 || busy !== null}\n label={labels.markAllRead}\n >\n <CheckCheck />\n </IconButton>\n <IconButton\n ref={clearRef}\n type=\"button\"\n size=\"xs\"\n tone=\"danger\"\n commit={COMMIT_EXCEPT_BILLING}\n onClick={() => {\n setReturning(false);\n setAsking(true);\n }}\n disabled={count === 0 || busy !== null}\n label={labels.clearAll}\n >\n <Trash2 />\n </IconButton>\n </div>\n </div>\n );\n\n let body: ReactNode;\n if (loading || items === undefined) {\n body = <Skeleton lines={3} label={labels.inboxLoading} className=\"p-3\" />;\n } else if (items.length === 0) {\n body = <EmptyState variant=\"inline\" title={labels.inboxEmpty} className=\"px-3 py-2\" />;\n } else {\n body = (\n // Named by the heading — except while \"Clear all\" asks, when the heading is away.\n <List className=\"p-1\" aria-labelledby={asking ? undefined : headingId} aria-label={asking ? labels.inboxTitle : undefined}>\n {items.map((item) => {\n const row = {\n title: item.title,\n subtitle: item.body,\n subtitleLines: 2 as const,\n overline: item.company ?? undefined,\n meta: timeOf(item.created_at),\n icon: iconOf(item.notification_type),\n unread: item.read_at === null,\n align: \"start\" as const,\n };\n if (onOpen) {\n return (\n <ListItem\n key={item.id}\n {...row}\n data-inbox-item={String(item.id)}\n onClick={() => {\n markOne(item);\n onOpen(item);\n }}\n />\n );\n }\n if (!item.url) {\n return <ListItem key={item.id} {...row} data-inbox-item={String(item.id)} onClick={() => markOne(item)} />;\n }\n // A real link, so a middle click opens a background tab; a middle click fires no\n // `click`, hence `onAuxClick` (keksdose #451).\n return (\n <ListItem\n key={item.id}\n {...row}\n data-inbox-item={String(item.id)}\n href={item.url}\n external={!item.url.startsWith(\"/\")}\n onClick={() => markOne(item)}\n onAuxClick={(event) => {\n if (event.button === 1) markOne(item);\n }}\n />\n );\n })}\n {hasMore && onLoadMore && (\n <li className=\"px-2 py-1\">\n <Button type=\"button\" size=\"sm\" variant=\"ghost\" pending={loadingMore} onClick={onLoadMore} className=\"w-full\">\n {labels.showMore}\n </Button>\n </li>\n )}\n </List>\n );\n }\n\n return (\n <Card {...rest} className={cn(\"overflow-hidden p-0\", className)}>\n {header}\n <div className=\"max-h-[min(24rem,70vh)] overflow-y-auto overscroll-contain\">{body}</div>\n {failure !== null && (\n <div className=\"px-3 pb-3\">\n <FailureLine>{failure}</FailureLine>\n </div>\n )}\n </Card>\n );\n}\n\n/** How often an app polls the unread count for the badge (keksdose's 60 s, `limit:1`). */\nexport const INBOX_BADGE_INTERVAL = 60_000;\n"],"mappings":";AAsLM,cAGA,YAHA;AAtLN,SAAS,WAAW,OAAO,QAAQ,gBAAgB;AAEnD,SAAS,MAAM,YAAY,cAAc;AAGzC,SAAS,oBAAwC;AACjD,SAAS,6BAA6B;AACtC,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,MAAM,gBAAgB;AAC/B,SAAS,gBAAgB;AACzB,SAAS,6BAA6B;AACtC,SAAS,yBAAyB;AAClC,SAAS,QAAQ,kBAAkB;AACnC,SAAS,iBAAiB,aAAa,8BAA8B;AAsF9D,SAAS,kBAAgE;AAAA,EAC9E;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV;AAAA,EACA,cAAc;AAAA,EACd,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA,GAAG;AACL,GAA+B;AAC7B,QAAM,SAAS,uBAAuB,UAAU;AA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,SAAS,MAAM,QAAQ,IAAI,KAA/E,KAAK,EAA6E;AAAA,QAC1G;AAGA,eACE;AAAA,UAAC;AAAA;AAAA,YAEE,GAAG;AAAA,YACJ,mBAAiB,OAAO,KAAK,EAAE;AAAA,YAC/B,MAAM,KAAK;AAAA,YACX,UAAU,CAAC,KAAK,IAAI,WAAW,GAAG;AAAA,YAClC,SAAS,MAAM,QAAQ,IAAI;AAAA,YAC3B,YAAY,CAAC,UAAU;AACrB,kBAAI,MAAM,WAAW,EAAG,SAAQ,IAAI;AAAA,YACtC;AAAA;AAAA,UARK,KAAK;AAAA,QASZ;AAAA,MAEJ,CAAC;AAAA,MACA,WAAW,cACV,oBAAC,QAAG,WAAU,aACZ,8BAAC,UAAO,MAAK,UAAS,MAAK,MAAK,SAAQ,SAAQ,SAAS,aAAa,SAAS,YAAY,WAAU,UAClG,iBAAO,UACV,GACF;AAAA,OAEJ;AAAA,EAEJ;AAEA,SACE,qBAAC,QAAM,GAAG,MAAM,WAAW,GAAG,uBAAuB,SAAS,GAC3D;AAAA;AAAA,IACD,oBAAC,SAAI,WAAU,8DAA8D,gBAAK;AAAA,IACjF,YAAY,QACX,oBAAC,SAAI,WAAU,aACb,8BAAC,eAAa,mBAAQ,GACxB;AAAA,KAEJ;AAEJ;AAGO,MAAM,uBAAuB;","names":[]}
|
|
@@ -39,10 +39,12 @@ export interface NotificationTypesSettingProps<Id extends string = string> exten
|
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* What the person hears about, and how (docs/notifications-harmonization.md §2.1–§2.3,
|
|
42
|
-
* §4.2): one row per type the SERVER answered, the app's words on it, a switch
|
|
43
|
-
* the
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* §4.2, §10.2): one row per type the SERVER answered, the app's words on it, and a switch
|
|
43
|
+
* per channel the type offers — "In the app", "Push", "E-mail". On a wide screen they are
|
|
44
|
+
* narrow columns under those headings; on a phone they stack under the type's label. A
|
|
45
|
+
* channel the server answers `null` is not drawn (kastlan and KS offer no push; KS no
|
|
46
|
+
* "in the app"), and a row with one channel keeps a single switch named by the type
|
|
47
|
+
* (Kurvenschmiede's e-mail-only rows).
|
|
46
48
|
*
|
|
47
49
|
* **The server's list is the only list.** The card keeps no defaults and no list of
|
|
48
50
|
* types: it draws what `value` holds, in the order of `groups`, else of `types`. A type
|
|
@@ -9,6 +9,7 @@ import { Skeleton } from "../components/skeleton.js";
|
|
|
9
9
|
import { Switch } from "../components/switch.js";
|
|
10
10
|
import { SectionLabel } from "../components/text.js";
|
|
11
11
|
import { COMMIT_EXCEPT_BILLING } from "../components/write-lock.js";
|
|
12
|
+
import { usePhoneLayout } from "../hooks/use-breakpoint.js";
|
|
12
13
|
import { CARD_DESCRIPTION_CLASS } from "../settings/settings-card-classes.js";
|
|
13
14
|
import { SettingsCardTitle } from "../settings/settings-heading.js";
|
|
14
15
|
import { settle, useMounted } from "../account/account-parts.js";
|
|
@@ -18,6 +19,13 @@ function devChecks() {
|
|
|
18
19
|
}
|
|
19
20
|
const switchKey = (id, channel) => `${id}.${channel}`;
|
|
20
21
|
const CADENCE_KEY = "digest_cadence";
|
|
22
|
+
const COLUMN_GRID = {
|
|
23
|
+
1: "grid-cols-[minmax(0,1fr)_4.5rem]",
|
|
24
|
+
2: "grid-cols-[minmax(0,1fr)_repeat(2,4.5rem)]",
|
|
25
|
+
3: "grid-cols-[minmax(0,1fr)_repeat(3,4.5rem)]"
|
|
26
|
+
};
|
|
27
|
+
const CHANNELS = ["app", "push", "email"];
|
|
28
|
+
const channelsOf = (switches) => CHANNELS.filter((channel) => switches[channel] !== null && switches[channel] !== void 0);
|
|
21
29
|
function NotificationTypesSetting({
|
|
22
30
|
types,
|
|
23
31
|
value,
|
|
@@ -58,10 +66,11 @@ function NotificationTypesSetting({
|
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
}
|
|
69
|
+
const phone = usePhoneLayout();
|
|
61
70
|
const rowOf = (id) => {
|
|
62
71
|
const switches = value?.[id];
|
|
63
72
|
const entry = entries.get(id);
|
|
64
|
-
if (!switches || !entry || switches.
|
|
73
|
+
if (!switches || !entry || channelsOf(switches).length === 0) return null;
|
|
65
74
|
return { entry, switches };
|
|
66
75
|
};
|
|
67
76
|
const rowsOf = (ids) => ids.map(rowOf).filter((row) => row !== null);
|
|
@@ -69,7 +78,8 @@ function NotificationTypesSetting({
|
|
|
69
78
|
const key = switchKey(id, channel);
|
|
70
79
|
return overlay.get(key) ?? server;
|
|
71
80
|
};
|
|
72
|
-
const
|
|
81
|
+
const channelOn = ({ entry, switches }, channel) => shown(entry.id, channel, switches[channel] === true);
|
|
82
|
+
const rowOn = (row) => channelsOf(row.switches).some((channel) => channelOn(row, channel));
|
|
73
83
|
const save = (key, patch, which, next) => {
|
|
74
84
|
if (which.pending(key)) return;
|
|
75
85
|
setFailure(null);
|
|
@@ -93,11 +103,26 @@ function NotificationTypesSetting({
|
|
|
93
103
|
);
|
|
94
104
|
const cadence = cadenceOverlay.get(CADENCE_KEY) ?? digest?.cadence;
|
|
95
105
|
const unverifiedLine = emailUnverified ? /* @__PURE__ */ jsx("span", { className: "block", "data-email-unverified": "", children: labels.emailUnverified }) : null;
|
|
106
|
+
const channelLabel = {
|
|
107
|
+
app: labels.channelApp,
|
|
108
|
+
push: labels.channelPush,
|
|
109
|
+
email: labels.channelEmail
|
|
110
|
+
};
|
|
111
|
+
const drawnRows = value && !loading ? rowsOf(groups ? groups.flatMap((group) => group.types) : types.map((entry) => entry.id)) : [];
|
|
112
|
+
const multi = drawnRows.filter((row) => channelsOf(row.switches).length > 1);
|
|
113
|
+
const columns = CHANNELS.filter((channel) => multi.some((row) => channelsOf(row.switches).includes(channel)));
|
|
114
|
+
const columnHeadings = !phone && columns.length > 0 ? (
|
|
115
|
+
// The switches carry the channel's name themselves; the headings are for the eye.
|
|
116
|
+
/* @__PURE__ */ jsxs("div", { "aria-hidden": true, className: cn("grid gap-x-2", COLUMN_GRID[columns.length]), "data-channel-headings": "", children: [
|
|
117
|
+
/* @__PURE__ */ jsx("span", {}),
|
|
118
|
+
columns.map((channel) => /* @__PURE__ */ jsx("span", { className: "text-center text-caption font-medium text-muted", children: channelLabel[channel] }, channel))
|
|
119
|
+
] })
|
|
120
|
+
) : null;
|
|
96
121
|
const renderRow = (row) => {
|
|
97
122
|
const { entry, switches } = row;
|
|
98
123
|
const on = rowOn(row);
|
|
99
|
-
const
|
|
100
|
-
const
|
|
124
|
+
const offered = channelsOf(switches);
|
|
125
|
+
const single = offered.length === 1 ? offered[0] : null;
|
|
101
126
|
const cadenceSelect = on && digest?.type === entry.id && cadence ? /* @__PURE__ */ jsxs(
|
|
102
127
|
Select,
|
|
103
128
|
{
|
|
@@ -117,45 +142,72 @@ function NotificationTypesSetting({
|
|
|
117
142
|
}
|
|
118
143
|
) : null;
|
|
119
144
|
const extra = on ? renderExtra?.(entry.id) : null;
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
] }) :
|
|
145
|
+
const below = cadenceSelect || hasContent(extra) ? /* @__PURE__ */ jsxs("div", { className: "ps-4 space-y-2", children: [
|
|
146
|
+
cadenceSelect,
|
|
147
|
+
extra
|
|
148
|
+
] }) : null;
|
|
149
|
+
if (single) {
|
|
150
|
+
const description = single === "email" && unverifiedLine ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
151
|
+
entry.description !== void 0 && /* @__PURE__ */ jsx("span", { className: "block", children: entry.description }),
|
|
152
|
+
unverifiedLine
|
|
153
|
+
] }) : entry.description;
|
|
154
|
+
return /* @__PURE__ */ jsxs("div", { "data-notification-type": entry.id, "data-channels": single, className: "space-y-2", children: [
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
Switch,
|
|
157
|
+
{
|
|
158
|
+
label: entry.label,
|
|
159
|
+
description,
|
|
160
|
+
checked: channelOn(row, single),
|
|
161
|
+
disabled,
|
|
162
|
+
commit: COMMIT_EXCEPT_BILLING,
|
|
163
|
+
onCheckedChange: (next) => flip(entry.id, single, next)
|
|
164
|
+
}
|
|
165
|
+
),
|
|
166
|
+
below
|
|
167
|
+
] }, entry.id);
|
|
168
|
+
}
|
|
169
|
+
const labelId = `${groupId}-type-${entry.id}`;
|
|
170
|
+
const unverifiedId = `${groupId}-unverified-${entry.id}`;
|
|
171
|
+
const channelSwitch = (channel) => /* @__PURE__ */ jsx(
|
|
172
|
+
Switch,
|
|
173
|
+
{
|
|
174
|
+
size: "sm",
|
|
175
|
+
label: phone ? channelLabel[channel] : void 0,
|
|
176
|
+
"aria-label": phone ? void 0 : channelLabel[channel],
|
|
177
|
+
description: phone && channel === "email" ? unverifiedLine ?? void 0 : void 0,
|
|
178
|
+
"aria-describedby": !phone && channel === "email" && unverifiedLine ? unverifiedId : void 0,
|
|
179
|
+
checked: channelOn(row, channel),
|
|
180
|
+
disabled,
|
|
181
|
+
commit: COMMIT_EXCEPT_BILLING,
|
|
182
|
+
onCheckedChange: (next) => flip(entry.id, channel, next),
|
|
183
|
+
"data-channel": channel
|
|
184
|
+
},
|
|
185
|
+
channel
|
|
186
|
+
);
|
|
187
|
+
const text = /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
188
|
+
/* @__PURE__ */ jsx("div", { id: labelId, className: "text-sm font-medium text-primary", children: entry.label }),
|
|
189
|
+
(entry.description !== void 0 || !phone && offered.includes("email") && unverifiedLine) && /* @__PURE__ */ jsxs("div", { className: CARD_DESCRIPTION_CLASS, children: [
|
|
190
|
+
entry.description !== void 0 && /* @__PURE__ */ jsx("span", { className: "block", children: entry.description }),
|
|
191
|
+
!phone && offered.includes("email") && /* @__PURE__ */ jsx("span", { id: unverifiedId, children: unverifiedLine })
|
|
192
|
+
] })
|
|
193
|
+
] });
|
|
124
194
|
return /* @__PURE__ */ jsxs(
|
|
125
195
|
"div",
|
|
126
196
|
{
|
|
127
197
|
"data-notification-type": entry.id,
|
|
128
|
-
|
|
129
|
-
"
|
|
198
|
+
"data-channels": offered.join(" "),
|
|
199
|
+
role: "group",
|
|
200
|
+
"aria-labelledby": labelId,
|
|
130
201
|
className: "space-y-2",
|
|
131
202
|
children: [
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
-
|
|
134
|
-
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
onCheckedChange: (next) => flip(entry.id, emailOnly ? "email" : "app", next)
|
|
141
|
-
}
|
|
142
|
-
),
|
|
143
|
-
both && /* @__PURE__ */ jsx("div", { className: "ps-4", children: /* @__PURE__ */ jsx(
|
|
144
|
-
Switch,
|
|
145
|
-
{
|
|
146
|
-
size: "sm",
|
|
147
|
-
label: labels.byEmail,
|
|
148
|
-
description: unverifiedLine ?? void 0,
|
|
149
|
-
checked: shown(entry.id, "email", switches.email === true),
|
|
150
|
-
disabled,
|
|
151
|
-
commit: COMMIT_EXCEPT_BILLING,
|
|
152
|
-
onCheckedChange: (next) => flip(entry.id, "email", next)
|
|
153
|
-
}
|
|
154
|
-
) }),
|
|
155
|
-
(cadenceSelect || hasContent(extra)) && /* @__PURE__ */ jsxs("div", { className: "ps-4 space-y-2", children: [
|
|
156
|
-
cadenceSelect,
|
|
157
|
-
extra
|
|
158
|
-
] })
|
|
203
|
+
phone ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
204
|
+
text,
|
|
205
|
+
/* @__PURE__ */ jsx("div", { className: "ps-4 space-y-2", "data-stacked": "", children: offered.map(channelSwitch) })
|
|
206
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: cn("grid items-start gap-x-2", COLUMN_GRID[columns.length]), children: [
|
|
207
|
+
text,
|
|
208
|
+
columns.map((channel) => /* @__PURE__ */ jsx("div", { className: "flex justify-center pt-0.5", children: offered.includes(channel) ? channelSwitch(channel) : null }, channel))
|
|
209
|
+
] }),
|
|
210
|
+
below
|
|
159
211
|
]
|
|
160
212
|
},
|
|
161
213
|
entry.id
|
|
@@ -166,16 +218,22 @@ function NotificationTypesSetting({
|
|
|
166
218
|
body = /* @__PURE__ */ jsx(Skeleton, { lines: 3, label: labels.typesLoading });
|
|
167
219
|
} else if (groups) {
|
|
168
220
|
const drawn = groups.map((group) => ({ group, rows: rowsOf(group.types) })).filter(({ rows }) => rows.length > 0);
|
|
169
|
-
body = drawn.length === 0 ? /* @__PURE__ */ jsx("p", { className: CARD_DESCRIPTION_CLASS, children: labels.typesEmpty }) :
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
221
|
+
body = drawn.length === 0 ? /* @__PURE__ */ jsx("p", { className: CARD_DESCRIPTION_CLASS, children: labels.typesEmpty }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
222
|
+
columnHeadings,
|
|
223
|
+
drawn.map(({ group, rows }) => {
|
|
224
|
+
const headingId = `${groupId}-${group.id}`;
|
|
225
|
+
return /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": headingId, className: "space-y-3", children: [
|
|
226
|
+
/* @__PURE__ */ jsx(SectionLabel, { as: "div", size: "xs", id: headingId, children: group.label }),
|
|
227
|
+
rows.map(renderRow)
|
|
228
|
+
] }, group.id);
|
|
229
|
+
})
|
|
230
|
+
] });
|
|
176
231
|
} else {
|
|
177
232
|
const rows = rowsOf(types.map((entry) => entry.id));
|
|
178
|
-
body = rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: CARD_DESCRIPTION_CLASS, children: labels.typesEmpty }) : /* @__PURE__ */
|
|
233
|
+
body = rows.length === 0 ? /* @__PURE__ */ jsx("p", { className: CARD_DESCRIPTION_CLASS, children: labels.typesEmpty }) : /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
234
|
+
columnHeadings,
|
|
235
|
+
rows.map(renderRow)
|
|
236
|
+
] });
|
|
179
237
|
}
|
|
180
238
|
return /* @__PURE__ */ jsxs(Card, { ...rest, className: cn("p-4 space-y-3", className), children: [
|
|
181
239
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/notifications/notification-types-setting.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { ComponentPropsWithRef, ReactNode } from \"react\";\n\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { cn } from \"../lib/cn\";\nimport { hasContent } from \"../lib/presence\";\nimport { Card } from \"../components/card\";\nimport { Select } from \"../components/select\";\nimport { Skeleton } from \"../components/skeleton\";\nimport { Switch } from \"../components/switch\";\nimport { SectionLabel } from \"../components/text\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { CARD_DESCRIPTION_CLASS } from \"../settings/settings-card-classes\";\nimport { SettingsCardTitle } from \"../settings/settings-heading\";\nimport { settle, useMounted } from \"../account/account-parts\";\nimport { describeFailure, FailureLine, useNotificationsLabels, useWriteOverlay } from \"./notification-parts\";\nimport type { WriteOverlay } from \"./notification-parts\";\nimport type { NotificationsLabels } from \"./notifications-labels\";\nimport type {\n DigestCadence,\n NotificationSettingsPatch,\n NotificationSwitches,\n NotificationTypeEntry,\n NotificationTypeGroup,\n NotificationTypesValue,\n} from \"./notification-types\";\n\n/** Is this a development build? Dead code in a consumer's production bundle; on under\n * vitest, where a type the card cannot draw is a bug a test should fail on (as\n * `SettingsSection`'s catalogue check). */\nfunction devChecks(): boolean {\n return Boolean(import.meta.env?.DEV);\n}\n\nexport interface NotificationTypesSettingProps<Id extends string = string>\n extends Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"onChange\"> {\n /** The app's words for its types, in its order. Where an app types its ids. */\n types: readonly NotificationTypeEntry<Id>[];\n /** The `GET`'s `types` (§3.2); `undefined` while the first load runs. */\n value: NotificationTypesValue | undefined;\n /** The settings are loading. */\n loading?: boolean;\n /**\n * Save one change — `PATCH /notifications/settings` with this body: one switch per\n * call (`{types: {digest: {app: true}}}`), or `{digest_cadence}`. The switch shows its\n * new state while the call runs and goes back if it rejects; hand the card the\n * PATCH's answer (or refetch) when it resolves.\n */\n onChange: (patch: NotificationSettingsPatch<Id>) => Promise<unknown> | void;\n /** Headings over the types, in the app's words (keksdose's three). Without them, one\n * list in the order of `types`. In development every type the server answered must\n * be in one. */\n groups?: readonly NotificationTypeGroup<Id>[];\n /** The digest type and the account's cadence: a cadence `Select` under that type\n * while it is on. */\n digest?: { type: Id; cadence: DigestCadence };\n /** Under a type while it is on — keksdose's low-balance threshold field. */\n renderExtra?: (id: Id) => ReactNode;\n /** The account's address is unverified: every e-mail switch says\n * `labels.emailUnverified` under it (decision 16). */\n emailUnverified?: boolean;\n /** Nothing can be changed (the switches stay readable). */\n disabled?: boolean;\n /** The app's own words for a failed save, or `undefined` for the kit's `failed`. */\n describeError?: (error: unknown) => ReactNode | undefined;\n labels?: LabelOverride<NotificationsLabels>;\n}\n\n/** One drawn type: the app's words and the server's switches. */\ninterface Row<Id extends string> {\n entry: NotificationTypeEntry<Id>;\n switches: NotificationSwitches;\n}\n\n/** A switch's key in the write overlay. */\nconst switchKey = (id: string, channel: \"app\" | \"email\") => `${id}.${channel}`;\nconst CADENCE_KEY = \"digest_cadence\";\n\n/**\n * What the person hears about, and how (docs/notifications-harmonization.md §2.1–§2.3,\n * §4.2): one row per type the SERVER answered, the app's words on it, a switch for \"in\n * the app\" and \"By e-mail\" under it where the type offers mail. Where the app has no\n * \"in the app\" channel (Kurvenschmiede), the e-mail switch is the row's own, with the\n * type's label.\n *\n * **The server's list is the only list.** The card keeps no defaults and no list of\n * types: it draws what `value` holds, in the order of `groups`, else of `types`. A type\n * the app names that the server did not answer is not drawn (kastlan's tenant receives\n * neither of its types). In development a type the server answered with no entry in\n * `types`, or in no group when `groups` is given, throws — keksdose's compile-time\n * `_EVERY_TYPE_IS_GROUPED`, now at run time, since the list is the server's.\n *\n * **Each flip saves at once**, one switch per call; the switch shows its new state while\n * the call runs and goes back if it rejects, with the failure said under the card. The\n * digest's cadence and the app's extra field (`renderExtra`) show under their type while\n * it is on.\n *\n * Under a write lock the switches are `commit` controls exempt from billing: a lapsed\n * plan never keeps a person from turning notifications off (billing §12.13).\n */\nexport function NotificationTypesSetting<Id extends string = string>({\n types,\n value,\n loading,\n onChange,\n groups,\n digest,\n renderExtra,\n emailUnverified = false,\n disabled = false,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: NotificationTypesSettingProps<Id>) {\n const labels = useNotificationsLabels(labelsProp);\n const overlay = useWriteOverlay<boolean>(value);\n const cadenceOverlay = useWriteOverlay<DigestCadence>(digest?.cadence);\n const [failure, setFailure] = useState<ReactNode>(null);\n const mounted = useMounted();\n const groupId = useId();\n\n const answered = value ? Object.keys(value) : [];\n const entries = new Map(types.map((entry) => [entry.id as string, entry]));\n if (value && devChecks()) {\n const unnamed = answered.filter((id) => !entries.has(id));\n if (unnamed.length) {\n throw new Error(\n `NotificationTypesSetting: the server answered ${unnamed.map((id) => `\"${id}\"`).join(\", \")} with no entry in \\`types\\` — give every type the server can send its words.`,\n );\n }\n if (groups) {\n const grouped = new Set<string>(groups.flatMap((group) => group.types));\n const loose = answered.filter((id) => !grouped.has(id));\n if (loose.length) {\n throw new Error(\n `NotificationTypesSetting: ${loose.map((id) => `\"${id}\"`).join(\", \")} is in no group — a type in no group is drawn nowhere, and could not be turned off.`,\n );\n }\n }\n }\n\n const rowOf = (id: Id): Row<Id> | null => {\n const switches = value?.[id];\n const entry = entries.get(id);\n if (!switches || !entry || (switches.app === null && switches.email === null)) return null;\n return { entry, switches };\n };\n const rowsOf = (ids: readonly Id[]) => ids.map(rowOf).filter((row): row is Row<Id> => row !== null);\n\n const shown = (id: string, channel: \"app\" | \"email\", server: boolean): boolean => {\n const key = switchKey(id, channel);\n return overlay.get(key) ?? server;\n };\n /** The row's own switch: `app`, or `email` where the app has no `app` channel. */\n const rowOn = ({ entry, switches }: Row<Id>) =>\n switches.app !== null\n ? shown(entry.id, \"app\", switches.app)\n : shown(entry.id, \"email\", switches.email === true);\n\n const save = <V,>(key: string, patch: NotificationSettingsPatch<Id>, which: WriteOverlay<V>, next: V) => {\n if (which.pending(key)) return;\n setFailure(null);\n which.set(key, next);\n settle(() => onChange(patch)).then(\n () => {\n if (mounted.current) which.settle(key, true);\n },\n (error: unknown) => {\n if (!mounted.current) return;\n which.settle(key, false);\n setFailure(describeFailure(describeError?.(error), labels.failed));\n },\n );\n };\n\n const flip = (id: Id, channel: \"app\" | \"email\", on: boolean) =>\n save(\n switchKey(id, channel),\n { types: { [id]: { [channel]: on } } as NotificationSettingsPatch<Id>[\"types\"] },\n overlay,\n on,\n );\n\n const cadence = cadenceOverlay.get(CADENCE_KEY) ?? digest?.cadence;\n\n const unverifiedLine = emailUnverified ? (\n <span className=\"block\" data-email-unverified=\"\">\n {labels.emailUnverified}\n </span>\n ) : null;\n\n const renderRow = (row: Row<Id>) => {\n const { entry, switches } = row;\n const on = rowOn(row);\n const emailOnly = switches.app === null;\n const both = !emailOnly && switches.email !== null;\n const cadenceSelect =\n on && digest?.type === entry.id && cadence ? (\n <Select\n label={labels.digestCadence}\n value={cadence}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onChange={(event) => {\n const next = event.target.value as DigestCadence;\n if (next !== cadence) save(CADENCE_KEY, { digest_cadence: next }, cadenceOverlay, next);\n }}\n className=\"max-w-44\"\n >\n <option value=\"weekly\">{labels.digestWeekly}</option>\n <option value=\"monthly\">{labels.digestMonthly}</option>\n </Select>\n ) : null;\n const extra = on ? renderExtra?.(entry.id) : null;\n const description =\n emailOnly && unverifiedLine ? (\n <>\n {entry.description !== undefined && <span className=\"block\">{entry.description}</span>}\n {unverifiedLine}\n </>\n ) : (\n entry.description\n );\n return (\n <div\n key={entry.id}\n data-notification-type={entry.id}\n // A row with two switches is a group named by its type, so \"By e-mail\" is heard\n // with the type it belongs to.\n role={both ? \"group\" : undefined}\n aria-label={both ? entry.label : undefined}\n className=\"space-y-2\"\n >\n <Switch\n label={entry.label}\n description={description}\n checked={on}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onCheckedChange={(next) => flip(entry.id, emailOnly ? \"email\" : \"app\", next)}\n />\n {both && (\n <div className=\"ps-4\">\n <Switch\n size=\"sm\"\n label={labels.byEmail}\n description={unverifiedLine ?? undefined}\n checked={shown(entry.id, \"email\", switches.email === true)}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onCheckedChange={(next) => flip(entry.id, \"email\", next)}\n />\n </div>\n )}\n {(cadenceSelect || hasContent(extra)) && (\n <div className=\"ps-4 space-y-2\">\n {cadenceSelect}\n {extra}\n </div>\n )}\n </div>\n );\n };\n\n let body: ReactNode;\n if (loading || value === undefined) {\n body = <Skeleton lines={3} label={labels.typesLoading} />;\n } else if (groups) {\n const drawn = groups\n .map((group) => ({ group, rows: rowsOf(group.types) }))\n .filter(({ rows }) => rows.length > 0);\n body =\n drawn.length === 0 ? (\n <p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>\n ) : (\n drawn.map(({ group, rows }) => {\n const headingId = `${groupId}-${group.id}`;\n return (\n <div key={group.id} role=\"group\" aria-labelledby={headingId} className=\"space-y-3\">\n <SectionLabel as=\"div\" size=\"xs\" id={headingId}>\n {group.label}\n </SectionLabel>\n {rows.map(renderRow)}\n </div>\n );\n })\n );\n } else {\n const rows = rowsOf(types.map((entry) => entry.id));\n body =\n rows.length === 0 ? (\n <p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>\n ) : (\n <div className=\"space-y-3\">{rows.map(renderRow)}</div>\n );\n }\n\n return (\n <Card {...rest} className={cn(\"p-4 space-y-3\", className)}>\n <div>\n <SettingsCardTitle>{labels.typesTitle}</SettingsCardTitle>\n <div className={CARD_DESCRIPTION_CLASS}>{labels.typesDescription}</div>\n </div>\n {body}\n <FailureLine>{failure}</FailureLine>\n </Card>\n );\n}\n"],"mappings":";AA2LI,SA8BI,UA9BJ,KAYI,YAZJ;AA3LJ,SAAS,OAAO,gBAAgB;AAIhC,SAAS,UAAU;AACnB,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,gBA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K,SAAQ,mBAAiB,WAAW,WAAU,aACrE;AAAA,4BAAC,gBAAa,IAAG,OAAM,MAAK,MAAK,IAAI,WAClC,gBAAM,OACT;AAAA,QACC,KAAK,IAAI,SAAS;AAAA,WAJX,MAAM,EAKhB;AAAA,IAEJ,CAAC;AAAA,EAEP,OAAO;AACL,UAAM,OAAO,OAAO,MAAM,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC;AAClD,WACE,KAAK,WAAW,IACd,oBAAC,OAAE,WAAW,wBAAyB,iBAAO,YAAW,IAEzD,oBAAC,SAAI,WAAU,aAAa,eAAK,IAAI,SAAS,GAAE;AAAA,EAEtD;AAEA,SACE,qBAAC,QAAM,GAAG,MAAM,WAAW,GAAG,iBAAiB,SAAS,GACtD;AAAA,yBAAC,SACC;AAAA,0BAAC,qBAAmB,iBAAO,YAAW;AAAA,MACtC,oBAAC,SAAI,WAAW,wBAAyB,iBAAO,kBAAiB;AAAA,OACnE;AAAA,IACC;AAAA,IACD,oBAAC,eAAa,mBAAQ;AAAA,KACxB;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/notifications/notification-types-setting.tsx"],"sourcesContent":["import { useId, useState } from \"react\";\nimport type { ComponentPropsWithRef, ReactNode } from \"react\";\n\nimport type { LabelOverride } from \"../i18n/kit-labels\";\nimport { cn } from \"../lib/cn\";\nimport { hasContent } from \"../lib/presence\";\nimport { Card } from \"../components/card\";\nimport { Select } from \"../components/select\";\nimport { Skeleton } from \"../components/skeleton\";\nimport { Switch } from \"../components/switch\";\nimport { SectionLabel } from \"../components/text\";\nimport { COMMIT_EXCEPT_BILLING } from \"../components/write-lock\";\nimport { usePhoneLayout } from \"../hooks/use-breakpoint\";\nimport { CARD_DESCRIPTION_CLASS } from \"../settings/settings-card-classes\";\nimport { SettingsCardTitle } from \"../settings/settings-heading\";\nimport { settle, useMounted } from \"../account/account-parts\";\nimport { describeFailure, FailureLine, useNotificationsLabels, useWriteOverlay } from \"./notification-parts\";\nimport type { WriteOverlay } from \"./notification-parts\";\nimport type { NotificationsLabels } from \"./notifications-labels\";\nimport type {\n DigestCadence,\n NotificationChannel,\n NotificationSettingsPatch,\n NotificationSwitches,\n NotificationTypeEntry,\n NotificationTypeGroup,\n NotificationTypesValue,\n} from \"./notification-types\";\n\n/** Is this a development build? Dead code in a consumer's production bundle; on under\n * vitest, where a type the card cannot draw is a bug a test should fail on (as\n * `SettingsSection`'s catalogue check). */\nfunction devChecks(): boolean {\n return Boolean(import.meta.env?.DEV);\n}\n\nexport interface NotificationTypesSettingProps<Id extends string = string>\n extends Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"onChange\"> {\n /** The app's words for its types, in its order. Where an app types its ids. */\n types: readonly NotificationTypeEntry<Id>[];\n /** The `GET`'s `types` (§3.2); `undefined` while the first load runs. */\n value: NotificationTypesValue | undefined;\n /** The settings are loading. */\n loading?: boolean;\n /**\n * Save one change — `PATCH /notifications/settings` with this body: one switch per\n * call (`{types: {digest: {app: true}}}`), or `{digest_cadence}`. The switch shows its\n * new state while the call runs and goes back if it rejects; hand the card the\n * PATCH's answer (or refetch) when it resolves.\n */\n onChange: (patch: NotificationSettingsPatch<Id>) => Promise<unknown> | void;\n /** Headings over the types, in the app's words (keksdose's three). Without them, one\n * list in the order of `types`. In development every type the server answered must\n * be in one. */\n groups?: readonly NotificationTypeGroup<Id>[];\n /** The digest type and the account's cadence: a cadence `Select` under that type\n * while it is on. */\n digest?: { type: Id; cadence: DigestCadence };\n /** Under a type while it is on — keksdose's low-balance threshold field. */\n renderExtra?: (id: Id) => ReactNode;\n /** The account's address is unverified: every e-mail switch says\n * `labels.emailUnverified` under it (decision 16). */\n emailUnverified?: boolean;\n /** Nothing can be changed (the switches stay readable). */\n disabled?: boolean;\n /** The app's own words for a failed save, or `undefined` for the kit's `failed`. */\n describeError?: (error: unknown) => ReactNode | undefined;\n labels?: LabelOverride<NotificationsLabels>;\n}\n\n/** One drawn type: the app's words and the server's switches. */\ninterface Row<Id extends string> {\n entry: NotificationTypeEntry<Id>;\n switches: NotificationSwitches;\n}\n\n/** A switch's key in the write overlay. */\nconst switchKey = (id: string, channel: NotificationChannel) => `${id}.${channel}`;\nconst CADENCE_KEY = \"digest_cadence\";\n\n/** The grid of a several-channel row on a wide screen: the type's words, then one narrow\n * column per channel drawn. Literal classes, so Tailwind's scan finds them. */\nconst COLUMN_GRID: Record<number, string> = {\n 1: \"grid-cols-[minmax(0,1fr)_4.5rem]\",\n 2: \"grid-cols-[minmax(0,1fr)_repeat(2,4.5rem)]\",\n 3: \"grid-cols-[minmax(0,1fr)_repeat(3,4.5rem)]\",\n};\n\n/** The channels in the card's column order (§10.2). */\nconst CHANNELS: readonly NotificationChannel[] = [\"app\", \"push\", \"email\"];\n\n/** The channels a type offers: every one the server did not answer `null` (or leave out,\n * as `push` before server-kit 0.16). */\nconst channelsOf = (switches: NotificationSwitches): NotificationChannel[] =>\n CHANNELS.filter((channel) => switches[channel] !== null && switches[channel] !== undefined);\n\n/**\n * What the person hears about, and how (docs/notifications-harmonization.md §2.1–§2.3,\n * §4.2, §10.2): one row per type the SERVER answered, the app's words on it, and a switch\n * per channel the type offers — \"In the app\", \"Push\", \"E-mail\". On a wide screen they are\n * narrow columns under those headings; on a phone they stack under the type's label. A\n * channel the server answers `null` is not drawn (kastlan and KS offer no push; KS no\n * \"in the app\"), and a row with one channel keeps a single switch named by the type\n * (Kurvenschmiede's e-mail-only rows).\n *\n * **The server's list is the only list.** The card keeps no defaults and no list of\n * types: it draws what `value` holds, in the order of `groups`, else of `types`. A type\n * the app names that the server did not answer is not drawn (kastlan's tenant receives\n * neither of its types). In development a type the server answered with no entry in\n * `types`, or in no group when `groups` is given, throws — keksdose's compile-time\n * `_EVERY_TYPE_IS_GROUPED`, now at run time, since the list is the server's.\n *\n * **Each flip saves at once**, one switch per call; the switch shows its new state while\n * the call runs and goes back if it rejects, with the failure said under the card. The\n * digest's cadence and the app's extra field (`renderExtra`) show under their type while\n * it is on.\n *\n * Under a write lock the switches are `commit` controls exempt from billing: a lapsed\n * plan never keeps a person from turning notifications off (billing §12.13).\n */\nexport function NotificationTypesSetting<Id extends string = string>({\n types,\n value,\n loading,\n onChange,\n groups,\n digest,\n renderExtra,\n emailUnverified = false,\n disabled = false,\n describeError,\n labels: labelsProp,\n className,\n ...rest\n}: NotificationTypesSettingProps<Id>) {\n const labels = useNotificationsLabels(labelsProp);\n const overlay = useWriteOverlay<boolean>(value);\n const cadenceOverlay = useWriteOverlay<DigestCadence>(digest?.cadence);\n const [failure, setFailure] = useState<ReactNode>(null);\n const mounted = useMounted();\n const groupId = useId();\n\n const answered = value ? Object.keys(value) : [];\n const entries = new Map(types.map((entry) => [entry.id as string, entry]));\n if (value && devChecks()) {\n const unnamed = answered.filter((id) => !entries.has(id));\n if (unnamed.length) {\n throw new Error(\n `NotificationTypesSetting: the server answered ${unnamed.map((id) => `\"${id}\"`).join(\", \")} with no entry in \\`types\\` — give every type the server can send its words.`,\n );\n }\n if (groups) {\n const grouped = new Set<string>(groups.flatMap((group) => group.types));\n const loose = answered.filter((id) => !grouped.has(id));\n if (loose.length) {\n throw new Error(\n `NotificationTypesSetting: ${loose.map((id) => `\"${id}\"`).join(\", \")} is in no group — a type in no group is drawn nowhere, and could not be turned off.`,\n );\n }\n }\n }\n\n const phone = usePhoneLayout();\n const rowOf = (id: Id): Row<Id> | null => {\n const switches = value?.[id];\n const entry = entries.get(id);\n if (!switches || !entry || channelsOf(switches).length === 0) return null;\n return { entry, switches };\n };\n const rowsOf = (ids: readonly Id[]) => ids.map(rowOf).filter((row): row is Row<Id> => row !== null);\n\n const shown = (id: string, channel: NotificationChannel, server: boolean): boolean => {\n const key = switchKey(id, channel);\n return overlay.get(key) ?? server;\n };\n const channelOn = ({ entry, switches }: Row<Id>, channel: NotificationChannel) =>\n shown(entry.id, channel, switches[channel] === true);\n /** The type reaches the person at all: some channel is on (the cadence and the app's\n * extra show then). */\n const rowOn = (row: Row<Id>) => channelsOf(row.switches).some((channel) => channelOn(row, channel));\n\n const save = <V,>(key: string, patch: NotificationSettingsPatch<Id>, which: WriteOverlay<V>, next: V) => {\n if (which.pending(key)) return;\n setFailure(null);\n which.set(key, next);\n settle(() => onChange(patch)).then(\n () => {\n if (mounted.current) which.settle(key, true);\n },\n (error: unknown) => {\n if (!mounted.current) return;\n which.settle(key, false);\n setFailure(describeFailure(describeError?.(error), labels.failed));\n },\n );\n };\n\n const flip = (id: Id, channel: NotificationChannel, on: boolean) =>\n save(\n switchKey(id, channel),\n { types: { [id]: { [channel]: on } } as NotificationSettingsPatch<Id>[\"types\"] },\n overlay,\n on,\n );\n\n const cadence = cadenceOverlay.get(CADENCE_KEY) ?? digest?.cadence;\n\n const unverifiedLine = emailUnverified ? (\n <span className=\"block\" data-email-unverified=\"\">\n {labels.emailUnverified}\n </span>\n ) : null;\n\n const channelLabel: Record<NotificationChannel, string> = {\n app: labels.channelApp,\n push: labels.channelPush,\n email: labels.channelEmail,\n };\n /** The columns on a wide screen: every channel some several-channel row offers. */\n const drawnRows = value && !loading ? rowsOf(groups ? groups.flatMap((group) => group.types) : types.map((entry) => entry.id)) : [];\n const multi = drawnRows.filter((row) => channelsOf(row.switches).length > 1);\n const columns = CHANNELS.filter((channel) => multi.some((row) => channelsOf(row.switches).includes(channel)));\n const columnHeadings =\n !phone && columns.length > 0 ? (\n // The switches carry the channel's name themselves; the headings are for the eye.\n <div aria-hidden className={cn(\"grid gap-x-2\", COLUMN_GRID[columns.length])} data-channel-headings=\"\">\n <span />\n {columns.map((channel) => (\n <span key={channel} className=\"text-center text-caption font-medium text-muted\">\n {channelLabel[channel]}\n </span>\n ))}\n </div>\n ) : null;\n\n const renderRow = (row: Row<Id>) => {\n const { entry, switches } = row;\n const on = rowOn(row);\n const offered = channelsOf(switches);\n const single = offered.length === 1 ? offered[0] : null;\n const cadenceSelect =\n on && digest?.type === entry.id && cadence ? (\n <Select\n label={labels.digestCadence}\n value={cadence}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onChange={(event) => {\n const next = event.target.value as DigestCadence;\n if (next !== cadence) save(CADENCE_KEY, { digest_cadence: next }, cadenceOverlay, next);\n }}\n className=\"max-w-44\"\n >\n <option value=\"weekly\">{labels.digestWeekly}</option>\n <option value=\"monthly\">{labels.digestMonthly}</option>\n </Select>\n ) : null;\n const extra = on ? renderExtra?.(entry.id) : null;\n const below =\n cadenceSelect || hasContent(extra) ? (\n <div className=\"ps-4 space-y-2\">\n {cadenceSelect}\n {extra}\n </div>\n ) : null;\n\n // One channel: today's single switch, named by the type (KS's e-mail-only rows).\n if (single) {\n const description =\n single === \"email\" && unverifiedLine ? (\n <>\n {entry.description !== undefined && <span className=\"block\">{entry.description}</span>}\n {unverifiedLine}\n </>\n ) : (\n entry.description\n );\n return (\n <div key={entry.id} data-notification-type={entry.id} data-channels={single} className=\"space-y-2\">\n <Switch\n label={entry.label}\n description={description}\n checked={channelOn(row, single)}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onCheckedChange={(next) => flip(entry.id, single, next)}\n />\n {below}\n </div>\n );\n }\n\n // Several channels: a group named by its type, a switch per channel — columns on a\n // wide screen (the headings above the list name them), stacked on a phone.\n const labelId = `${groupId}-type-${entry.id}`;\n const unverifiedId = `${groupId}-unverified-${entry.id}`;\n const channelSwitch = (channel: NotificationChannel) => (\n <Switch\n key={channel}\n size=\"sm\"\n label={phone ? channelLabel[channel] : undefined}\n aria-label={phone ? undefined : channelLabel[channel]}\n description={phone && channel === \"email\" ? (unverifiedLine ?? undefined) : undefined}\n aria-describedby={!phone && channel === \"email\" && unverifiedLine ? unverifiedId : undefined}\n checked={channelOn(row, channel)}\n disabled={disabled}\n commit={COMMIT_EXCEPT_BILLING}\n onCheckedChange={(next) => flip(entry.id, channel, next)}\n data-channel={channel}\n />\n );\n const text = (\n <div className=\"min-w-0\">\n <div id={labelId} className=\"text-sm font-medium text-primary\">\n {entry.label}\n </div>\n {(entry.description !== undefined || (!phone && offered.includes(\"email\") && unverifiedLine)) && (\n <div className={CARD_DESCRIPTION_CLASS}>\n {entry.description !== undefined && <span className=\"block\">{entry.description}</span>}\n {!phone && offered.includes(\"email\") && <span id={unverifiedId}>{unverifiedLine}</span>}\n </div>\n )}\n </div>\n );\n return (\n <div\n key={entry.id}\n data-notification-type={entry.id}\n data-channels={offered.join(\" \")}\n role=\"group\"\n aria-labelledby={labelId}\n className=\"space-y-2\"\n >\n {phone ? (\n <>\n {text}\n <div className=\"ps-4 space-y-2\" data-stacked=\"\">\n {offered.map(channelSwitch)}\n </div>\n </>\n ) : (\n <div className={cn(\"grid items-start gap-x-2\", COLUMN_GRID[columns.length])}>\n {text}\n {columns.map((channel) => (\n <div key={channel} className=\"flex justify-center pt-0.5\">\n {offered.includes(channel) ? channelSwitch(channel) : null}\n </div>\n ))}\n </div>\n )}\n {below}\n </div>\n );\n };\n\n let body: ReactNode;\n if (loading || value === undefined) {\n body = <Skeleton lines={3} label={labels.typesLoading} />;\n } else if (groups) {\n const drawn = groups\n .map((group) => ({ group, rows: rowsOf(group.types) }))\n .filter(({ rows }) => rows.length > 0);\n body =\n drawn.length === 0 ? (\n <p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>\n ) : (\n <>\n {columnHeadings}\n {drawn.map(({ group, rows }) => {\n const headingId = `${groupId}-${group.id}`;\n return (\n <div key={group.id} role=\"group\" aria-labelledby={headingId} className=\"space-y-3\">\n <SectionLabel as=\"div\" size=\"xs\" id={headingId}>\n {group.label}\n </SectionLabel>\n {rows.map(renderRow)}\n </div>\n );\n })}\n </>\n );\n } else {\n const rows = rowsOf(types.map((entry) => entry.id));\n body =\n rows.length === 0 ? (\n <p className={CARD_DESCRIPTION_CLASS}>{labels.typesEmpty}</p>\n ) : (\n <div className=\"space-y-3\">\n {columnHeadings}\n {rows.map(renderRow)}\n </div>\n );\n }\n\n return (\n <Card {...rest} className={cn(\"p-4 space-y-3\", className)}>\n <div>\n <SettingsCardTitle>{labels.typesTitle}</SettingsCardTitle>\n <div className={CARD_D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