@eifi1/ui-kit 0.41.0 → 0.43.0
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 -7
- package/dist/admin/admin-area-labels.d.ts +59 -0
- package/dist/admin/admin-area-labels.js +35 -0
- package/dist/admin/admin-area-labels.js.map +1 -0
- package/dist/admin/admin-forbidden.d.ts +35 -0
- package/dist/admin/admin-forbidden.js +36 -0
- package/dist/admin/admin-forbidden.js.map +1 -0
- package/dist/admin/admin-overview.d.ts +110 -0
- package/dist/admin/admin-overview.js +92 -0
- package/dist/admin/admin-overview.js.map +1 -0
- package/dist/admin/admin-sections.d.ts +94 -0
- package/dist/admin/admin-sections.js +81 -0
- package/dist/admin/admin-sections.js.map +1 -0
- package/dist/admin/admin-tool-links.d.ts +48 -0
- package/dist/admin/admin-tool-links.js +31 -0
- package/dist/admin/admin-tool-links.js.map +1 -0
- package/dist/billing/billing-banner.d.ts +33 -2
- package/dist/billing/billing-banner.js +29 -3
- package/dist/billing/billing-banner.js.map +1 -1
- package/dist/billing/billing-labels.d.ts +36 -0
- package/dist/billing/billing-labels.js +10 -0
- package/dist/billing/billing-labels.js.map +1 -1
- package/dist/billing/billing-overview.d.ts +33 -0
- package/dist/billing/billing-overview.js +6 -0
- package/dist/billing/billing-overview.js.map +1 -1
- package/dist/billing/billing-standing.d.ts +8 -0
- package/dist/billing/billing-standing.js.map +1 -1
- package/dist/billing/cancel-request.d.ts +53 -0
- package/dist/billing/cancel-request.js +21 -0
- package/dist/billing/cancel-request.js.map +1 -0
- package/dist/billing/cancel-subscription.d.ts +46 -0
- package/dist/billing/cancel-subscription.js +57 -0
- package/dist/billing/cancel-subscription.js.map +1 -0
- package/dist/billing/plan-card.d.ts +45 -1
- package/dist/billing/plan-card.js +53 -2
- package/dist/billing/plan-card.js.map +1 -1
- package/dist/billing/plan-switch.d.ts +10 -1
- package/dist/billing/plan-switch.js +22 -13
- package/dist/billing/plan-switch.js.map +1 -1
- package/dist/billing/provider-page.d.ts +40 -0
- package/dist/billing/provider-page.js +33 -0
- package/dist/billing/provider-page.js.map +1 -0
- package/dist/billing/subscription-actions.d.ts +68 -4
- package/dist/billing/subscription-actions.js +65 -5
- package/dist/billing/subscription-actions.js.map +1 -1
- package/dist/components/account-chips.d.ts +50 -2
- package/dist/components/account-chips.js +33 -0
- package/dist/components/account-chips.js.map +1 -1
- package/dist/components/empty-state.d.ts +2 -1
- package/dist/components/empty-state.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/feedback/feedback-menu.d.ts +7 -4
- package/dist/feedback/feedback-menu.js +4 -2
- package/dist/feedback/feedback-menu.js.map +1 -1
- package/dist/hooks/use-search-param-state.js +4 -1
- package/dist/hooks/use-search-param-state.js.map +1 -1
- package/dist/i18n/defaults.js +7 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +113 -0
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +12 -0
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +142 -1
- package/dist/i18n/locales/en.js.map +3 -3
- package/dist/i18n/locales/es.js +110 -0
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +109 -0
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +110 -0
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +110 -0
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +109 -0
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +34 -1
- package/dist/i18n/review.js.map +1 -1
- package/dist/index.d.ts +24 -2
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/search/global-search.d.ts +3 -0
- package/dist/search/global-search.js +3 -1
- package/dist/search/global-search.js.map +1 -1
- package/dist/settings/settings-catalogue.d.ts +9 -1
- package/dist/settings/settings-catalogue.js +1 -1
- package/dist/settings/settings-catalogue.js.map +1 -1
- package/dist/settings/settings-layout.d.ts +7 -1
- package/dist/settings/settings-layout.js +35 -27
- package/dist/settings/settings-layout.js.map +1 -1
- package/dist/shell/account-menu-language.d.ts +46 -0
- package/dist/shell/account-menu-language.js +64 -0
- package/dist/shell/account-menu-language.js.map +1 -0
- package/dist/shell/admin-menu.d.ts +69 -0
- package/dist/shell/admin-menu.js +64 -0
- package/dist/shell/admin-menu.js.map +1 -0
- package/dist/shell/app-shell.d.ts +10 -0
- package/dist/shell/app-shell.js +22 -4
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/dev-switchers.d.ts +53 -0
- package/dist/shell/dev-switchers.js +107 -0
- package/dist/shell/dev-switchers.js.map +1 -0
- package/dist/shell/sync-status-indicator.d.ts +86 -0
- package/dist/shell/sync-status-indicator.js +170 -0
- package/dist/shell/sync-status-indicator.js.map +1 -0
- package/dist/shell/top-bar-actions.d.ts +49 -0
- package/dist/shell/top-bar-actions.js +31 -0
- package/dist/shell/top-bar-actions.js.map +1 -0
- package/dist/shell/top-bar-parts-labels.d.ts +90 -0
- package/dist/shell/top-bar-parts-labels.js +51 -0
- package/dist/shell/top-bar-parts-labels.js.map +1 -0
- package/dist/shell/topbar-action-menu.d.ts +13 -1
- package/dist/shell/topbar-action-menu.js +5 -2
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell/topbar-controls.d.ts +16 -3
- package/dist/shell/topbar-controls.js +5 -1
- package/dist/shell/topbar-controls.js.map +1 -1
- package/dist/shell/tour-menu.d.ts +67 -0
- package/dist/shell/tour-menu.js +87 -0
- package/dist/shell/tour-menu.js.map +1 -0
- package/dist/shell.d.ts +16 -0
- package/dist/shell.js +21 -0
- package/dist/shell.js.map +1 -1
- package/dist/tour/tour-catalogue-labels.d.ts +44 -0
- package/dist/tour/tour-catalogue-labels.js +32 -0
- package/dist/tour/tour-catalogue-labels.js.map +1 -0
- package/dist/tour/tour-catalogue.d.ts +68 -0
- package/dist/tour/tour-catalogue.js +189 -0
- package/dist/tour/tour-catalogue.js.map +1 -0
- package/dist/tour/tour-info.d.ts +112 -0
- package/dist/tour/tour-info.js +36 -0
- package/dist/tour/tour-info.js.map +1 -0
- package/dist/tour/use-tour-progress.d.ts +61 -0
- package/dist/tour/use-tour-progress.js +116 -0
- package/dist/tour/use-tour-progress.js.map +1 -0
- package/dist/tour/use-tour-url-sync.d.ts +58 -0
- package/dist/tour/use-tour-url-sync.js +110 -0
- package/dist/tour/use-tour-url-sync.js.map +1 -0
- package/dist/tour.d.ts +8 -0
- package/dist/tour.js +18 -0
- package/dist/tour.js.map +1 -1
- package/package.json +1 -1
- package/src/admin/admin-area-labels.ts +91 -0
- package/src/admin/admin-forbidden.tsx +75 -0
- package/src/admin/admin-overview.tsx +217 -0
- package/src/admin/admin-sections.tsx +198 -0
- package/src/admin/admin-tool-links.tsx +84 -0
- package/src/billing/billing-banner.tsx +57 -6
- package/src/billing/billing-labels.ts +59 -0
- package/src/billing/billing-overview.ts +37 -0
- package/src/billing/billing-standing.ts +8 -0
- package/src/billing/cancel-request.ts +75 -0
- package/src/billing/cancel-subscription.tsx +102 -0
- package/src/billing/plan-card.tsx +97 -1
- package/src/billing/plan-switch.tsx +16 -0
- package/src/billing/provider-page.ts +75 -0
- package/src/billing/subscription-actions.tsx +155 -20
- package/src/components/account-chips.tsx +89 -2
- package/src/components/empty-state.tsx +2 -1
- package/src/feedback/feedback-menu.tsx +8 -3
- package/src/hooks/use-search-param-state.ts +6 -1
- package/src/i18n/defaults.ts +6 -0
- package/src/i18n/german.ts +127 -0
- package/src/i18n/kit-labels.tsx +12 -0
- package/src/i18n/locales/en.ts +32 -0
- package/src/i18n/locales/es.ts +121 -0
- package/src/i18n/locales/fr.ts +121 -0
- package/src/i18n/locales/hu.ts +119 -0
- package/src/i18n/locales/it.ts +122 -0
- package/src/i18n/locales/zh.ts +114 -0
- package/src/i18n/review.ts +33 -0
- package/src/index.ts +38 -2
- package/src/search/global-search.tsx +5 -0
- package/src/settings/settings-catalogue.ts +10 -2
- package/src/settings/settings-layout.tsx +58 -34
- package/src/shell/account-menu-language.tsx +116 -0
- package/src/shell/admin-menu.tsx +146 -0
- package/src/shell/app-shell.tsx +44 -3
- package/src/shell/dev-switchers.tsx +179 -0
- package/src/shell/sync-status-indicator.tsx +301 -0
- package/src/shell/top-bar-actions.tsx +79 -0
- package/src/shell/top-bar-parts-labels.ts +142 -0
- package/src/shell/topbar-action-menu.tsx +15 -2
- package/src/shell/topbar-controls.tsx +20 -3
- package/src/shell/tour-menu.tsx +179 -0
- package/src/shell.ts +27 -0
- package/src/tour/tour-catalogue-labels.ts +75 -0
- package/src/tour/tour-catalogue.tsx +316 -0
- package/src/tour/tour-info.ts +144 -0
- package/src/tour/use-tour-progress.ts +198 -0
- package/src/tour/use-tour-url-sync.ts +221 -0
- package/src/tour.ts +11 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { AlertBanner } from "../components/alert-banner";
|
|
3
|
+
import { Button } from "../components/button";
|
|
4
|
+
import { StatTile, StatTileGrid } from "../components/stat-tile";
|
|
5
|
+
import type { StatTileProps } from "../components/stat-tile";
|
|
6
|
+
import type { LabelOverride } from "../i18n/kit-labels";
|
|
7
|
+
import { cn } from "../lib/cn";
|
|
8
|
+
import { useAdminAreaLabels } from "./admin-area-labels";
|
|
9
|
+
import type { AdminAreaLabels } from "./admin-area-labels";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The admin's start page (0.42.0, docs/admin-harmonization.md §2.4, §6.1–§6.5): a grid
|
|
13
|
+
* of tiles, each a count of what is waiting and a link to where the work is, fed by one
|
|
14
|
+
* server answer.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `GET /admin/attention` (§2.4 decision 14, §6.4) — server-kit's `AdminAttention`
|
|
19
|
+
* (`eifi1_server_kit.user_admin.attention`), as the API sends it.
|
|
20
|
+
*
|
|
21
|
+
* Each count is `null` where the app has no such thing or this viewer cannot act on it,
|
|
22
|
+
* and every count is `null` in a demo session. Demo accounts never count. `extra` holds
|
|
23
|
+
* the app's own counts, keyed as its overview names them (keksdose `support_waiting`,
|
|
24
|
+
* Kurvenschmiede `released_for_work`).
|
|
25
|
+
*/
|
|
26
|
+
export interface AdminAttention {
|
|
27
|
+
/** "To triage": OPEN reports, crash reports included (§6.1). */
|
|
28
|
+
feedback_waiting: number | null;
|
|
29
|
+
/** Accounts that asked to be deleted — only where this viewer acts on them (§6.2). */
|
|
30
|
+
deletion_requests: number | null;
|
|
31
|
+
invitations_pending: number | null;
|
|
32
|
+
users_total: number | null;
|
|
33
|
+
/** Accounts made in the last seven days. */
|
|
34
|
+
users_new_7d: number | null;
|
|
35
|
+
extra: Record<string, number | null>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The shared counts that are a tile of their own (`users_new_7d` is the users tile's line). */
|
|
39
|
+
export type AdminAttentionTile = "feedback_waiting" | "deletion_requests" | "invitations_pending" | "users_total";
|
|
40
|
+
|
|
41
|
+
/** Where each shared tile links when the app names nothing else (§2.4 decision 13). */
|
|
42
|
+
export const DEFAULT_ADMIN_ATTENTION_HREFS: Readonly<Record<AdminAttentionTile, string>> = Object.freeze({
|
|
43
|
+
feedback_waiting: "/feedback",
|
|
44
|
+
deletion_requests: "/admin/users?state=deletion_requested",
|
|
45
|
+
invitations_pending: "/admin/invitations",
|
|
46
|
+
users_total: "/admin/users",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The account menu's badge (§2.4 decision 15, §6.3): the sum of the counts that are work
|
|
51
|
+
* waiting on THIS admin — each app names its own (keksdose `["feedback_waiting",
|
|
52
|
+
* "support_waiting", "awaiting_verdict"]`, kastlan `["feedback_waiting"]`, Kurvenschmiede
|
|
53
|
+
* `["feedback_waiting", "deletion_requests"]`). A name is a shared count or an `extra`
|
|
54
|
+
* key; a `null` or missing count adds nothing. Invitations and users never belong in it.
|
|
55
|
+
* `null` while there is no answer yet, so the badge shows nothing rather than a 0.
|
|
56
|
+
*/
|
|
57
|
+
export function adminWaitingCount(
|
|
58
|
+
attention: AdminAttention | null | undefined,
|
|
59
|
+
counts: readonly (AdminAttentionTile | (string & {}))[],
|
|
60
|
+
): number | null {
|
|
61
|
+
if (!attention) return null;
|
|
62
|
+
let sum = 0;
|
|
63
|
+
for (const key of counts) {
|
|
64
|
+
const shared = (attention as unknown as Record<string, unknown>)[key];
|
|
65
|
+
const value = typeof shared === "number" ? shared : attention.extra?.[key];
|
|
66
|
+
if (typeof value === "number" && value > 0) sum += value;
|
|
67
|
+
}
|
|
68
|
+
return sum;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface AttentionTileProps extends Omit<StatTileProps, "href" | "onClick" | "value"> {
|
|
72
|
+
/** The count. `null` shows the tile's dash; {@link AdminOverview} leaves such a tile out. */
|
|
73
|
+
count: number | null | undefined;
|
|
74
|
+
/** Where the work is — the tile is a link to it. Since 0.43 it may be left out: a
|
|
75
|
+
* quiet count, no link (Kurvenschmiede). */
|
|
76
|
+
href?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* One tile of the overview: a {@link StatTile} that is a LINK to where the work is, its
|
|
81
|
+
* count the headline. The whole tile is the link, named by its label; route it through
|
|
82
|
+
* `renderLink` or the provider's link component, as any StatTile. Without `href` (0.43) it
|
|
83
|
+
* is a quiet count, no link.
|
|
84
|
+
*/
|
|
85
|
+
export function AttentionTile({ count, href, ...tile }: AttentionTileProps) {
|
|
86
|
+
return <StatTile data-slot="attention-tile" {...tile} value={count ?? null} href={href} />;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One of the app's own tiles (§2.4 decision 13: keksdose's "Support waiting"). */
|
|
90
|
+
export interface AdminExtraTile {
|
|
91
|
+
/** Unique among the tiles; usually the `extra` key it shows. */
|
|
92
|
+
key: string;
|
|
93
|
+
label: ReactNode;
|
|
94
|
+
/** `null` or `undefined` leaves the tile out, as for a shared one. */
|
|
95
|
+
count: number | null | undefined;
|
|
96
|
+
/** Where the work is. Left out (0.43, Kurvenschmiede): a quiet count with no link —
|
|
97
|
+
* a number worth seeing that has no page of its own. */
|
|
98
|
+
href?: string;
|
|
99
|
+
/** A line under the count. */
|
|
100
|
+
description?: ReactNode;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface AdminOverviewProps {
|
|
104
|
+
/** The server's answer; `undefined` while it loads (the grid shows its skeletons). */
|
|
105
|
+
attention: AdminAttention | null | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Where the shared tiles link, over {@link DEFAULT_ADMIN_ATTENTION_HREFS} — the
|
|
108
|
+
* inbox's address filtered to OPEN (§6.1) is the app's own:
|
|
109
|
+
* `{ feedback_waiting: "/feedback?status=OPEN" }`.
|
|
110
|
+
*/
|
|
111
|
+
hrefs?: Partial<Record<AdminAttentionTile, string>>;
|
|
112
|
+
/** The app's own tiles, after the shared ones, in this order. */
|
|
113
|
+
extraTiles?: readonly AdminExtraTile[];
|
|
114
|
+
/** Passed to every tile — `renderLink` for the router, `size`, `variant`. */
|
|
115
|
+
tileProps?: Pick<StatTileProps, "renderLink" | "size" | "variant" | "locale">;
|
|
116
|
+
/**
|
|
117
|
+
* 0.43 (keksdose): the answer failed — the query's `error`, or `true`. Anything truthy
|
|
118
|
+
* shows `adminArea.overviewError` in a danger box, with "Try again" when
|
|
119
|
+
* {@link onRetry} is given. A failed poll keeps the last good tiles: with `attention`
|
|
120
|
+
* still there (a query keeps its last data), the box shows ALONGSIDE them, above, not
|
|
121
|
+
* instead (build review 0.43, keksdose N7) — pass `attention.data` as it is. Without
|
|
122
|
+
* an answer yet, the box alone. Without `error`: `undefined` is the skeletons and
|
|
123
|
+
* `null` nothing, as before.
|
|
124
|
+
*/
|
|
125
|
+
error?: unknown;
|
|
126
|
+
/** "Try again" in the error box — the query's `refetch`. */
|
|
127
|
+
onRetry?: () => void;
|
|
128
|
+
/** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
|
|
129
|
+
labels?: LabelOverride<AdminAreaLabels>;
|
|
130
|
+
className?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The overview section (§2.4): the shared tiles in their order — To triage, Deletion
|
|
135
|
+
* requests, Pending invitations, Users (with the new accounts of the last 7 days under
|
|
136
|
+
* the total) — then the app's `extraTiles`. A tile whose count is `null` is left out,
|
|
137
|
+
* so each app shows only what it has; a `0` is a quiet tile, "nothing waiting".
|
|
138
|
+
*
|
|
139
|
+
* The overview is the admin area's landing page, standalone: it is NOT wrapped in a
|
|
140
|
+
* `SettingsSection` (`adminSections` gives it no entry; render it as the page's body, as
|
|
141
|
+
* Kurvenschmiede's `OverviewPanel` does). keksdose links its metrics from here with at
|
|
142
|
+
* most two tiles (§6.5).
|
|
143
|
+
*/
|
|
144
|
+
export function AdminOverview({
|
|
145
|
+
attention,
|
|
146
|
+
hrefs,
|
|
147
|
+
extraTiles = [],
|
|
148
|
+
tileProps,
|
|
149
|
+
error,
|
|
150
|
+
onRetry,
|
|
151
|
+
labels: labelsProp,
|
|
152
|
+
className,
|
|
153
|
+
}: AdminOverviewProps) {
|
|
154
|
+
const labels = useAdminAreaLabels(labelsProp);
|
|
155
|
+
/** The error box: on its own (`alone`) it is the overview's root. */
|
|
156
|
+
const errorBox = (alone: boolean) => (
|
|
157
|
+
<AlertBanner
|
|
158
|
+
data-slot={alone ? "admin-overview" : undefined}
|
|
159
|
+
data-state={alone ? "error" : undefined}
|
|
160
|
+
variant="box"
|
|
161
|
+
tone="danger"
|
|
162
|
+
className={alone ? className : undefined}
|
|
163
|
+
action={
|
|
164
|
+
onRetry ? (
|
|
165
|
+
<Button type="button" variant="secondary" size="sm" onClick={() => onRetry()}>
|
|
166
|
+
{labels.retry}
|
|
167
|
+
</Button>
|
|
168
|
+
) : undefined
|
|
169
|
+
}
|
|
170
|
+
>
|
|
171
|
+
{labels.overviewError}
|
|
172
|
+
</AlertBanner>
|
|
173
|
+
);
|
|
174
|
+
// Nothing good to keep: the box alone.
|
|
175
|
+
if (error && !attention) return errorBox(true);
|
|
176
|
+
const href = { ...DEFAULT_ADMIN_ATTENTION_HREFS, ...hrefs };
|
|
177
|
+
const loading = attention === undefined;
|
|
178
|
+
const shared: { key: AdminAttentionTile; label: string; description?: ReactNode }[] = [
|
|
179
|
+
{ key: "feedback_waiting", label: labels.tiles.feedbackWaiting },
|
|
180
|
+
{ key: "deletion_requests", label: labels.tiles.deletionRequests },
|
|
181
|
+
{ key: "invitations_pending", label: labels.tiles.invitationsPending },
|
|
182
|
+
{
|
|
183
|
+
key: "users_total",
|
|
184
|
+
label: labels.tiles.users,
|
|
185
|
+
description:
|
|
186
|
+
attention && typeof attention.users_new_7d === "number" ? labels.tiles.usersNew(attention.users_new_7d) : undefined,
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
const tiles = [
|
|
190
|
+
...shared.map((t) => ({ ...t, count: attention ? attention[t.key] : undefined, href: href[t.key] })),
|
|
191
|
+
...extraTiles,
|
|
192
|
+
].filter((t) => loading || (t.count !== null && t.count !== undefined));
|
|
193
|
+
if (!loading && tiles.length === 0) return error ? errorBox(true) : null;
|
|
194
|
+
const grid = (
|
|
195
|
+
<StatTileGrid data-slot={error ? undefined : "admin-overview"} loading={loading} className={error ? undefined : className}>
|
|
196
|
+
{tiles.map((t) => (
|
|
197
|
+
<AttentionTile
|
|
198
|
+
key={t.key}
|
|
199
|
+
{...tileProps}
|
|
200
|
+
data-attention={t.key}
|
|
201
|
+
label={t.label}
|
|
202
|
+
count={t.count}
|
|
203
|
+
href={t.href}
|
|
204
|
+
description={t.description}
|
|
205
|
+
/>
|
|
206
|
+
))}
|
|
207
|
+
</StatTileGrid>
|
|
208
|
+
);
|
|
209
|
+
if (!error) return grid;
|
|
210
|
+
// A failed poll: the error above the last good tiles.
|
|
211
|
+
return (
|
|
212
|
+
<div data-slot="admin-overview" data-state="error" className={cn("space-y-4", className)}>
|
|
213
|
+
{errorBox(false)}
|
|
214
|
+
{grid}
|
|
215
|
+
</div>
|
|
216
|
+
);
|
|
217
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { History, LayoutDashboard, Mail, Receipt, Users } from "lucide-react";
|
|
4
|
+
import type { LucideIcon } from "lucide-react";
|
|
5
|
+
import type { SettingsGroup } from "../settings/settings-catalogue";
|
|
6
|
+
import { DEFAULT_ADMIN_AREA_LABELS } from "./admin-area-labels";
|
|
7
|
+
import type { AdminAreaLabels, AdminSharedSection } from "./admin-area-labels";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The admin area's sections (0.42.0, docs/admin-harmonization.md §2.3, §6.8): the five
|
|
11
|
+
* every app shares, in the template's order, and the helper that builds an app's
|
|
12
|
+
* `SettingsLayout` catalogue groups from them and the app's own.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** One shared section: its path segment and its icon. The words are `adminArea.sections`. */
|
|
16
|
+
export interface AdminSectionDefinition {
|
|
17
|
+
id: AdminSharedSection;
|
|
18
|
+
icon: LucideIcon;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The shared sections in the template's order (§2.3 decision 10, §6.13): Overview, Users,
|
|
23
|
+
* Invitations, Billing, Activity. An app's own sections go between them
|
|
24
|
+
* ({@link adminSections}).
|
|
25
|
+
*/
|
|
26
|
+
export const ADMIN_SECTIONS: readonly AdminSectionDefinition[] = Object.freeze([
|
|
27
|
+
{ id: "overview", icon: LayoutDashboard },
|
|
28
|
+
{ id: "users", icon: Users },
|
|
29
|
+
{ id: "invitations", icon: Mail },
|
|
30
|
+
{ id: "billing", icon: Receipt },
|
|
31
|
+
{ id: "activity", icon: History },
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One of the app's own sections: a catalogue group with its words, plus where it goes.
|
|
36
|
+
* `after` names the section it follows — a shared one or another of the app's own. Left
|
|
37
|
+
* out, it goes where the template puts an app's sections, after Invitations and before
|
|
38
|
+
* Billing, in the order given.
|
|
39
|
+
*/
|
|
40
|
+
export interface AdminOwnSection<G extends string = string> extends SettingsGroup<G> {
|
|
41
|
+
after?: AdminSharedSection | G;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Where one section goes, without its words — what {@link adminSectionOrder} takes. An
|
|
45
|
+
* {@link AdminOwnSection} is one. */
|
|
46
|
+
export interface AdminSectionPlace<G extends string = string> {
|
|
47
|
+
id: G;
|
|
48
|
+
after?: AdminSharedSection | G;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The order's options: the shared sections an app does not have. */
|
|
52
|
+
export interface AdminSectionOrderOptions<L extends AdminSharedSection = AdminSharedSection> {
|
|
53
|
+
/**
|
|
54
|
+
* Shared sections this app does not have — keksdose and Kurvenschmiede have no billing
|
|
55
|
+
* view (`["billing"]`). Left out, every shared section is in the catalogue. Since 0.43
|
|
56
|
+
* the result's type leaves them out too, so no cast is needed to drop `"billing"` —
|
|
57
|
+
* when TypeScript infers the type arguments. With them written out, name the left-out
|
|
58
|
+
* ones as the second (`adminSections<Own, "billing">(…)`); `adminSections<Own>(…)`
|
|
59
|
+
* keeps every shared id in the type, as before.
|
|
60
|
+
*/
|
|
61
|
+
leaveOut?: readonly L[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface AdminSectionsOptions<L extends AdminSharedSection = AdminSharedSection> extends AdminSectionOrderOptions<L> {
|
|
65
|
+
/**
|
|
66
|
+
* A shared section that is in the catalogue but hidden for now, as
|
|
67
|
+
* {@link SettingsGroup.visible}: kastlan's `{ billing: billingEnabled }` (settings §5),
|
|
68
|
+
* whose path then acts as an unknown one.
|
|
69
|
+
*/
|
|
70
|
+
visible?: Partial<Record<AdminSharedSection, boolean>>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The shared sections an app keeps when it leaves out `L`. A `leaveOut` typed as the
|
|
74
|
+
* whole union (a variable of `AdminSharedSection[]`) says nothing about which, so it
|
|
75
|
+
* narrows nothing. */
|
|
76
|
+
export type AdminKeptSection<L extends AdminSharedSection = AdminSharedSection> = [AdminSharedSection] extends [L]
|
|
77
|
+
? AdminSharedSection
|
|
78
|
+
: Exclude<AdminSharedSection, L>;
|
|
79
|
+
|
|
80
|
+
/** The shared section after which the app's sections go when they name no place. */
|
|
81
|
+
const OWN_DEFAULT_AFTER: AdminSharedSection = "invitations";
|
|
82
|
+
|
|
83
|
+
/** The shared and own sections in their order — a shared one as its definition, an own
|
|
84
|
+
* one as given. Throws as {@link adminSections} documents. */
|
|
85
|
+
function orderSections<S extends AdminSectionPlace<string>>(
|
|
86
|
+
own: readonly S[],
|
|
87
|
+
leaveOutIds: readonly AdminSharedSection[] | undefined,
|
|
88
|
+
): ({ shared: AdminSectionDefinition } | { own: S })[] {
|
|
89
|
+
const leaveOut = new Set<string>(leaveOutIds ?? []);
|
|
90
|
+
const shared = new Set<string>(ADMIN_SECTIONS.map((s) => s.id));
|
|
91
|
+
const ownIds = new Set<string>();
|
|
92
|
+
for (const section of own) {
|
|
93
|
+
if (shared.has(section.id)) throw new Error(`adminSections: "${section.id}" is a shared section's id`);
|
|
94
|
+
if (ownIds.has(section.id)) throw new Error(`adminSections: "${section.id}" is given twice`);
|
|
95
|
+
ownIds.add(section.id);
|
|
96
|
+
}
|
|
97
|
+
for (const section of own) {
|
|
98
|
+
const after = section.after;
|
|
99
|
+
if (after !== undefined && !shared.has(after) && !ownIds.has(after)) {
|
|
100
|
+
throw new Error(`adminSections: "${section.id}" goes after "${after}", which is no section`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Each section's followers, in the order given: the shared ones, then the own ones
|
|
105
|
+
// under their `after`, recursively, so an own section may follow another own one.
|
|
106
|
+
const followers = new Map<string, S[]>();
|
|
107
|
+
for (const section of own) {
|
|
108
|
+
const after = section.after ?? OWN_DEFAULT_AFTER;
|
|
109
|
+
followers.set(after, [...(followers.get(after) ?? []), section]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const out: ({ shared: AdminSectionDefinition } | { own: S })[] = [];
|
|
113
|
+
const placed = new Set<string>();
|
|
114
|
+
const placeAfter = (id: string) => {
|
|
115
|
+
for (const section of followers.get(id) ?? []) {
|
|
116
|
+
out.push({ own: section });
|
|
117
|
+
placed.add(section.id);
|
|
118
|
+
placeAfter(section.id);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
for (const definition of ADMIN_SECTIONS) {
|
|
122
|
+
if (!leaveOut.has(definition.id)) out.push({ shared: definition });
|
|
123
|
+
// A left-out section's followers keep its place.
|
|
124
|
+
placeAfter(definition.id);
|
|
125
|
+
}
|
|
126
|
+
const stuck = own.filter((s) => !placed.has(s.id)).map((s) => s.id);
|
|
127
|
+
if (stuck.length) throw new Error(`adminSections: ${stuck.join(", ")} follow each other in a circle`);
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The admin area's section ids in the template's order (0.43, keksdose) — what
|
|
133
|
+
* {@link adminSections} builds its groups in, without the words: for an app that needs the
|
|
134
|
+
* ORDER only (a router's list of paths, a test), outside a component, with no labels.
|
|
135
|
+
*
|
|
136
|
+
* adminSectionOrder([{ id: "metrics", after: "overview" }], { leaveOut: ["billing"] })
|
|
137
|
+
* // ["overview", "metrics", "users", "invitations", "activity"]
|
|
138
|
+
*
|
|
139
|
+
* Throws as {@link adminSections} does.
|
|
140
|
+
*/
|
|
141
|
+
export function adminSectionOrder<G extends string = never, L extends AdminSharedSection = AdminSharedSection>(
|
|
142
|
+
own: readonly AdminSectionPlace<G>[] = [],
|
|
143
|
+
options: AdminSectionOrderOptions<L> = {},
|
|
144
|
+
): (AdminKeptSection<L> | G)[] {
|
|
145
|
+
return orderSections(own, options.leaveOut).map((s) =>
|
|
146
|
+
"shared" in s ? (s.shared.id as AdminKeptSection<L>) : s.own.id,
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* An app's admin catalogue groups, in the template's order (§2.3 decision 10, §6.8): the
|
|
152
|
+
* shared sections with the kit's icons and words, and the app's own at the places they
|
|
153
|
+
* name. The result is `SettingsLayout`'s `groups`; the entries stay the app's (a group
|
|
154
|
+
* with no visible entry is hidden, as on any settings page — except, since 0.43, the
|
|
155
|
+
* Overview, a page of tiles that needs no entry: it is `standalone`). Since 0.43 the
|
|
156
|
+
* result's type leaves out the `leaveOut` sections, and {@link adminSectionOrder} gives
|
|
157
|
+
* the same order as ids, without words.
|
|
158
|
+
*
|
|
159
|
+
* const groups = adminSections(useAdminAreaLabels(), [
|
|
160
|
+
* { id: "metrics", icon: <BarChart3 />, title: t("…"), help: t("…"), after: "overview" },
|
|
161
|
+
* { id: "messaging", icon: <MessageSquare />, title: t("…"), help: t("…") },
|
|
162
|
+
* { id: "health", icon: <HeartPulse />, title: t("…"), help: t("…"), after: "billing" },
|
|
163
|
+
* ], { leaveOut: ["billing"] });
|
|
164
|
+
*
|
|
165
|
+
* gives keksdose's overview, metrics, users, invitations, messaging, health, activity.
|
|
166
|
+
* An `after` that names a left-out section takes that section's place. Kurvenschmiede's
|
|
167
|
+
* Teams needs no `after`: between Invitations and Activity is the default.
|
|
168
|
+
*
|
|
169
|
+
* `labels` is the `adminArea` namespace, resolved — {@link useAdminAreaLabels} inside a
|
|
170
|
+
* component, or the app's catalogue for the language; `undefined` is English. Throws for
|
|
171
|
+
* an own section whose id is a shared one, an id given twice, or an `after` that names no
|
|
172
|
+
* section: the catalogue is built once, and a section quietly missing from it is worse.
|
|
173
|
+
*/
|
|
174
|
+
export function adminSections<G extends string = never, L extends AdminSharedSection = AdminSharedSection>(
|
|
175
|
+
labels: AdminAreaLabels | undefined,
|
|
176
|
+
own: readonly AdminOwnSection<G>[] = [],
|
|
177
|
+
options: AdminSectionsOptions<L> = {},
|
|
178
|
+
): SettingsGroup<AdminKeptSection<L> | G>[] {
|
|
179
|
+
const words = labels ?? DEFAULT_ADMIN_AREA_LABELS;
|
|
180
|
+
return orderSections(own, options.leaveOut).map((s): SettingsGroup<AdminKeptSection<L> | G> => {
|
|
181
|
+
if ("own" in s) {
|
|
182
|
+
const { after: _after, ...group } = s.own;
|
|
183
|
+
return group;
|
|
184
|
+
}
|
|
185
|
+
const { id, icon } = s.shared;
|
|
186
|
+
const visible = options.visible?.[id];
|
|
187
|
+
return {
|
|
188
|
+
id: id as AdminKeptSection<L>,
|
|
189
|
+
icon: createElement(icon, { "aria-hidden": true }) as ReactNode,
|
|
190
|
+
title: words.sections[id].title,
|
|
191
|
+
help: words.sections[id].help,
|
|
192
|
+
// 0.43 (kastlan): the overview is a page of tiles, not of setting cards — it shows
|
|
193
|
+
// with no entry of its own.
|
|
194
|
+
...(id === "overview" ? { standalone: true } : null),
|
|
195
|
+
...(visible === undefined ? null : { visible }),
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { useId } from "react";
|
|
2
|
+
import type { ReactElement, ReactNode } from "react";
|
|
3
|
+
import { cn } from "../lib/cn";
|
|
4
|
+
import { List, ListItem } from "../components/list";
|
|
5
|
+
import type { ListItemLinkProps } from "../components/list";
|
|
6
|
+
import type { LabelOverride } from "../i18n/kit-labels";
|
|
7
|
+
import { useAdminAreaLabels } from "./admin-area-labels";
|
|
8
|
+
import type { AdminAreaLabels } from "./admin-area-labels";
|
|
9
|
+
|
|
10
|
+
/** One link of the Tools list. */
|
|
11
|
+
export interface AdminToolLink {
|
|
12
|
+
/** Unique in the list. */
|
|
13
|
+
key: string;
|
|
14
|
+
label: string;
|
|
15
|
+
href: string;
|
|
16
|
+
/** A lucide element, sized by the row. */
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
/** `false` leaves the link out — Translations for an admin who doesn't review
|
|
19
|
+
* (§6.11, ka F7). Default: shown. */
|
|
20
|
+
visible?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AdminToolLinksProps {
|
|
24
|
+
links: readonly AdminToolLink[];
|
|
25
|
+
/**
|
|
26
|
+
* `sidebar` (default): a `<nav>` named and headed "Tools", for `SettingsLayout`'s
|
|
27
|
+
* `sidebarFooter` under the section list on a desktop. `list`: the bare rows, for
|
|
28
|
+
* `SettingsLayout`'s `phoneFooter`, which puts them in a list of their own.
|
|
29
|
+
*/
|
|
30
|
+
variant?: "sidebar" | "list";
|
|
31
|
+
/** Your router's link. Default: the `<UiKitProvider linkComponent>`, then `<a>`. */
|
|
32
|
+
renderLink?: (props: ListItemLinkProps) => ReactElement;
|
|
33
|
+
/** Prop > `<UiKitProvider labels={{ adminArea }}>` > English. */
|
|
34
|
+
labels?: LabelOverride<AdminAreaLabels>;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The admin area's links to the admin tools that are pages of their own (0.42.0,
|
|
40
|
+
* docs/admin-harmonization.md §2.5 decision 16, §6.11): Translations, and the app's task
|
|
41
|
+
* pages (kastlan's Data import). The feedback inbox is not one of them: the top bar's
|
|
42
|
+
* feedback menu reaches it, and the overview's tiles link to it.
|
|
43
|
+
*
|
|
44
|
+
* Draw it twice from one list — at the foot of the section sidebar and in the phone
|
|
45
|
+
* footer:
|
|
46
|
+
*
|
|
47
|
+
* <SettingsLayout
|
|
48
|
+
* sidebarFooter={<AdminToolLinks links={TOOLS} />}
|
|
49
|
+
* phoneFooter={<AdminToolLinks links={TOOLS} variant="list" />}
|
|
50
|
+
* …
|
|
51
|
+
* />
|
|
52
|
+
*
|
|
53
|
+
* With no visible link it renders nothing.
|
|
54
|
+
*/
|
|
55
|
+
export function AdminToolLinks({ links, variant = "sidebar", renderLink, labels: labelsProp, className }: AdminToolLinksProps) {
|
|
56
|
+
const labels = useAdminAreaLabels(labelsProp);
|
|
57
|
+
const headingId = useId();
|
|
58
|
+
const shown = links.filter((l) => l.visible !== false);
|
|
59
|
+
if (shown.length === 0) return null;
|
|
60
|
+
const rows = shown.map((l) => (
|
|
61
|
+
<ListItem
|
|
62
|
+
key={l.key}
|
|
63
|
+
href={l.href}
|
|
64
|
+
renderLink={renderLink}
|
|
65
|
+
title={l.label}
|
|
66
|
+
leading={
|
|
67
|
+
l.icon === undefined ? undefined : (
|
|
68
|
+
<span aria-hidden className="flex shrink-0 text-muted [&_svg]:size-4">
|
|
69
|
+
{l.icon}
|
|
70
|
+
</span>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
/>
|
|
74
|
+
));
|
|
75
|
+
if (variant === "list") return <>{rows}</>;
|
|
76
|
+
return (
|
|
77
|
+
<nav data-slot="admin-tool-links" aria-labelledby={headingId} className={cn("space-y-1", className)}>
|
|
78
|
+
<div id={headingId} className="px-3 text-caption font-semibold uppercase tracking-wide text-muted">
|
|
79
|
+
{labels.tools}
|
|
80
|
+
</div>
|
|
81
|
+
<List density="compact">{rows}</List>
|
|
82
|
+
</nav>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
2
|
import { CreditCard, Hourglass, PencilOff } from "lucide-react";
|
|
3
3
|
|
|
4
|
+
import { DEFAULT_COMMON_LABELS, useKitLabels } from "../i18n/kit-labels";
|
|
4
5
|
import type { LabelOverride } from "../i18n/kit-labels";
|
|
5
6
|
import { AlertBanner } from "../components/alert-banner";
|
|
6
7
|
import type { AlertSize, AlertTone } from "../components/alert-banner";
|
|
@@ -8,6 +9,8 @@ import { Button } from "../components/button";
|
|
|
8
9
|
import { Spinner } from "../components/spinner";
|
|
9
10
|
import { useBillingLabels } from "./billing-labels";
|
|
10
11
|
import type { BillingLabels } from "./billing-labels";
|
|
12
|
+
import type { BillingPortalAccess } from "./billing-overview";
|
|
13
|
+
import { ExternalMark } from "./subscription-actions";
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* The billing banners (docs/billing-harmonization.md §3.3, §7, §12.6, §12.21):
|
|
@@ -16,7 +19,8 @@ import type { BillingLabels } from "./billing-labels";
|
|
|
16
19
|
* - `grant-ending` — from 7 days before `comped_until`: a beta user's 12 months, an
|
|
17
20
|
* operator's grant;
|
|
18
21
|
* - `payment-failed` — from the first failed payment (`past_due`), while the provider
|
|
19
|
-
* retries;
|
|
22
|
+
* retries; since 0.42, for an admin who isn't the buyer (`portal="buyer_only"`), it
|
|
23
|
+
* names who can update the payment method, with no button;
|
|
20
24
|
* - `plan-ended` — out of good standing: read-only, never locked (§2.3);
|
|
21
25
|
* - `guest` — a guest in someone else's read-only item (§12.6);
|
|
22
26
|
* - `processing` — back from checkout before the webhook landed (§12.21).
|
|
@@ -64,6 +68,14 @@ interface BillingBannerBaseProps extends Omit<ComponentPropsWithRef<"div">, "chi
|
|
|
64
68
|
actionLabel?: string;
|
|
65
69
|
/** The action is under way: the button's spinner, no second press. */
|
|
66
70
|
actionPending?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 0.43 (§17): the action opens the provider's portal in a NEW TAB (`openProviderPage`
|
|
73
|
+
* in {@link onAction}): the external-link mark, "(opens in a new tab)" for a reader,
|
|
74
|
+
* and `target="_blank"` on an {@link actionHref}. Default: true for `payment-failed`
|
|
75
|
+
* with `onAction` (the portal's card page), false otherwise — an `actionHref` is
|
|
76
|
+
* usually the app's own subscription page.
|
|
77
|
+
*/
|
|
78
|
+
actionNewTab?: boolean;
|
|
67
79
|
/** An × that calls this; the app removes the banner and remembers that it did. */
|
|
68
80
|
onDismiss?: () => void;
|
|
69
81
|
dismissLabel?: string;
|
|
@@ -78,6 +90,8 @@ export type BillingBannerProps = BillingBannerBaseProps &
|
|
|
78
90
|
/** Calendar days left — `billingDaysLeft(trial_ends_at)`. 0 is today. */
|
|
79
91
|
daysLeft: number;
|
|
80
92
|
item?: never;
|
|
93
|
+
portal?: never;
|
|
94
|
+
buyerName?: never;
|
|
81
95
|
}
|
|
82
96
|
| {
|
|
83
97
|
kind: "guest";
|
|
@@ -85,11 +99,31 @@ export type BillingBannerProps = BillingBannerBaseProps &
|
|
|
85
99
|
* the banner says "for now" and nothing more (§12.6). */
|
|
86
100
|
item?: string;
|
|
87
101
|
daysLeft?: never;
|
|
102
|
+
portal?: never;
|
|
103
|
+
buyerName?: never;
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
kind: "payment-failed";
|
|
107
|
+
/**
|
|
108
|
+
* 0.42 (§16.7 A, §16.8): `GET /billing/status`'s `portal` (`BillingStanding`).
|
|
109
|
+
* `"buyer_only"` — the viewer isn't the buyer, so the portal's page for the card
|
|
110
|
+
* would answer 403: the banner says who can update the payment method
|
|
111
|
+
* (`paymentFailedAskBuyer`) and shows NO button, whatever `actionHref` or
|
|
112
|
+
* `onAction` say. `"open"` (default): as before.
|
|
113
|
+
*/
|
|
114
|
+
portal?: BillingPortalAccess;
|
|
115
|
+
/** 0.42: the status's `buyer_name`, under `"buyer_only"`. Empty: "…the admin who
|
|
116
|
+
* bought the subscription". */
|
|
117
|
+
buyerName?: string | null;
|
|
118
|
+
daysLeft?: never;
|
|
119
|
+
item?: never;
|
|
88
120
|
}
|
|
89
121
|
| {
|
|
90
|
-
kind: "
|
|
122
|
+
kind: "plan-ended" | "processing";
|
|
91
123
|
daysLeft?: never;
|
|
92
124
|
item?: never;
|
|
125
|
+
portal?: never;
|
|
126
|
+
buyerName?: never;
|
|
93
127
|
}
|
|
94
128
|
);
|
|
95
129
|
|
|
@@ -128,6 +162,8 @@ export function BillingBanner(props: BillingBannerProps) {
|
|
|
128
162
|
kind,
|
|
129
163
|
daysLeft,
|
|
130
164
|
item,
|
|
165
|
+
portal,
|
|
166
|
+
buyerName,
|
|
131
167
|
tone,
|
|
132
168
|
variant = "strip",
|
|
133
169
|
size,
|
|
@@ -135,6 +171,7 @@ export function BillingBanner(props: BillingBannerProps) {
|
|
|
135
171
|
onAction,
|
|
136
172
|
actionLabel,
|
|
137
173
|
actionPending,
|
|
174
|
+
actionNewTab,
|
|
138
175
|
onDismiss,
|
|
139
176
|
dismissLabel,
|
|
140
177
|
labels: labelsProp,
|
|
@@ -142,11 +179,14 @@ export function BillingBanner(props: BillingBannerProps) {
|
|
|
142
179
|
...rest
|
|
143
180
|
} = props;
|
|
144
181
|
const labels = useBillingLabels(labelsProp);
|
|
182
|
+
const common = useKitLabels("common", DEFAULT_COMMON_LABELS);
|
|
145
183
|
const days = Math.max(0, Math.floor(daysLeft ?? 0));
|
|
146
184
|
|
|
147
185
|
let text: string;
|
|
148
186
|
let icon: ReactNode;
|
|
149
187
|
let ownAction: string | undefined;
|
|
188
|
+
// 0.42 (§16.7 A): only the buyer can reach the portal's card page.
|
|
189
|
+
const askBuyer = kind === "payment-failed" && portal === "buyer_only";
|
|
150
190
|
switch (kind) {
|
|
151
191
|
case "trial-ending":
|
|
152
192
|
text = labels.trialEnding(days);
|
|
@@ -159,7 +199,7 @@ export function BillingBanner(props: BillingBannerProps) {
|
|
|
159
199
|
ownAction = labels.choosePlan;
|
|
160
200
|
break;
|
|
161
201
|
case "payment-failed":
|
|
162
|
-
text = labels.paymentFailed;
|
|
202
|
+
text = askBuyer ? labels.paymentFailedAskBuyer(buyerName || undefined) : labels.paymentFailed;
|
|
163
203
|
icon = <CreditCard />;
|
|
164
204
|
ownAction = labels.updatePayment;
|
|
165
205
|
break;
|
|
@@ -181,14 +221,25 @@ export function BillingBanner(props: BillingBannerProps) {
|
|
|
181
221
|
}
|
|
182
222
|
|
|
183
223
|
const words = actionLabel ?? ownAction;
|
|
224
|
+
const newTab = actionNewTab ?? (kind === "payment-failed" && actionHref === undefined && onAction !== undefined);
|
|
184
225
|
const action =
|
|
185
|
-
words === undefined || (actionHref === undefined && onAction === undefined) ? undefined : actionHref !== undefined ? (
|
|
186
|
-
<Button href={actionHref} variant="secondary" size="sm">
|
|
226
|
+
askBuyer || words === undefined || (actionHref === undefined && onAction === undefined) ? undefined : actionHref !== undefined ? (
|
|
227
|
+
<Button href={actionHref} variant="secondary" size="sm" external={newTab || undefined}>
|
|
187
228
|
{words}
|
|
229
|
+
{newTab && <ExternalMark />}
|
|
188
230
|
</Button>
|
|
189
231
|
) : (
|
|
190
|
-
<Button
|
|
232
|
+
<Button
|
|
233
|
+
type="button"
|
|
234
|
+
variant="secondary"
|
|
235
|
+
size="sm"
|
|
236
|
+
onClick={onAction}
|
|
237
|
+
pending={actionPending}
|
|
238
|
+
className={newTab ? "relative" : undefined}
|
|
239
|
+
data-portal-action={newTab ? "payment_method" : undefined}
|
|
240
|
+
>
|
|
191
241
|
{words}
|
|
242
|
+
{newTab && <ExternalMark reader={common.opensInNewTab} />}
|
|
192
243
|
</Button>
|
|
193
244
|
);
|
|
194
245
|
|