@alepha/ui 0.25.0 → 0.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/src/components/account/__tests__/account-router.spec.ts +201 -0
- package/src/components/account/account-connections.tsx +103 -0
- package/src/components/account/account-delete-dialog.tsx +184 -0
- package/src/components/account/account-header.tsx +57 -0
- package/src/components/account/account-keys.tsx +221 -0
- package/src/components/account/account-layout.tsx +63 -0
- package/src/components/account/account-password-dialog.tsx +152 -0
- package/src/components/account/account-profile.tsx +229 -0
- package/src/components/account/account-router-options.tsx +74 -0
- package/src/components/account/account-router-page.tsx +69 -0
- package/src/components/account/account-router.tsx +214 -0
- package/src/components/account/account-security.tsx +150 -0
- package/src/components/account/account-sessions.tsx +140 -0
- package/src/components/admin/__tests__/admin-keys-token-dialog.browser.spec.tsx +62 -0
- package/src/components/admin/__tests__/admin-layout.browser.spec.tsx +82 -0
- package/src/components/admin/__tests__/admin-router-page.spec.ts +54 -0
- package/src/components/admin/__tests__/admin-router.spec.ts +208 -0
- package/src/components/admin/__tests__/admin-user-cell.browser.spec.tsx +99 -0
- package/src/components/admin/__tests__/admin-user-detail.spec.ts +29 -0
- package/src/components/admin/admin-analytics-query-panel.tsx +149 -0
- package/src/components/admin/admin-analytics-results.tsx +95 -0
- package/src/components/admin/admin-analytics.tsx +104 -0
- package/src/components/admin/admin-audits.tsx +12 -15
- package/src/components/admin/admin-files.tsx +10 -18
- package/src/components/admin/admin-jobs-executions-panel.tsx +2 -1
- package/src/components/admin/admin-jobs.tsx +3 -1
- package/src/components/admin/admin-keys-token-dialog.tsx +123 -0
- package/src/components/admin/admin-keys.tsx +54 -3
- package/src/components/admin/admin-layout.tsx +107 -0
- package/src/components/admin/admin-payments.tsx +4 -5
- package/src/components/admin/admin-router-options.tsx +130 -0
- package/src/components/admin/admin-router-page.tsx +74 -0
- package/src/components/admin/admin-router.tsx +379 -0
- package/src/components/admin/admin-sessions.tsx +2 -16
- package/src/components/admin/admin-user-cell.tsx +70 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +28 -0
- package/src/components/admin/admin-user-detail-profile-policy.spec.ts +146 -0
- package/src/components/admin/admin-user-detail-profile-policy.ts +147 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +1 -1
- package/src/components/admin/admin-user-detail.tsx +76 -32
- package/src/components/admin/admin-users-status-filter.tsx +2 -0
- package/src/components/admin/admin-workflows-execution-sheet.tsx +277 -0
- package/src/components/admin/admin-workflows-executions-panel.tsx +170 -0
- package/src/components/admin/admin-workflows-status-badge.tsx +40 -0
- package/src/components/admin/admin-workflows.tsx +207 -0
- package/src/components/alepha-table/alepha-table.tsx +73 -17
- package/src/components/app-actions/__tests__/app-actions.browser.spec.tsx +79 -0
- package/src/components/app-actions/app-actions.tsx +113 -0
- package/src/components/app-shell/app-shell.tsx +122 -0
- package/src/components/auth/auth-reset-password.tsx +81 -8
- package/src/components/button-user/button-user.tsx +58 -1
- package/src/components/control/control.tsx +14 -71
- package/src/components/control-password/control-password.tsx +87 -0
- package/src/components/control-select/__tests__/control-select-clear-label.browser.spec.tsx +101 -0
- package/src/components/control-select/__tests__/control-select-deselect.browser.spec.tsx +126 -0
- package/src/components/control-select/__tests__/control-select-searchable.browser.spec.tsx +142 -0
- package/src/components/control-select/control-select.tsx +133 -111
- package/src/components/control-upload/control-upload.tsx +27 -1
- package/src/components/markdown-view/markdown-view.tsx +6 -0
- package/src/components/nav-shell/nav-page.tsx +3 -3
- package/src/components/settings/__tests__/settings-nav.browser.spec.tsx +123 -0
- package/src/components/settings/__tests__/settings-section.browser.spec.tsx +130 -0
- package/src/components/settings/settings-danger-section.tsx +59 -0
- package/src/components/settings/settings-layout.tsx +56 -0
- package/src/components/settings/settings-nav.tsx +131 -0
- package/src/components/settings/settings-row.tsx +81 -0
- package/src/components/settings/settings-section.tsx +64 -0
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/avatar.tsx +2 -0
- package/src/components/ui/breadcrumb.tsx +1 -1
- package/src/components/ui/calendar.tsx +11 -6
- package/src/components/ui/card.tsx +5 -5
- package/src/components/ui/carousel.tsx +4 -4
- package/src/components/ui/chart.tsx +2 -0
- package/src/components/ui/collapsible.tsx +2 -0
- package/src/components/ui/combobox.tsx +3 -1
- package/src/components/ui/context-menu.tsx +3 -3
- package/src/components/ui/dialog.tsx +6 -1
- package/src/components/ui/direction.tsx +2 -0
- package/src/components/ui/drawer.tsx +134 -37
- package/src/components/ui/dropdown-menu.tsx +13 -3
- package/src/components/ui/empty.tsx +4 -1
- package/src/components/ui/input-otp.tsx +2 -0
- package/src/components/ui/menubar.tsx +2 -2
- package/src/components/ui/pagination.tsx +2 -2
- package/src/components/ui/popover.tsx +2 -0
- package/src/components/ui/radio-group.tsx +2 -0
- package/src/components/ui/scroll-area.tsx +2 -0
- package/src/components/ui/select.tsx +1 -1
- package/src/components/ui/separator.tsx +2 -0
- package/src/components/ui/sheet.tsx +4 -1
- package/src/components/ui/sidebar.tsx +1 -1
- package/src/components/ui/spinner.tsx +1 -0
- package/src/components/ui/switch.tsx +2 -0
- package/src/components/ui/tabs.tsx +2 -0
- package/src/components/ui/toggle-group.tsx +2 -0
- package/src/components/ui/tooltip.tsx +2 -0
- package/src/lib/__tests__/rehype-safe-img.spec.ts +121 -0
- package/src/lib/i18n-fr.ts +68 -0
- package/src/lib/rehype-safe-img.ts +150 -0
- package/src/lib/resize-image.ts +135 -0
- package/src/styles.css +126 -1
- /package/src/components/{admin/admin-user-detail-provider-labels.ts → auth/provider-labels.ts} +0 -0
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"tailwind"
|
|
11
11
|
],
|
|
12
12
|
"author": "Feunard",
|
|
13
|
-
"version": "0.25.
|
|
13
|
+
"version": "0.25.2",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=22.0.0"
|
|
@@ -57,11 +57,10 @@
|
|
|
57
57
|
"shadcn": "^4.16.1",
|
|
58
58
|
"sonner": "^2.0.7",
|
|
59
59
|
"tailwind-merge": "^3.6.0",
|
|
60
|
-
"tw-animate-css": "^1.4.0"
|
|
61
|
-
"vaul": "^1.1.2"
|
|
60
|
+
"tw-animate-css": "^1.4.0"
|
|
62
61
|
},
|
|
63
62
|
"peerDependencies": {
|
|
64
|
-
"alepha": "0.25.
|
|
63
|
+
"alepha": "0.25.2",
|
|
65
64
|
"react": "*",
|
|
66
65
|
"react-dom": "*",
|
|
67
66
|
"recharts": "^3",
|
|
@@ -77,7 +76,7 @@
|
|
|
77
76
|
"@testing-library/dom": "^10.4.1",
|
|
78
77
|
"@testing-library/react": "^16.3.2",
|
|
79
78
|
"@types/react": "^19.2.18",
|
|
80
|
-
"alepha": "0.25.
|
|
79
|
+
"alepha": "0.25.2",
|
|
81
80
|
"react": "^19.2.8",
|
|
82
81
|
"react-dom": "^19.2.8",
|
|
83
82
|
"typescript": "^7.0.2"
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Alepha, OPTIONS } from "alepha";
|
|
2
|
+
import {
|
|
3
|
+
$page,
|
|
4
|
+
AlephaReactRouter,
|
|
5
|
+
type PagePrimitive,
|
|
6
|
+
} from "alepha/react/router";
|
|
7
|
+
import { describe, expect, it } from "vitest";
|
|
8
|
+
import { AdminRouter } from "../../admin/admin-router.tsx";
|
|
9
|
+
import { AccountRouter } from "../account-router.tsx";
|
|
10
|
+
import { $pageAccount } from "../account-router-page.tsx";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reads the permissions a page's route gate actually enforces — see
|
|
14
|
+
* `admin-router.spec.ts` for why this reads the gate back rather than the
|
|
15
|
+
* `permission` option a page was built from.
|
|
16
|
+
*/
|
|
17
|
+
const permissionsOf = (page: PagePrimitive): string[] => {
|
|
18
|
+
const required: string[] = [];
|
|
19
|
+
for (const middleware of page.options.use ?? []) {
|
|
20
|
+
const metadata = middleware[OPTIONS];
|
|
21
|
+
if (metadata?.name !== "$secure") {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const permissions = (
|
|
25
|
+
metadata.options as
|
|
26
|
+
| { permissions?: Array<string | { name: string }> }
|
|
27
|
+
| undefined
|
|
28
|
+
)?.permissions;
|
|
29
|
+
for (const permission of permissions ?? []) {
|
|
30
|
+
required.push(
|
|
31
|
+
typeof permission === "string" ? permission : permission.name,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return required;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe("AccountRouter", () => {
|
|
39
|
+
const mount = async () => {
|
|
40
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
41
|
+
alepha.inject(AccountRouter);
|
|
42
|
+
await alepha.start();
|
|
43
|
+
return alepha
|
|
44
|
+
.primitives($page)
|
|
45
|
+
.map((page) => ({ path: page.options.path, name: page.name }));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
it("mounts the shell and its five pages", async () => {
|
|
49
|
+
const pages = await mount();
|
|
50
|
+
|
|
51
|
+
expect(pages).toEqual(
|
|
52
|
+
expect.arrayContaining([
|
|
53
|
+
{ path: "/account", name: "account" },
|
|
54
|
+
{ path: "/", name: "accountProfile" },
|
|
55
|
+
{ path: "/security", name: "accountSecurity" },
|
|
56
|
+
{ path: "/sessions", name: "accountSessions" },
|
|
57
|
+
{ path: "/keys", name: "accountKeys" },
|
|
58
|
+
{ path: "/connections", name: "accountConnections" },
|
|
59
|
+
]),
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("gates the shell on being signed in, and nothing more", async () => {
|
|
64
|
+
/*
|
|
65
|
+
An account area needs a session and no permission. Requiring one would
|
|
66
|
+
mean every realm has to remember to grant it, and the failure mode is a
|
|
67
|
+
page that renders empty for users nobody thought to configure.
|
|
68
|
+
*/
|
|
69
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
70
|
+
const router = alepha.inject(AccountRouter);
|
|
71
|
+
await alepha.start();
|
|
72
|
+
|
|
73
|
+
expect(permissionsOf(router.layout)).toEqual([]);
|
|
74
|
+
expect(router.layout.options.use?.length).toBe(1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("gates every page on an action rather than a permission", async () => {
|
|
78
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
79
|
+
const router = alepha.inject(AccountRouter);
|
|
80
|
+
await alepha.start();
|
|
81
|
+
|
|
82
|
+
// An empty registry: no action exists for any page to be granted.
|
|
83
|
+
alepha.store.set("alepha.server.request.apiLinks", { actions: {} });
|
|
84
|
+
|
|
85
|
+
const pages = [
|
|
86
|
+
router.profile,
|
|
87
|
+
router.security,
|
|
88
|
+
router.sessions,
|
|
89
|
+
router.keys,
|
|
90
|
+
router.connections,
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
for (const page of pages) {
|
|
94
|
+
expect(page.options.can).toBeDefined();
|
|
95
|
+
// `has` grants every permission-shaped name. A `can` derived from a
|
|
96
|
+
// permission would answer true here; these must not, because the whole
|
|
97
|
+
// point is "is this module mounted", which a permission cannot answer.
|
|
98
|
+
expect(page.options.can!({ has: (name) => name.includes(":") })).toBe(
|
|
99
|
+
false,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("hides only the pages whose backing action is absent", async () => {
|
|
105
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
106
|
+
const router = alepha.inject(AccountRouter);
|
|
107
|
+
await alepha.start();
|
|
108
|
+
|
|
109
|
+
// The keys module is the realistic absentee: an application can mount
|
|
110
|
+
// users without ever mounting AlephaApiKeys, and then the page must go.
|
|
111
|
+
// (Connections is no longer such a case — `MyConnectionController` lives
|
|
112
|
+
// in `api/users` to avoid a module cycle, so it ships with the rest.)
|
|
113
|
+
alepha.store.set("alepha.server.request.apiLinks", {
|
|
114
|
+
actions: {
|
|
115
|
+
getMyProfile: { path: "/users/me" },
|
|
116
|
+
listMyIdentities: { path: "/users/me/identities" },
|
|
117
|
+
listMySessions: { path: "/users/me/sessions" },
|
|
118
|
+
listMyConnections: { path: "/users/me/connections" },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(router.profile.options.can!({ has: () => true })).toBe(true);
|
|
123
|
+
expect(router.security.options.can!({ has: () => true })).toBe(true);
|
|
124
|
+
expect(router.sessions.options.can!({ has: () => true })).toBe(true);
|
|
125
|
+
expect(router.connections.options.can!({ has: () => true })).toBe(true);
|
|
126
|
+
expect(router.keys.options.can!({ has: () => true })).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("does not collide with the admin router's route names", async () => {
|
|
130
|
+
/*
|
|
131
|
+
The reason every name here is prefixed. `AdminRouter` claims `sessions`
|
|
132
|
+
and `keys` globally, and `ReactPageProvider.page()` returns the FIRST
|
|
133
|
+
match on a duplicate — so bare names would shadow one side or the other
|
|
134
|
+
depending on mount order, silently.
|
|
135
|
+
*/
|
|
136
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
137
|
+
alepha.inject(AdminRouter);
|
|
138
|
+
alepha.inject(AccountRouter);
|
|
139
|
+
await alepha.start();
|
|
140
|
+
|
|
141
|
+
const names = alepha.primitives($page).map((page) => page.name);
|
|
142
|
+
const duplicates = names.filter(
|
|
143
|
+
(name, index) => names.indexOf(name) !== index,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(duplicates).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("puts the profile at the shell root so bare /account resolves", async () => {
|
|
150
|
+
// Why there is no `indexPath` option, unlike admin.
|
|
151
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
152
|
+
const router = alepha.inject(AccountRouter);
|
|
153
|
+
await alepha.start();
|
|
154
|
+
|
|
155
|
+
expect(router.profile.options.path).toBe("/");
|
|
156
|
+
expect(router.profile.options.parent).toBe(router.layout);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("lets an application hang its own page off the shell", async () => {
|
|
160
|
+
class LoreAccountRouter {
|
|
161
|
+
invitations = $pageAccount({
|
|
162
|
+
path: "/invitations",
|
|
163
|
+
name: "accountInvitations",
|
|
164
|
+
nav: { label: "Invitations", group: "Lore", order: 100 },
|
|
165
|
+
component: () => "invitations",
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
170
|
+
alepha.with(LoreAccountRouter);
|
|
171
|
+
await alepha.start();
|
|
172
|
+
|
|
173
|
+
const page = alepha
|
|
174
|
+
.primitives($page)
|
|
175
|
+
.find((it) => it.name === "accountInvitations");
|
|
176
|
+
|
|
177
|
+
expect(page).toBeDefined();
|
|
178
|
+
expect(page!.options.parent).toBe(alepha.inject(AccountRouter).layout);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("registers the whole shell from a single $pageAccount call", async () => {
|
|
182
|
+
// Declaring one page this way must mount the built-ins too — an account
|
|
183
|
+
// page without the account area around it is not a thing.
|
|
184
|
+
class LoreAccountRouter {
|
|
185
|
+
invitations = $pageAccount({
|
|
186
|
+
path: "/invitations",
|
|
187
|
+
name: "accountInvitations",
|
|
188
|
+
component: () => "invitations",
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const alepha = Alepha.create().with(AlephaReactRouter);
|
|
193
|
+
alepha.with(LoreAccountRouter);
|
|
194
|
+
await alepha.start();
|
|
195
|
+
|
|
196
|
+
const names = alepha.primitives($page).map((page) => page.name);
|
|
197
|
+
expect(names).toEqual(
|
|
198
|
+
expect.arrayContaining(["account", "accountProfile", "accountSessions"]),
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SettingsRow } from "@alepha/ui/components/settings/settings-row";
|
|
2
|
+
import { SettingsSection } from "@alepha/ui/components/settings/settings-section";
|
|
3
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
4
|
+
import { useDialog } from "@alepha/ui/components/use-dialog/use-dialog";
|
|
5
|
+
import { useToast } from "@alepha/ui/components/use-toast/use-toast";
|
|
6
|
+
import type { MyConnection, MyConnectionController } from "alepha/api/users";
|
|
7
|
+
import { DateTimeProvider } from "alepha/datetime";
|
|
8
|
+
import { useClient, useInject } from "alepha/react";
|
|
9
|
+
import { Plug } from "lucide-react";
|
|
10
|
+
import { useState } from "react";
|
|
11
|
+
|
|
12
|
+
export interface AccountConnectionsProps {
|
|
13
|
+
connections?: MyConnection[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Applications holding access to this account through OAuth — an MCP client,
|
|
18
|
+
* a CLI, a third-party integration.
|
|
19
|
+
*
|
|
20
|
+
* Confirmed on revoke, unlike a plain session. A session comes back by
|
|
21
|
+
* signing in again; a connection comes back only by re-running whatever
|
|
22
|
+
* authorization flow created it, which for an MCP client means the person has
|
|
23
|
+
* to go and reconnect it from the other side.
|
|
24
|
+
*/
|
|
25
|
+
const AccountConnections = (props: AccountConnectionsProps) => {
|
|
26
|
+
const api = useClient<MyConnectionController>();
|
|
27
|
+
const dt = useInject(DateTimeProvider);
|
|
28
|
+
const dialog = useDialog();
|
|
29
|
+
const toaster = useToast();
|
|
30
|
+
|
|
31
|
+
const [connections, setConnections] = useState<MyConnection[]>(
|
|
32
|
+
props.connections ?? [],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const revoke = async (connection: MyConnection) => {
|
|
36
|
+
const ok = await dialog.confirm({
|
|
37
|
+
title: `Disconnect ${connection.clientName}?`,
|
|
38
|
+
description:
|
|
39
|
+
"It loses access immediately and has to be authorized again to come back.",
|
|
40
|
+
confirmLabel: "Disconnect",
|
|
41
|
+
destructive: true,
|
|
42
|
+
});
|
|
43
|
+
if (!ok) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await api.revokeMyConnection({ params: { id: connection.id } });
|
|
48
|
+
setConnections((prev) => prev.filter((it) => it.id !== connection.id));
|
|
49
|
+
} catch (error: any) {
|
|
50
|
+
toaster.show(error?.message ?? "Could not disconnect it", "danger");
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (connections.length === 0) {
|
|
55
|
+
return (
|
|
56
|
+
<SettingsSection title="Connected apps">
|
|
57
|
+
<SettingsRow
|
|
58
|
+
label={
|
|
59
|
+
<span className="flex items-center gap-2 text-muted-foreground">
|
|
60
|
+
<Plug className="size-4" />
|
|
61
|
+
Nothing is connected
|
|
62
|
+
</span>
|
|
63
|
+
}
|
|
64
|
+
description="Applications you authorize will appear here."
|
|
65
|
+
/>
|
|
66
|
+
</SettingsSection>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<SettingsSection
|
|
72
|
+
title="Connected apps"
|
|
73
|
+
description="Applications that can act on your behalf."
|
|
74
|
+
>
|
|
75
|
+
{connections.map((connection) => (
|
|
76
|
+
<SettingsRow
|
|
77
|
+
key={connection.id}
|
|
78
|
+
label={
|
|
79
|
+
<span className="flex items-center gap-2">
|
|
80
|
+
{connection.clientName}
|
|
81
|
+
{connection.current ? (
|
|
82
|
+
<span className="text-muted-foreground text-xs">
|
|
83
|
+
(this one)
|
|
84
|
+
</span>
|
|
85
|
+
) : null}
|
|
86
|
+
</span>
|
|
87
|
+
}
|
|
88
|
+
description={`Connected ${dt.of(connection.createdAt).fromNow()}${
|
|
89
|
+
connection.lastUsedAt
|
|
90
|
+
? ` · last used ${dt.of(connection.lastUsedAt).fromNow()}`
|
|
91
|
+
: " · never used"
|
|
92
|
+
}`}
|
|
93
|
+
>
|
|
94
|
+
<Button variant="ghost" size="sm" onClick={() => revoke(connection)}>
|
|
95
|
+
Disconnect
|
|
96
|
+
</Button>
|
|
97
|
+
</SettingsRow>
|
|
98
|
+
))}
|
|
99
|
+
</SettingsSection>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export default AccountConnections;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ControlPassword } from "@alepha/ui/components/control-password/control-password";
|
|
2
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
3
|
+
import {
|
|
4
|
+
Dialog,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogHeader,
|
|
7
|
+
DialogTitle,
|
|
8
|
+
} from "@alepha/ui/components/ui/dialog";
|
|
9
|
+
import { Input } from "@alepha/ui/components/ui/input";
|
|
10
|
+
import { Label } from "@alepha/ui/components/ui/label";
|
|
11
|
+
import { useToast } from "@alepha/ui/components/use-toast/use-toast";
|
|
12
|
+
import type {
|
|
13
|
+
MyAccountController,
|
|
14
|
+
MyProfileController,
|
|
15
|
+
} from "alepha/api/users";
|
|
16
|
+
import { useClient } from "alepha/react";
|
|
17
|
+
import { type FormEvent, type ReactNode, useEffect, useState } from "react";
|
|
18
|
+
|
|
19
|
+
export interface AccountDeleteDialogProps {
|
|
20
|
+
open: boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Whether the account has a `credentials` identity. An OAuth-only account
|
|
24
|
+
* has no password to prove knowledge of, so the field is not shown — and
|
|
25
|
+
* the server agrees, accepting the confirmation phrase alone.
|
|
26
|
+
*/
|
|
27
|
+
hasPassword: boolean;
|
|
28
|
+
|
|
29
|
+
onOpenChange: (open: boolean) => void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Application-supplied consequences, rendered above the confirmation field.
|
|
33
|
+
*
|
|
34
|
+
* The framework can say what deleting an *account* does; it cannot say what
|
|
35
|
+
* that costs inside your data. An application whose foreign keys cascade —
|
|
36
|
+
* rows the account authored inside other people's projects, say — puts the
|
|
37
|
+
* count here so the person reads it *before* confirming rather than
|
|
38
|
+
* discovering it afterwards.
|
|
39
|
+
*
|
|
40
|
+
* A `ReactNode` rather than a string because the honest version of this is
|
|
41
|
+
* usually a live count, which means a component that fetches one.
|
|
42
|
+
*/
|
|
43
|
+
warning?: ReactNode;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Called once the account is gone. The caller signs the (now orphaned)
|
|
47
|
+
* session out.
|
|
48
|
+
*/
|
|
49
|
+
onDeleted: () => void | Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Permanently delete your own account.
|
|
54
|
+
*
|
|
55
|
+
* Asks for two independent things because the two failure modes are different
|
|
56
|
+
* people: the password proves it is *you* (against someone at your unlocked
|
|
57
|
+
* laptop), and typing the confirmation phrase proves you *meant it* (against
|
|
58
|
+
* you, five seconds from now).
|
|
59
|
+
*
|
|
60
|
+
* The phrase is fetched rather than guessed. The server accepts the account's
|
|
61
|
+
* email, falling back to username and then the literal `DELETE`, and this
|
|
62
|
+
* dialog must ask for exactly what the server will accept — a hardcoded
|
|
63
|
+
* "type DELETE" would be refused for every account that has an email.
|
|
64
|
+
*/
|
|
65
|
+
export const AccountDeleteDialog = (props: AccountDeleteDialogProps) => {
|
|
66
|
+
const accountApi = useClient<MyAccountController>();
|
|
67
|
+
const profileApi = useClient<MyProfileController>();
|
|
68
|
+
const toaster = useToast();
|
|
69
|
+
|
|
70
|
+
const [expected, setExpected] = useState<string | undefined>();
|
|
71
|
+
const [confirm, setConfirm] = useState("");
|
|
72
|
+
const [currentPassword, setCurrentPassword] = useState("");
|
|
73
|
+
const [submitting, setSubmitting] = useState(false);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (!props.open) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
let cancelled = false;
|
|
80
|
+
profileApi
|
|
81
|
+
.getMyProfile()
|
|
82
|
+
.then((profile) => {
|
|
83
|
+
if (!cancelled) {
|
|
84
|
+
setExpected(profile.email ?? profile.username ?? "DELETE");
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
.catch(() => {
|
|
88
|
+
if (!cancelled) {
|
|
89
|
+
setExpected("DELETE");
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return () => {
|
|
93
|
+
cancelled = true;
|
|
94
|
+
};
|
|
95
|
+
}, [props.open, profileApi]);
|
|
96
|
+
|
|
97
|
+
const close = () => {
|
|
98
|
+
setConfirm("");
|
|
99
|
+
setCurrentPassword("");
|
|
100
|
+
props.onOpenChange(false);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const submit = async (event: FormEvent) => {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
setSubmitting(true);
|
|
106
|
+
try {
|
|
107
|
+
await accountApi.deleteMyAccount({
|
|
108
|
+
body: {
|
|
109
|
+
confirm,
|
|
110
|
+
currentPassword: props.hasPassword ? currentPassword : undefined,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
await props.onDeleted();
|
|
114
|
+
} catch (error: any) {
|
|
115
|
+
/*
|
|
116
|
+
An application's `user:delete:before` hook refuses here — "You still
|
|
117
|
+
own 3 projects" — and the framework's fast-path emit delivers that
|
|
118
|
+
message unwrapped. Showing it verbatim is the entire reason the emit
|
|
119
|
+
avoids `{ log: true }`; a generic "could not delete" would waste it.
|
|
120
|
+
*/
|
|
121
|
+
toaster.show(error?.message ?? "Could not delete your account", "danger");
|
|
122
|
+
} finally {
|
|
123
|
+
setSubmitting(false);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const ready = expected !== undefined && confirm === expected;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<Dialog open={props.open} onOpenChange={(next) => !next && close()}>
|
|
131
|
+
<DialogContent>
|
|
132
|
+
<DialogHeader>
|
|
133
|
+
<DialogTitle>Delete your account</DialogTitle>
|
|
134
|
+
</DialogHeader>
|
|
135
|
+
<form onSubmit={submit} className="flex flex-col gap-4">
|
|
136
|
+
<span className="text-muted-foreground text-sm">
|
|
137
|
+
This permanently removes your account, its sign-in methods and every
|
|
138
|
+
session. It cannot be undone.
|
|
139
|
+
</span>
|
|
140
|
+
|
|
141
|
+
{props.warning}
|
|
142
|
+
|
|
143
|
+
{props.hasPassword ? (
|
|
144
|
+
<ControlPassword
|
|
145
|
+
id="deleteCurrentPassword"
|
|
146
|
+
label="Current password"
|
|
147
|
+
value={currentPassword}
|
|
148
|
+
onChange={setCurrentPassword}
|
|
149
|
+
autoComplete="current-password"
|
|
150
|
+
required
|
|
151
|
+
/>
|
|
152
|
+
) : null}
|
|
153
|
+
|
|
154
|
+
<div className="flex flex-col gap-1.5">
|
|
155
|
+
<Label htmlFor="deleteConfirm">
|
|
156
|
+
Type <span className="font-mono">{expected ?? "…"}</span> to
|
|
157
|
+
confirm
|
|
158
|
+
</Label>
|
|
159
|
+
<Input
|
|
160
|
+
id="deleteConfirm"
|
|
161
|
+
value={confirm}
|
|
162
|
+
onChange={(event) => setConfirm(event.target.value)}
|
|
163
|
+
autoComplete="off"
|
|
164
|
+
required
|
|
165
|
+
/>
|
|
166
|
+
</div>
|
|
167
|
+
|
|
168
|
+
<div className="flex justify-end gap-2">
|
|
169
|
+
<Button type="button" variant="ghost" onClick={close}>
|
|
170
|
+
Cancel
|
|
171
|
+
</Button>
|
|
172
|
+
<Button
|
|
173
|
+
type="submit"
|
|
174
|
+
variant="destructive"
|
|
175
|
+
disabled={submitting || !ready}
|
|
176
|
+
>
|
|
177
|
+
Delete account
|
|
178
|
+
</Button>
|
|
179
|
+
</div>
|
|
180
|
+
</form>
|
|
181
|
+
</DialogContent>
|
|
182
|
+
</Dialog>
|
|
183
|
+
);
|
|
184
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AppActions } from "@alepha/ui/components/app-actions/app-actions";
|
|
2
|
+
import { Button } from "@alepha/ui/components/ui/button";
|
|
3
|
+
import { Link, useRouter } from "alepha/react/router";
|
|
4
|
+
import { ArrowLeft } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
export interface AccountHeaderProps {
|
|
7
|
+
/**
|
|
8
|
+
* Route name the back link points at.
|
|
9
|
+
*
|
|
10
|
+
* @default "home"
|
|
11
|
+
*/
|
|
12
|
+
homeRouteName?: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Label for the back link.
|
|
16
|
+
*
|
|
17
|
+
* @default "Back to site"
|
|
18
|
+
*/
|
|
19
|
+
backLabel?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The account area's top bar: a way out on the left, the ambient controls on
|
|
24
|
+
* the right.
|
|
25
|
+
*
|
|
26
|
+
* The way out is the point. `/account` is a destination you arrive at from
|
|
27
|
+
* somewhere else and leave again, and unlike `/admin` it has no sidebar to
|
|
28
|
+
* carry a brand or a home affordance — without this the only exit is the
|
|
29
|
+
* browser's back button.
|
|
30
|
+
*
|
|
31
|
+
* It is a real `<Link href>`, not a button that calls `router.push`, so the
|
|
32
|
+
* middle-click / open-in-new-tab / copy-link behaviours all work and the
|
|
33
|
+
* destination is visible in the status bar on hover.
|
|
34
|
+
*
|
|
35
|
+
* Replaceable wholesale: `AccountRouterOptions.header` overrides this, for an
|
|
36
|
+
* application whose account area sits inside its own chrome and needs no
|
|
37
|
+
* second header.
|
|
38
|
+
*/
|
|
39
|
+
export const AccountHeader = (props: AccountHeaderProps) => {
|
|
40
|
+
const router = useRouter<any>();
|
|
41
|
+
const home = props.homeRouteName ?? "home";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="flex items-center justify-between gap-4 border-b pb-3">
|
|
45
|
+
<Button
|
|
46
|
+
variant="ghost"
|
|
47
|
+
size="sm"
|
|
48
|
+
className="-ml-2 text-muted-foreground hover:text-foreground"
|
|
49
|
+
render={<Link href={router.path(home)} />}
|
|
50
|
+
>
|
|
51
|
+
<ArrowLeft className="size-4" />
|
|
52
|
+
{props.backLabel ?? "Back to site"}
|
|
53
|
+
</Button>
|
|
54
|
+
<AppActions />
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|