@alepha/ui 0.31.0 → 0.33.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 +1 -1
- package/dist/account/AccountConnections.js +1 -1
- package/dist/account/AccountConnections.js.map +1 -1
- package/dist/account/AccountDeleteDialog.d.ts.map +1 -1
- package/dist/account/AccountDeleteDialog.js +17 -17
- package/dist/account/AccountDeleteDialog.js.map +1 -1
- package/dist/account/AccountKeys.js +2 -2
- package/dist/account/AccountKeys.js.map +1 -1
- package/dist/account/AccountMfaDialog.d.ts.map +1 -1
- package/dist/account/AccountMfaDialog.js +19 -25
- package/dist/account/AccountMfaDialog.js.map +1 -1
- package/dist/account/AccountPasswordDialog.d.ts.map +1 -1
- package/dist/account/AccountPasswordDialog.js +25 -24
- package/dist/account/AccountPasswordDialog.js.map +1 -1
- package/dist/account/AccountProfile.d.ts.map +1 -1
- package/dist/account/AccountProfile.js +17 -24
- package/dist/account/AccountProfile.js.map +1 -1
- package/dist/account/AccountSecurity.d.ts.map +1 -1
- package/dist/account/AccountSecurity.js +21 -19
- package/dist/account/AccountSecurity.js.map +1 -1
- package/dist/account/AccountSessions.js +1 -1
- package/dist/account/AccountSessions.js.map +1 -1
- package/dist/account/ApiKeyCreateDialog.d.ts.map +1 -1
- package/dist/account/ApiKeyCreateDialog.js +8 -12
- package/dist/account/ApiKeyCreateDialog.js.map +1 -1
- package/dist/admin/AdminFiles.js +1 -1
- package/dist/admin/AdminFiles.js.map +1 -1
- package/dist/admin/AdminJobs.js +1 -1
- package/dist/admin/AdminJobs.js.map +1 -1
- package/dist/admin/AdminKeys.js +1 -1
- package/dist/admin/AdminKeys.js.map +1 -1
- package/dist/admin/AdminParameters.d.ts.map +1 -1
- package/dist/admin/AdminParameters.js +7 -5
- package/dist/admin/AdminParameters.js.map +1 -1
- package/dist/admin/AdminParametersTreeFooterActions.d.ts +2 -2
- package/dist/admin/AdminParametersTreeFooterActions.d.ts.map +1 -1
- package/dist/admin/AdminParametersTreeFooterActions.js.map +1 -1
- package/dist/admin/AdminParametersTreePane.d.ts +2 -2
- package/dist/admin/AdminParametersTreePane.d.ts.map +1 -1
- package/dist/admin/AdminParametersTreePane.js.map +1 -1
- package/dist/admin/AdminRouter.d.ts +1 -3
- package/dist/admin/AdminRouter.d.ts.map +1 -1
- package/dist/admin/AdminRouter.js +2 -4
- package/dist/admin/AdminRouter.js.map +1 -1
- package/dist/admin/AdminSessions.js +1 -1
- package/dist/admin/AdminSessions.js.map +1 -1
- package/dist/admin/AdminUserAvatarControl.d.ts.map +1 -1
- package/dist/admin/AdminUserAvatarControl.js +9 -16
- package/dist/admin/AdminUserAvatarControl.js.map +1 -1
- package/dist/admin/AdminUserDetail.js +4 -4
- package/dist/admin/AdminUserDetail.js.map +1 -1
- package/dist/admin/AdminUsers.d.ts.map +1 -1
- package/dist/admin/AdminUsers.js +10 -12
- package/dist/admin/AdminUsers.js.map +1 -1
- package/dist/admin/AdminUsersRolesPicker.d.ts +5 -1
- package/dist/admin/AdminUsersRolesPicker.d.ts.map +1 -1
- package/dist/admin/AdminUsersRolesPicker.js +2 -3
- package/dist/admin/AdminUsersRolesPicker.js.map +1 -1
- package/dist/admin/analytics/QueryPanel.js +1 -1
- package/dist/admin/analytics/QueryPanel.js.map +1 -1
- package/dist/admin/useConfirmedAction.d.ts +8 -2
- package/dist/admin/useConfirmedAction.d.ts.map +1 -1
- package/dist/admin/useConfirmedAction.js +15 -4
- package/dist/admin/useConfirmedAction.js.map +1 -1
- package/dist/auth/AuthLogin.d.ts.map +1 -1
- package/dist/auth/AuthLogin.js +4 -4
- package/dist/auth/AuthLogin.js.map +1 -1
- package/dist/auth/AuthRegister.js.map +1 -1
- package/dist/form/AutoForm.js +1 -1
- package/dist/form/AutoForm.js.map +1 -1
- package/dist/form/Control.d.ts.map +1 -1
- package/dist/form/Control.js +11 -1
- package/dist/form/Control.js.map +1 -1
- package/dist/form/ControlArray.js +5 -5
- package/dist/form/ControlArray.js.map +1 -1
- package/dist/form/ControlSelect.js +2 -2
- package/dist/form/ControlSelect.js.map +1 -1
- package/dist/form/ControlUpload.d.ts +1 -1
- package/dist/form/ControlUpload.js.map +1 -1
- package/dist/i18n/fr/uiFr.d.ts.map +1 -1
- package/dist/i18n/fr/uiFr.js +0 -9
- package/dist/i18n/fr/uiFr.js.map +1 -1
- package/dist/organizations/MyOrganizationInvitations.js +2 -2
- package/dist/organizations/MyOrganizationInvitations.js.map +1 -1
- package/dist/organizations/OrganizationInviteDialog.js +1 -1
- package/dist/organizations/OrganizationInviteDialog.js.map +1 -1
- package/dist/organizations/OrganizationMembers.js +1 -1
- package/dist/organizations/OrganizationMembers.js.map +1 -1
- package/dist/organizations/OrganizationPendingInvitations.js +1 -1
- package/dist/organizations/OrganizationPendingInvitations.js.map +1 -1
- package/dist/organizations/OrganizationRanks.js +3 -3
- package/dist/organizations/OrganizationRanks.js.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts +6 -1
- package/dist/organizations/useInviteOrganizationMember.d.ts.map +1 -1
- package/dist/organizations/useInviteOrganizationMember.js +13 -13
- package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
- package/dist/organizations/useRevokeOrganizationInvitation.d.ts +7 -1
- package/dist/organizations/useRevokeOrganizationInvitation.d.ts.map +1 -1
- package/dist/organizations/useRevokeOrganizationInvitation.js +13 -2
- package/dist/organizations/useRevokeOrganizationInvitation.js.map +1 -1
- package/dist/shell/ButtonUser.d.ts +1 -2
- package/dist/shell/ButtonUser.d.ts.map +1 -1
- package/dist/shell/ButtonUser.js +14 -42
- package/dist/shell/ButtonUser.js.map +1 -1
- package/dist/shell/ButtonUserContent.d.ts +13 -0
- package/dist/shell/ButtonUserContent.d.ts.map +1 -0
- package/dist/shell/ButtonUserContent.js +52 -0
- package/dist/shell/ButtonUserContent.js.map +1 -0
- package/dist/shell/ButtonUserPlaceholder.d.ts +14 -0
- package/dist/shell/ButtonUserPlaceholder.d.ts.map +1 -0
- package/dist/shell/ButtonUserPlaceholder.js +17 -0
- package/dist/shell/ButtonUserPlaceholder.js.map +1 -0
- package/dist/styles.css +94 -0
- package/dist/table/DataTable.js +1 -1
- package/dist/table/DataTable.js.map +1 -1
- package/dist/table/DataTableFilterBar.js +2 -2
- package/dist/table/DataTableFilterBar.js.map +1 -1
- package/dist/table/dataTableBaseProps.d.ts +1 -1
- package/dist/table/dataTableTypes.d.ts +3 -3
- package/dist/table/dataTableTypes.d.ts.map +1 -1
- package/dist/table/useDataTableData.d.ts.map +1 -1
- package/dist/table/useDataTableData.js +3 -1
- package/dist/table/useDataTableData.js.map +1 -1
- package/dist/table/useDataTableRefresh.js +2 -2
- package/dist/table/useDataTableRefresh.js.map +1 -1
- package/dist/table/useDataTableSummary.d.ts.map +1 -1
- package/dist/table/useDataTableSummary.js +2 -1
- package/dist/table/useDataTableSummary.js.map +1 -1
- package/package.json +9 -9
- package/src/account/AccountConnections.tsx +1 -1
- package/src/account/AccountDeleteDialog.tsx +25 -31
- package/src/account/AccountKeys.tsx +2 -2
- package/src/account/AccountMfaDialog.tsx +33 -27
- package/src/account/AccountPasswordDialog.tsx +36 -39
- package/src/account/AccountProfile.tsx +29 -43
- package/src/account/AccountSecurity.tsx +57 -64
- package/src/account/AccountSessions.tsx +1 -1
- package/src/account/ApiKeyCreateDialog.tsx +12 -20
- package/src/account/__tests__/AccountRouter.spec.ts +2 -1
- package/src/admin/AdminFiles.tsx +1 -1
- package/src/admin/AdminJobs.tsx +1 -1
- package/src/admin/AdminKeys.tsx +1 -1
- package/src/admin/AdminParameters.tsx +7 -5
- package/src/admin/AdminParametersTreeFooterActions.tsx +2 -2
- package/src/admin/AdminParametersTreePane.tsx +2 -2
- package/src/admin/AdminRouter.tsx +2 -4
- package/src/admin/AdminSessions.tsx +1 -1
- package/src/admin/AdminUserAvatarControl.tsx +17 -22
- package/src/admin/AdminUserDetail.tsx +4 -4
- package/src/admin/AdminUsers.tsx +10 -12
- package/src/admin/AdminUsersRolesPicker.tsx +11 -4
- package/src/admin/__tests__/AdminRouter.spec.ts +3 -2
- package/src/admin/analytics/QueryPanel.tsx +1 -1
- package/src/admin/useConfirmedAction.tsx +24 -10
- package/src/auth/AuthLogin.tsx +10 -9
- package/src/auth/AuthRegister.tsx +2 -2
- package/src/form/AutoForm.tsx +1 -1
- package/src/form/Control.tsx +14 -1
- package/src/form/ControlArray.tsx +5 -5
- package/src/form/ControlSelect.tsx +2 -2
- package/src/form/ControlUpload.tsx +1 -1
- package/src/form/__tests__/ControlArrayChildChange.browser.spec.tsx +1 -1
- package/src/form/__tests__/ControlVerbatim.browser.spec.tsx +71 -0
- package/src/i18n/fr/uiFr.ts +0 -9
- package/src/organizations/MyOrganizationInvitations.tsx +2 -2
- package/src/organizations/OrganizationInviteDialog.tsx +1 -1
- package/src/organizations/OrganizationMembers.tsx +1 -1
- package/src/organizations/OrganizationPendingInvitations.tsx +1 -1
- package/src/organizations/OrganizationRanks.tsx +3 -3
- package/src/organizations/useInviteOrganizationMember.ts +22 -15
- package/src/organizations/useRevokeOrganizationInvitation.ts +23 -4
- package/src/shell/ButtonUser.tsx +14 -79
- package/src/shell/ButtonUserContent.tsx +92 -0
- package/src/shell/ButtonUserPlaceholder.tsx +25 -0
- package/src/shell/__tests__/ActionErrorToaster.browser.spec.tsx +1 -1
- package/src/shell/__tests__/ActionErrorToasterHandled.browser.spec.tsx +1 -2
- package/src/shell/__tests__/AppShell.pageCache.spec.tsx +67 -0
- package/src/styles.css +94 -0
- package/src/table/DataTable.tsx +1 -1
- package/src/table/DataTableFilterBar.tsx +2 -2
- package/src/table/__tests__/DataTableFilterDateRange.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableQuerySeed.browser.spec.tsx +1 -1
- package/src/table/__tests__/DataTableShareFilters.browser.spec.tsx +1 -1
- package/src/table/dataTableBaseProps.ts +1 -1
- package/src/table/dataTableTypes.ts +3 -3
- package/src/table/useDataTableData.ts +2 -0
- package/src/table/useDataTableRefresh.ts +3 -3
- package/src/table/useDataTableSummary.ts +2 -1
|
@@ -2,7 +2,7 @@ import type {
|
|
|
2
2
|
MyIdentityController,
|
|
3
3
|
MyPasswordController,
|
|
4
4
|
} from "alepha/api/users";
|
|
5
|
-
import { useClient } from "alepha/react";
|
|
5
|
+
import { useAction, useClient } from "alepha/react";
|
|
6
6
|
import { useI18n } from "alepha/react/i18n";
|
|
7
7
|
import { type FormEvent, useState } from "react";
|
|
8
8
|
|
|
@@ -59,7 +59,6 @@ export const AccountPasswordDialog = (props: AccountPasswordDialogProps) => {
|
|
|
59
59
|
const [currentPassword, setCurrentPassword] = useState("");
|
|
60
60
|
const [password, setPassword] = useState("");
|
|
61
61
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
62
|
-
const [submitting, setSubmitting] = useState(false);
|
|
63
62
|
|
|
64
63
|
const close = () => {
|
|
65
64
|
setCurrentPassword("");
|
|
@@ -68,6 +67,40 @@ export const AccountPasswordDialog = (props: AccountPasswordDialogProps) => {
|
|
|
68
67
|
props.onOpenChange(false);
|
|
69
68
|
};
|
|
70
69
|
|
|
70
|
+
// The realm's password policy and the wrong-current-password refusal both
|
|
71
|
+
// arrive as errors whose message is worth showing verbatim: the app's
|
|
72
|
+
// ActionErrorToaster shows it.
|
|
73
|
+
const save = useAction<[]>(
|
|
74
|
+
{
|
|
75
|
+
handler: async () => {
|
|
76
|
+
if (props.hasPassword) {
|
|
77
|
+
const { otherSessionsRevoked } = await passwordApi.changeMyPassword({
|
|
78
|
+
body: { currentPassword, newPassword: password },
|
|
79
|
+
});
|
|
80
|
+
toaster.show(
|
|
81
|
+
otherSessionsRevoked > 0
|
|
82
|
+
? tr("account.password.changedWithSessions", {
|
|
83
|
+
default: "Password changed - $1 other session(s) signed out",
|
|
84
|
+
args: [String(otherSessionsRevoked)],
|
|
85
|
+
})
|
|
86
|
+
: tr("account.password.changed", { default: "Password changed" }),
|
|
87
|
+
"success",
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
await identityApi.setMyFirstPassword({ body: { password } });
|
|
91
|
+
toaster.show(
|
|
92
|
+
tr("account.password.set", { default: "Password set" }),
|
|
93
|
+
"success",
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
await props.onDone?.();
|
|
97
|
+
close();
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
[currentPassword, password, props.hasPassword, props.onDone],
|
|
101
|
+
);
|
|
102
|
+
const submitting = save.loading;
|
|
103
|
+
|
|
71
104
|
const submit = async (event: FormEvent) => {
|
|
72
105
|
event.preventDefault();
|
|
73
106
|
if (password !== confirmPassword) {
|
|
@@ -79,43 +112,7 @@ export const AccountPasswordDialog = (props: AccountPasswordDialogProps) => {
|
|
|
79
112
|
);
|
|
80
113
|
return;
|
|
81
114
|
}
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
if (props.hasPassword) {
|
|
85
|
-
const { otherSessionsRevoked } = await passwordApi.changeMyPassword({
|
|
86
|
-
body: { currentPassword, newPassword: password },
|
|
87
|
-
});
|
|
88
|
-
toaster.show(
|
|
89
|
-
otherSessionsRevoked > 0
|
|
90
|
-
? tr("account.password.changedWithSessions", {
|
|
91
|
-
default: "Password changed - $1 other session(s) signed out",
|
|
92
|
-
args: [String(otherSessionsRevoked)],
|
|
93
|
-
})
|
|
94
|
-
: tr("account.password.changed", { default: "Password changed" }),
|
|
95
|
-
"success",
|
|
96
|
-
);
|
|
97
|
-
} else {
|
|
98
|
-
await identityApi.setMyFirstPassword({ body: { password } });
|
|
99
|
-
toaster.show(
|
|
100
|
-
tr("account.password.set", { default: "Password set" }),
|
|
101
|
-
"success",
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
await props.onDone?.();
|
|
105
|
-
close();
|
|
106
|
-
} catch (error: any) {
|
|
107
|
-
// The realm's password policy and the wrong-current-password refusal
|
|
108
|
-
// both arrive here with messages worth showing verbatim.
|
|
109
|
-
toaster.show(
|
|
110
|
-
error?.message ??
|
|
111
|
-
tr("account.password.error", {
|
|
112
|
-
default: "Could not save that password",
|
|
113
|
-
}),
|
|
114
|
-
"danger",
|
|
115
|
-
);
|
|
116
|
-
} finally {
|
|
117
|
-
setSubmitting(false);
|
|
118
|
-
}
|
|
115
|
+
void save.run();
|
|
119
116
|
};
|
|
120
117
|
|
|
121
118
|
const title = props.hasPassword
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
RealmConfig,
|
|
6
6
|
} from "alepha/api/users";
|
|
7
7
|
import { updateMyProfileBodySchema } from "alepha/api/users";
|
|
8
|
-
import { useClient } from "alepha/react";
|
|
8
|
+
import { useAction, useClient } from "alepha/react";
|
|
9
9
|
import { useForm } from "alepha/react/form";
|
|
10
10
|
import { useI18n } from "alepha/react/i18n";
|
|
11
11
|
import { AtSign, Camera, Trash2, User } from "lucide-react";
|
|
@@ -53,7 +53,29 @@ const AccountProfile = (props: AccountProfileProps) => {
|
|
|
53
53
|
const fileInput = useRef<HTMLInputElement>(null);
|
|
54
54
|
|
|
55
55
|
const [profile, setProfile] = useState<MyProfile | undefined>(props.profile);
|
|
56
|
-
|
|
56
|
+
// A refused image (too large, a type the realm does not take) is toasted
|
|
57
|
+
// by the app's ActionErrorToaster with the server's message.
|
|
58
|
+
const uploadAvatar = useAction<[file: File]>(
|
|
59
|
+
{
|
|
60
|
+
handler: async (_ctx, file) => {
|
|
61
|
+
setProfile(await avatarApi.updateMyAvatar({ body: { file } }));
|
|
62
|
+
toaster.show(
|
|
63
|
+
tr("account.profile.avatarUpdated", { default: "Avatar updated" }),
|
|
64
|
+
"success",
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
[avatarApi, toaster, tr],
|
|
69
|
+
);
|
|
70
|
+
const removeAvatar = useAction<[]>(
|
|
71
|
+
{
|
|
72
|
+
handler: async () => {
|
|
73
|
+
setProfile(await avatarApi.deleteMyAvatar());
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
[avatarApi],
|
|
77
|
+
);
|
|
78
|
+
const uploading = uploadAvatar.loading || removeAvatar.loading;
|
|
57
79
|
|
|
58
80
|
/*
|
|
59
81
|
* Does this realm have usernames at all?
|
|
@@ -150,50 +172,14 @@ const AccountProfile = (props: AccountProfileProps) => {
|
|
|
150
172
|
return null;
|
|
151
173
|
}
|
|
152
174
|
|
|
153
|
-
const onPickAvatar =
|
|
175
|
+
const onPickAvatar = (event: ChangeEvent<HTMLInputElement>) => {
|
|
154
176
|
const file = event.target.files?.[0];
|
|
177
|
+
// Cleared at once, so picking the same file again still fires a change.
|
|
178
|
+
event.target.value = "";
|
|
155
179
|
if (!file) {
|
|
156
180
|
return;
|
|
157
181
|
}
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
setProfile(await avatarApi.updateMyAvatar({ body: { file } }));
|
|
161
|
-
toaster.show(
|
|
162
|
-
tr("account.profile.avatarUpdated", { default: "Avatar updated" }),
|
|
163
|
-
"success",
|
|
164
|
-
);
|
|
165
|
-
} catch (error: any) {
|
|
166
|
-
toaster.show(
|
|
167
|
-
error?.message ??
|
|
168
|
-
tr("account.profile.avatarUploadError", {
|
|
169
|
-
default: "Could not upload that image",
|
|
170
|
-
}),
|
|
171
|
-
"danger",
|
|
172
|
-
);
|
|
173
|
-
} finally {
|
|
174
|
-
setUploading(false);
|
|
175
|
-
// Reset so picking the same file again still fires a change event.
|
|
176
|
-
if (fileInput.current) {
|
|
177
|
-
fileInput.current.value = "";
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const removeAvatar = async () => {
|
|
183
|
-
setUploading(true);
|
|
184
|
-
try {
|
|
185
|
-
setProfile(await avatarApi.deleteMyAvatar());
|
|
186
|
-
} catch (error: any) {
|
|
187
|
-
toaster.show(
|
|
188
|
-
error?.message ??
|
|
189
|
-
tr("account.profile.avatarRemoveError", {
|
|
190
|
-
default: "Could not remove your avatar",
|
|
191
|
-
}),
|
|
192
|
-
"danger",
|
|
193
|
-
);
|
|
194
|
-
} finally {
|
|
195
|
-
setUploading(false);
|
|
196
|
-
}
|
|
182
|
+
void uploadAvatar.run(file);
|
|
197
183
|
};
|
|
198
184
|
|
|
199
185
|
// Realms opt into avatars (`features.avatars`, off by default), and an
|
|
@@ -254,7 +240,7 @@ const AccountProfile = (props: AccountProfileProps) => {
|
|
|
254
240
|
<Button
|
|
255
241
|
variant="minimal"
|
|
256
242
|
size="sm"
|
|
257
|
-
onClick={removeAvatar}
|
|
243
|
+
onClick={() => removeAvatar.run()}
|
|
258
244
|
disabled={uploading}
|
|
259
245
|
>
|
|
260
246
|
<Trash2 className="size-4" />
|
|
@@ -111,39 +111,36 @@ const AccountSecurity = (props: AccountSecurityProps) => {
|
|
|
111
111
|
* A session alone is not proof: someone at an unattended signed-in browser
|
|
112
112
|
* could otherwise strip the factor and come back later at leisure.
|
|
113
113
|
*/
|
|
114
|
-
const disableMfa =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
} catch (error: any) {
|
|
138
|
-
toaster.show(
|
|
139
|
-
error?.message ??
|
|
140
|
-
tr("account.security.invalidCode", {
|
|
141
|
-
default: "That code is not valid",
|
|
114
|
+
const disableMfa = useAction<[]>(
|
|
115
|
+
{
|
|
116
|
+
handler: async () => {
|
|
117
|
+
const code = await dialog.prompt({
|
|
118
|
+
title: tr("account.security.mfaDisableTitle", {
|
|
119
|
+
default: "Turn off two-factor authentication?",
|
|
120
|
+
}),
|
|
121
|
+
description: tr("account.security.mfaDisableDescription", {
|
|
122
|
+
default:
|
|
123
|
+
"Enter a code from your authenticator app, or one of your recovery codes.",
|
|
124
|
+
}),
|
|
125
|
+
confirmLabel: tr("account.security.mfaTurnOff", {
|
|
126
|
+
default: "Turn off",
|
|
127
|
+
}),
|
|
128
|
+
});
|
|
129
|
+
if (!code) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
await mfaApi.disableTotp({ body: { code: String(code) } });
|
|
133
|
+
await reloadMfa();
|
|
134
|
+
toaster.show(
|
|
135
|
+
tr("account.security.mfaDisabled", {
|
|
136
|
+
default: "Two-factor authentication is off",
|
|
142
137
|
}),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
"success",
|
|
139
|
+
);
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
[dialog, mfaApi, reloadMfa, toaster, tr],
|
|
143
|
+
);
|
|
147
144
|
|
|
148
145
|
const [newCodes, setNewCodes] = useState<string[]>();
|
|
149
146
|
|
|
@@ -181,37 +178,33 @@ const AccountSecurity = (props: AccountSecurityProps) => {
|
|
|
181
178
|
[mfaApi, dialog],
|
|
182
179
|
);
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!ok) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
try {
|
|
202
|
-
await api.unlinkMyIdentity({ params: { id: identity.id } });
|
|
203
|
-
await reload();
|
|
204
|
-
} catch (error: any) {
|
|
205
|
-
// Includes the last-identity refusal, whose message is the whole point.
|
|
206
|
-
toaster.show(
|
|
207
|
-
error?.message ??
|
|
208
|
-
tr("account.security.unlinkError", {
|
|
209
|
-
default: "Could not remove that method",
|
|
181
|
+
// The last-identity refusal arrives as an error whose message is the whole
|
|
182
|
+
// point; the app's ActionErrorToaster shows it verbatim.
|
|
183
|
+
const unlink = useAction<[identity: MyIdentity]>(
|
|
184
|
+
{
|
|
185
|
+
handler: async (_ctx, identity) => {
|
|
186
|
+
const label = PROVIDER_LABELS[identity.provider] ?? identity.provider;
|
|
187
|
+
const ok = await dialog.confirm({
|
|
188
|
+
title: tr("account.security.unlinkTitle", {
|
|
189
|
+
default: "Remove $1?",
|
|
190
|
+
args: [label],
|
|
191
|
+
}),
|
|
192
|
+
description: tr("account.security.unlinkDescription", {
|
|
193
|
+
default: "You will no longer be able to sign in with $1.",
|
|
194
|
+
args: [label],
|
|
210
195
|
}),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
196
|
+
confirmLabel: tr("account.security.unlink", { default: "Remove" }),
|
|
197
|
+
destructive: true,
|
|
198
|
+
});
|
|
199
|
+
if (!ok) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await api.unlinkMyIdentity({ params: { id: identity.id } });
|
|
203
|
+
await reload();
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
[api, dialog, tr],
|
|
207
|
+
);
|
|
215
208
|
|
|
216
209
|
return (
|
|
217
210
|
<AccountPage variant="form">
|
|
@@ -237,7 +230,7 @@ const AccountSecurity = (props: AccountSecurityProps) => {
|
|
|
237
230
|
<Button
|
|
238
231
|
variant="minimal"
|
|
239
232
|
size="sm"
|
|
240
|
-
onClick={() => unlink(identity)}
|
|
233
|
+
onClick={() => unlink.run(identity)}
|
|
241
234
|
aria-label={tr("account.security.unlinkAria", {
|
|
242
235
|
default: "Remove $1",
|
|
243
236
|
args: [identity.provider],
|
|
@@ -298,7 +291,7 @@ const AccountSecurity = (props: AccountSecurityProps) => {
|
|
|
298
291
|
variant="solid"
|
|
299
292
|
intent="none"
|
|
300
293
|
size="sm"
|
|
301
|
-
onClick={disableMfa}
|
|
294
|
+
onClick={() => disableMfa.run()}
|
|
302
295
|
>
|
|
303
296
|
<ShieldOff className="size-4" />
|
|
304
297
|
{tr("account.security.mfaTurnOff", { default: "Turn off" })}
|
|
@@ -87,7 +87,7 @@ const AccountSessions = (props: AccountSessionsProps) => {
|
|
|
87
87
|
|
|
88
88
|
const revoke = useAction<[session: MySession], boolean>(
|
|
89
89
|
{
|
|
90
|
-
handler: async (session) => {
|
|
90
|
+
handler: async (_ctx, session) => {
|
|
91
91
|
const ok = await dialog.confirm({
|
|
92
92
|
title: tr("account.sessions.revokeTitle", {
|
|
93
93
|
default: "Revoke this session?",
|
|
@@ -175,26 +175,18 @@ export const ApiKeyCreateDialog = (props: ApiKeyCreateDialogProps) => {
|
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
toaster.show(
|
|
191
|
-
error?.message ??
|
|
192
|
-
tr("account.keys.createError", {
|
|
193
|
-
default: "Could not create that key",
|
|
194
|
-
}),
|
|
195
|
-
"danger",
|
|
196
|
-
);
|
|
197
|
-
}
|
|
178
|
+
// A refusal is toasted by the app's ActionErrorToaster: the form
|
|
179
|
+
// emits it, so a toast here put it on screen twice.
|
|
180
|
+
const created = await api.createApiKey({
|
|
181
|
+
body: {
|
|
182
|
+
name,
|
|
183
|
+
description: values.description?.trim() || undefined,
|
|
184
|
+
expiresIn: values.expiresIn as never,
|
|
185
|
+
permissions,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
await props.onCreated(created.token);
|
|
189
|
+
props.onOpenChange(false);
|
|
198
190
|
},
|
|
199
191
|
},
|
|
200
192
|
// Not keyed on the options: rebuilt when they arrive, the form dropped
|
package/src/admin/AdminFiles.tsx
CHANGED
|
@@ -81,7 +81,7 @@ export const AdminFiles = () => {
|
|
|
81
81
|
|
|
82
82
|
const upload = useAction<[ChangeEvent<HTMLInputElement>], void>(
|
|
83
83
|
{
|
|
84
|
-
handler: async (e) => {
|
|
84
|
+
handler: async (_ctx, e) => {
|
|
85
85
|
const file = e.target.files?.[0];
|
|
86
86
|
// Reset so the same file can be re-selected on a subsequent click,
|
|
87
87
|
// regardless of whether the upload succeeds.
|
package/src/admin/AdminJobs.tsx
CHANGED
|
@@ -56,7 +56,7 @@ export const AdminJobs = () => {
|
|
|
56
56
|
|
|
57
57
|
const trigger = useAction<[JobRegistration], void>(
|
|
58
58
|
{
|
|
59
|
-
handler: async (job) => {
|
|
59
|
+
handler: async (_ctx, job) => {
|
|
60
60
|
await client.triggerJob({ params: { name: job.name }, body: {} });
|
|
61
61
|
toast.success(
|
|
62
62
|
tr("admin.jobs.triggered", {
|
package/src/admin/AdminKeys.tsx
CHANGED
|
@@ -132,7 +132,7 @@ export const AdminKeys = () => {
|
|
|
132
132
|
[AdminApiKeyResource[], { clearSelection: () => void; refresh: () => void }]
|
|
133
133
|
>(
|
|
134
134
|
{
|
|
135
|
-
handler: async (items, ctx) => {
|
|
135
|
+
handler: async (_ctx, items, ctx) => {
|
|
136
136
|
const targets = items.filter((k) => !k.revokedAt);
|
|
137
137
|
if (targets.length === 0) {
|
|
138
138
|
toast.error(
|
|
@@ -156,7 +156,7 @@ export const AdminParameters = (props: AdminParametersProps = {}) => {
|
|
|
156
156
|
|
|
157
157
|
const importParams = useAction<[File], void>(
|
|
158
158
|
{
|
|
159
|
-
handler: async (file) => {
|
|
159
|
+
handler: async (_ctx, file) => {
|
|
160
160
|
let parsed: unknown;
|
|
161
161
|
try {
|
|
162
162
|
parsed = JSON.parse(await file.text());
|
|
@@ -227,7 +227,7 @@ export const AdminParameters = (props: AdminParametersProps = {}) => {
|
|
|
227
227
|
|
|
228
228
|
const rollback = useAction<[number], void>(
|
|
229
229
|
{
|
|
230
|
-
handler: async (version) => {
|
|
230
|
+
handler: async (_ctx, version) => {
|
|
231
231
|
if (!selected) return;
|
|
232
232
|
const ok = await dialog.confirm({
|
|
233
233
|
title: tr("admin.parameters.rollbackTitle", {
|
|
@@ -274,8 +274,8 @@ export const AdminParameters = (props: AdminParametersProps = {}) => {
|
|
|
274
274
|
nodes={visibleNodes}
|
|
275
275
|
selected={selected}
|
|
276
276
|
onSelect={setSelected}
|
|
277
|
-
onExportAll={exportAll.run}
|
|
278
|
-
onImport={importParams.run}
|
|
277
|
+
onExportAll={() => exportAll.run()}
|
|
278
|
+
onImport={(file) => importParams.run(file)}
|
|
279
279
|
exporting={exportAll.loading}
|
|
280
280
|
importing={importParams.loading}
|
|
281
281
|
orphanCount={orphanCount}
|
|
@@ -315,7 +315,9 @@ export const AdminParameters = (props: AdminParametersProps = {}) => {
|
|
|
315
315
|
key={`history-${selected}`}
|
|
316
316
|
name={selected}
|
|
317
317
|
reloadKey={reloadKey}
|
|
318
|
-
onRollback={
|
|
318
|
+
onRollback={async (version) => {
|
|
319
|
+
await rollback.run(version);
|
|
320
|
+
}}
|
|
319
321
|
onCollapse={toggleHistory}
|
|
320
322
|
className={historyCollapsed ? "lg:hidden" : undefined}
|
|
321
323
|
/>
|
|
@@ -9,8 +9,8 @@ import { useRef } from "react";
|
|
|
9
9
|
import { Button } from "../core/Button.tsx";
|
|
10
10
|
|
|
11
11
|
export interface AdminParametersTreeFooterActionsProps {
|
|
12
|
-
onExportAll: () =>
|
|
13
|
-
onImport: (file: File) =>
|
|
12
|
+
onExportAll: () => unknown;
|
|
13
|
+
onImport: (file: File) => unknown;
|
|
14
14
|
disabled?: boolean;
|
|
15
15
|
exporting?: boolean;
|
|
16
16
|
importing?: boolean;
|
|
@@ -17,8 +17,8 @@ export interface AdminParametersTreePaneProps {
|
|
|
17
17
|
nodes: ParamNode[] | undefined;
|
|
18
18
|
selected: string | undefined;
|
|
19
19
|
onSelect: (name: string) => void;
|
|
20
|
-
onExportAll: () =>
|
|
21
|
-
onImport: (file: File) =>
|
|
20
|
+
onExportAll: () => unknown;
|
|
21
|
+
onImport: (file: File) => unknown;
|
|
22
22
|
exporting?: boolean;
|
|
23
23
|
importing?: boolean;
|
|
24
24
|
/**
|
|
@@ -507,16 +507,14 @@ export class AdminRouter {
|
|
|
507
507
|
});
|
|
508
508
|
|
|
509
509
|
/**
|
|
510
|
-
*
|
|
511
|
-
* gates every read with `["admin:payment:read", "payments:read"]` — and
|
|
512
|
-
* `$pageNav` treats an array as AND, the same way `$secure` does.
|
|
510
|
+
* Uses the same read permission as `AdminPaymentController`.
|
|
513
511
|
*/
|
|
514
512
|
payments = $pageNav({
|
|
515
513
|
parent: this.layout,
|
|
516
514
|
path: "/payments",
|
|
517
515
|
name: "payments",
|
|
518
516
|
head: this.adminHead("Payments", "admin.nav.payments"),
|
|
519
|
-
permission: ["admin:payment:read"
|
|
517
|
+
permission: ["admin:payment:read"],
|
|
520
518
|
can: () => this.paymentApi.listIntents.can(),
|
|
521
519
|
nav: {
|
|
522
520
|
label: "Payments",
|
|
@@ -179,7 +179,7 @@ export const AdminSessions = () => {
|
|
|
179
179
|
[SessionResource[], { clearSelection: () => void; refresh: () => void }]
|
|
180
180
|
>(
|
|
181
181
|
{
|
|
182
|
-
handler: async (items, ctx) => {
|
|
182
|
+
handler: async (_ctx, items, ctx) => {
|
|
183
183
|
if (items.length === 0) return;
|
|
184
184
|
const ok = await dialog.confirm({
|
|
185
185
|
title: tr("admin.sessions.bulkRevokeTitle", {
|
|
@@ -3,10 +3,10 @@ import * as React from "react";
|
|
|
3
3
|
void React;
|
|
4
4
|
|
|
5
5
|
import type { AdminAvatarController, UserResource } from "alepha/api/users";
|
|
6
|
-
import { useClient } from "alepha/react";
|
|
6
|
+
import { useAction, useClient } from "alepha/react";
|
|
7
7
|
import { useI18n } from "alepha/react/i18n";
|
|
8
8
|
import { ImageUp, Trash2 } from "lucide-react";
|
|
9
|
-
import { useRef
|
|
9
|
+
import { useRef } from "react";
|
|
10
10
|
|
|
11
11
|
import { Button } from "../core/Button.tsx";
|
|
12
12
|
import { useToast } from "../core/useToast.tsx";
|
|
@@ -37,29 +37,24 @@ export const AdminUserAvatarControl = (props: AdminUserAvatarControlProps) => {
|
|
|
37
37
|
const toaster = useToast();
|
|
38
38
|
const { tr } = useI18n();
|
|
39
39
|
const input = useRef<HTMLInputElement>(null);
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
// A failure is toasted by the app's ActionErrorToaster, with the server's
|
|
42
|
+
// message (an image too large, a type refused).
|
|
43
|
+
const change = useAction<[task: () => Promise<UserResource>, done: string]>(
|
|
44
|
+
{
|
|
45
|
+
handler: async (_ctx, task, done) => {
|
|
46
|
+
props.onChanged(await task());
|
|
47
|
+
toaster.success(done);
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
[props.onChanged, toaster],
|
|
51
|
+
);
|
|
52
|
+
const busy = change.loading;
|
|
41
53
|
|
|
42
54
|
if (!client.updateUserAvatar.can()) {
|
|
43
55
|
return null;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
const run = async (task: () => Promise<UserResource>, done: string) => {
|
|
47
|
-
setBusy(true);
|
|
48
|
-
try {
|
|
49
|
-
props.onChanged(await task());
|
|
50
|
-
toaster.success(done);
|
|
51
|
-
} catch (error: any) {
|
|
52
|
-
toaster.error(
|
|
53
|
-
error?.message ??
|
|
54
|
-
tr("admin.userDetail.avatar.failed", {
|
|
55
|
-
default: "Could not change the avatar.",
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
} finally {
|
|
59
|
-
setBusy(false);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
58
|
return (
|
|
64
59
|
<div className="flex flex-wrap gap-2">
|
|
65
60
|
<input
|
|
@@ -74,7 +69,7 @@ export const AdminUserAvatarControl = (props: AdminUserAvatarControlProps) => {
|
|
|
74
69
|
// in a row fires no `change` while the value is still set.
|
|
75
70
|
event.target.value = "";
|
|
76
71
|
if (!file) return;
|
|
77
|
-
void run(
|
|
72
|
+
void change.run(
|
|
78
73
|
async () =>
|
|
79
74
|
(await client.updateUserAvatar({
|
|
80
75
|
params: { id: props.user.id },
|
|
@@ -105,7 +100,7 @@ export const AdminUserAvatarControl = (props: AdminUserAvatarControlProps) => {
|
|
|
105
100
|
loading={busy}
|
|
106
101
|
data-testid="admin-avatar-remove"
|
|
107
102
|
onClick={() =>
|
|
108
|
-
void run(
|
|
103
|
+
void change.run(
|
|
109
104
|
async () =>
|
|
110
105
|
(await client.deleteUserAvatar({
|
|
111
106
|
params: { id: props.user.id },
|
|
@@ -406,7 +406,7 @@ export const AdminUserDetail = (props: AdminUserDetailProps) => {
|
|
|
406
406
|
|
|
407
407
|
const removeIdentity = useAction<[IdentityResource]>(
|
|
408
408
|
{
|
|
409
|
-
handler: async (identity) => {
|
|
409
|
+
handler: async (_ctx, identity) => {
|
|
410
410
|
const provider =
|
|
411
411
|
PROVIDER_LABELS[identity.provider] ?? identity.provider;
|
|
412
412
|
const ok = await dialog.confirm({
|
|
@@ -449,7 +449,7 @@ export const AdminUserDetail = (props: AdminUserDetailProps) => {
|
|
|
449
449
|
*/
|
|
450
450
|
const clearTotp = useAction<[IdentityResource]>(
|
|
451
451
|
{
|
|
452
|
-
handler: async (identity) => {
|
|
452
|
+
handler: async (_ctx, identity) => {
|
|
453
453
|
// Named, the same way `toggleEnabled` and `remove` name theirs. An
|
|
454
454
|
// admin can have several user pages open, and this is the one action
|
|
455
455
|
// whose confirmation must leave no doubt about whose account it is.
|
|
@@ -501,7 +501,7 @@ export const AdminUserDetail = (props: AdminUserDetailProps) => {
|
|
|
501
501
|
|
|
502
502
|
const revokeSession = useAction<[SessionResource, () => void]>(
|
|
503
503
|
{
|
|
504
|
-
handler: async (s, refresh) => {
|
|
504
|
+
handler: async (_ctx, s, refresh) => {
|
|
505
505
|
const ok = await dialog.confirm({
|
|
506
506
|
title: tr("admin.userDetail.revokeTitle", {
|
|
507
507
|
default: "Revoke session",
|
|
@@ -527,7 +527,7 @@ export const AdminUserDetail = (props: AdminUserDetailProps) => {
|
|
|
527
527
|
[SessionResource[], { refresh: () => void; clearSelection: () => void }]
|
|
528
528
|
>(
|
|
529
529
|
{
|
|
530
|
-
handler: async (items, ctx) => {
|
|
530
|
+
handler: async (_ctx, items, ctx) => {
|
|
531
531
|
const ok = await dialog.confirm({
|
|
532
532
|
title: tr("admin.userDetail.bulkRevokeTitle", {
|
|
533
533
|
default: "Revoke sessions",
|