@alepha/ui 0.32.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.
Files changed (186) hide show
  1. package/dist/account/AccountConnections.js +1 -1
  2. package/dist/account/AccountConnections.js.map +1 -1
  3. package/dist/account/AccountDeleteDialog.d.ts.map +1 -1
  4. package/dist/account/AccountDeleteDialog.js +17 -17
  5. package/dist/account/AccountDeleteDialog.js.map +1 -1
  6. package/dist/account/AccountKeys.js +2 -2
  7. package/dist/account/AccountKeys.js.map +1 -1
  8. package/dist/account/AccountMfaDialog.d.ts.map +1 -1
  9. package/dist/account/AccountMfaDialog.js +19 -25
  10. package/dist/account/AccountMfaDialog.js.map +1 -1
  11. package/dist/account/AccountPasswordDialog.d.ts.map +1 -1
  12. package/dist/account/AccountPasswordDialog.js +25 -24
  13. package/dist/account/AccountPasswordDialog.js.map +1 -1
  14. package/dist/account/AccountProfile.d.ts.map +1 -1
  15. package/dist/account/AccountProfile.js +17 -24
  16. package/dist/account/AccountProfile.js.map +1 -1
  17. package/dist/account/AccountSecurity.d.ts.map +1 -1
  18. package/dist/account/AccountSecurity.js +21 -19
  19. package/dist/account/AccountSecurity.js.map +1 -1
  20. package/dist/account/AccountSessions.js +1 -1
  21. package/dist/account/AccountSessions.js.map +1 -1
  22. package/dist/account/ApiKeyCreateDialog.d.ts.map +1 -1
  23. package/dist/account/ApiKeyCreateDialog.js +8 -12
  24. package/dist/account/ApiKeyCreateDialog.js.map +1 -1
  25. package/dist/admin/AdminFiles.js +1 -1
  26. package/dist/admin/AdminFiles.js.map +1 -1
  27. package/dist/admin/AdminJobs.js +1 -1
  28. package/dist/admin/AdminJobs.js.map +1 -1
  29. package/dist/admin/AdminKeys.js +1 -1
  30. package/dist/admin/AdminKeys.js.map +1 -1
  31. package/dist/admin/AdminParameters.d.ts.map +1 -1
  32. package/dist/admin/AdminParameters.js +7 -5
  33. package/dist/admin/AdminParameters.js.map +1 -1
  34. package/dist/admin/AdminParametersTreeFooterActions.d.ts +2 -2
  35. package/dist/admin/AdminParametersTreeFooterActions.d.ts.map +1 -1
  36. package/dist/admin/AdminParametersTreeFooterActions.js.map +1 -1
  37. package/dist/admin/AdminParametersTreePane.d.ts +2 -2
  38. package/dist/admin/AdminParametersTreePane.d.ts.map +1 -1
  39. package/dist/admin/AdminParametersTreePane.js.map +1 -1
  40. package/dist/admin/AdminRouter.d.ts +1 -3
  41. package/dist/admin/AdminRouter.d.ts.map +1 -1
  42. package/dist/admin/AdminRouter.js +2 -4
  43. package/dist/admin/AdminRouter.js.map +1 -1
  44. package/dist/admin/AdminSessions.js +1 -1
  45. package/dist/admin/AdminSessions.js.map +1 -1
  46. package/dist/admin/AdminUserAvatarControl.d.ts.map +1 -1
  47. package/dist/admin/AdminUserAvatarControl.js +9 -16
  48. package/dist/admin/AdminUserAvatarControl.js.map +1 -1
  49. package/dist/admin/AdminUserDetail.js +4 -4
  50. package/dist/admin/AdminUserDetail.js.map +1 -1
  51. package/dist/admin/AdminUsers.d.ts.map +1 -1
  52. package/dist/admin/AdminUsers.js +10 -12
  53. package/dist/admin/AdminUsers.js.map +1 -1
  54. package/dist/admin/AdminUsersRolesPicker.d.ts +5 -1
  55. package/dist/admin/AdminUsersRolesPicker.d.ts.map +1 -1
  56. package/dist/admin/AdminUsersRolesPicker.js +2 -3
  57. package/dist/admin/AdminUsersRolesPicker.js.map +1 -1
  58. package/dist/admin/analytics/QueryPanel.js +1 -1
  59. package/dist/admin/analytics/QueryPanel.js.map +1 -1
  60. package/dist/admin/useConfirmedAction.d.ts +8 -2
  61. package/dist/admin/useConfirmedAction.d.ts.map +1 -1
  62. package/dist/admin/useConfirmedAction.js +15 -4
  63. package/dist/admin/useConfirmedAction.js.map +1 -1
  64. package/dist/auth/AuthLogin.d.ts.map +1 -1
  65. package/dist/auth/AuthLogin.js +4 -4
  66. package/dist/auth/AuthLogin.js.map +1 -1
  67. package/dist/auth/AuthRegister.js.map +1 -1
  68. package/dist/core/index.js +1 -1
  69. package/dist/form/AutoForm.js +1 -1
  70. package/dist/form/AutoForm.js.map +1 -1
  71. package/dist/form/Control.js +1 -1
  72. package/dist/form/Control.js.map +1 -1
  73. package/dist/form/ControlArray.js +5 -5
  74. package/dist/form/ControlArray.js.map +1 -1
  75. package/dist/form/ControlSelect.js +2 -2
  76. package/dist/form/ControlSelect.js.map +1 -1
  77. package/dist/form/ControlUpload.d.ts +1 -1
  78. package/dist/form/ControlUpload.js.map +1 -1
  79. package/dist/i18n/fr/uiFr.d.ts.map +1 -1
  80. package/dist/i18n/fr/uiFr.js +0 -9
  81. package/dist/i18n/fr/uiFr.js.map +1 -1
  82. package/dist/organizations/MyOrganizationInvitations.js +2 -2
  83. package/dist/organizations/MyOrganizationInvitations.js.map +1 -1
  84. package/dist/organizations/OrganizationInviteDialog.js +1 -1
  85. package/dist/organizations/OrganizationInviteDialog.js.map +1 -1
  86. package/dist/organizations/OrganizationMembers.js +1 -1
  87. package/dist/organizations/OrganizationMembers.js.map +1 -1
  88. package/dist/organizations/OrganizationPendingInvitations.js +1 -1
  89. package/dist/organizations/OrganizationPendingInvitations.js.map +1 -1
  90. package/dist/organizations/OrganizationRanks.js +3 -3
  91. package/dist/organizations/OrganizationRanks.js.map +1 -1
  92. package/dist/organizations/useInviteOrganizationMember.d.ts +6 -1
  93. package/dist/organizations/useInviteOrganizationMember.d.ts.map +1 -1
  94. package/dist/organizations/useInviteOrganizationMember.js +13 -13
  95. package/dist/organizations/useInviteOrganizationMember.js.map +1 -1
  96. package/dist/organizations/useRevokeOrganizationInvitation.d.ts +7 -1
  97. package/dist/organizations/useRevokeOrganizationInvitation.d.ts.map +1 -1
  98. package/dist/organizations/useRevokeOrganizationInvitation.js +13 -2
  99. package/dist/organizations/useRevokeOrganizationInvitation.js.map +1 -1
  100. package/dist/shell/ButtonUser.d.ts +1 -2
  101. package/dist/shell/ButtonUser.d.ts.map +1 -1
  102. package/dist/shell/ButtonUser.js +14 -42
  103. package/dist/shell/ButtonUser.js.map +1 -1
  104. package/dist/shell/ButtonUserContent.d.ts +13 -0
  105. package/dist/shell/ButtonUserContent.d.ts.map +1 -0
  106. package/dist/shell/ButtonUserContent.js +52 -0
  107. package/dist/shell/ButtonUserContent.js.map +1 -0
  108. package/dist/shell/ButtonUserPlaceholder.d.ts +14 -0
  109. package/dist/shell/ButtonUserPlaceholder.d.ts.map +1 -0
  110. package/dist/shell/ButtonUserPlaceholder.js +17 -0
  111. package/dist/shell/ButtonUserPlaceholder.js.map +1 -0
  112. package/dist/styles.css +31 -0
  113. package/dist/table/DataTable.js +1 -1
  114. package/dist/table/DataTable.js.map +1 -1
  115. package/dist/table/DataTableFilterBar.js +2 -2
  116. package/dist/table/DataTableFilterBar.js.map +1 -1
  117. package/dist/table/dataTableBaseProps.d.ts +1 -1
  118. package/dist/table/dataTableTypes.d.ts +3 -3
  119. package/dist/table/dataTableTypes.d.ts.map +1 -1
  120. package/dist/table/useDataTableData.d.ts.map +1 -1
  121. package/dist/table/useDataTableData.js +3 -1
  122. package/dist/table/useDataTableData.js.map +1 -1
  123. package/dist/table/useDataTableRefresh.js +2 -2
  124. package/dist/table/useDataTableRefresh.js.map +1 -1
  125. package/dist/table/useDataTableSummary.d.ts.map +1 -1
  126. package/dist/table/useDataTableSummary.js +2 -1
  127. package/dist/table/useDataTableSummary.js.map +1 -1
  128. package/package.json +6 -6
  129. package/src/account/AccountConnections.tsx +1 -1
  130. package/src/account/AccountDeleteDialog.tsx +25 -31
  131. package/src/account/AccountKeys.tsx +2 -2
  132. package/src/account/AccountMfaDialog.tsx +33 -27
  133. package/src/account/AccountPasswordDialog.tsx +36 -39
  134. package/src/account/AccountProfile.tsx +29 -43
  135. package/src/account/AccountSecurity.tsx +57 -64
  136. package/src/account/AccountSessions.tsx +1 -1
  137. package/src/account/ApiKeyCreateDialog.tsx +12 -20
  138. package/src/account/__tests__/AccountRouter.spec.ts +2 -1
  139. package/src/admin/AdminFiles.tsx +1 -1
  140. package/src/admin/AdminJobs.tsx +1 -1
  141. package/src/admin/AdminKeys.tsx +1 -1
  142. package/src/admin/AdminParameters.tsx +7 -5
  143. package/src/admin/AdminParametersTreeFooterActions.tsx +2 -2
  144. package/src/admin/AdminParametersTreePane.tsx +2 -2
  145. package/src/admin/AdminRouter.tsx +2 -4
  146. package/src/admin/AdminSessions.tsx +1 -1
  147. package/src/admin/AdminUserAvatarControl.tsx +17 -22
  148. package/src/admin/AdminUserDetail.tsx +4 -4
  149. package/src/admin/AdminUsers.tsx +10 -12
  150. package/src/admin/AdminUsersRolesPicker.tsx +11 -4
  151. package/src/admin/__tests__/AdminRouter.spec.ts +3 -2
  152. package/src/admin/analytics/QueryPanel.tsx +1 -1
  153. package/src/admin/useConfirmedAction.tsx +24 -10
  154. package/src/auth/AuthLogin.tsx +10 -9
  155. package/src/auth/AuthRegister.tsx +2 -2
  156. package/src/form/AutoForm.tsx +1 -1
  157. package/src/form/Control.tsx +1 -1
  158. package/src/form/ControlArray.tsx +5 -5
  159. package/src/form/ControlSelect.tsx +2 -2
  160. package/src/form/ControlUpload.tsx +1 -1
  161. package/src/form/__tests__/ControlArrayChildChange.browser.spec.tsx +1 -1
  162. package/src/i18n/fr/uiFr.ts +0 -9
  163. package/src/organizations/MyOrganizationInvitations.tsx +2 -2
  164. package/src/organizations/OrganizationInviteDialog.tsx +1 -1
  165. package/src/organizations/OrganizationMembers.tsx +1 -1
  166. package/src/organizations/OrganizationPendingInvitations.tsx +1 -1
  167. package/src/organizations/OrganizationRanks.tsx +3 -3
  168. package/src/organizations/useInviteOrganizationMember.ts +22 -15
  169. package/src/organizations/useRevokeOrganizationInvitation.ts +23 -4
  170. package/src/shell/ButtonUser.tsx +14 -79
  171. package/src/shell/ButtonUserContent.tsx +92 -0
  172. package/src/shell/ButtonUserPlaceholder.tsx +25 -0
  173. package/src/shell/__tests__/ActionErrorToaster.browser.spec.tsx +1 -1
  174. package/src/shell/__tests__/ActionErrorToasterHandled.browser.spec.tsx +1 -2
  175. package/src/shell/__tests__/AppShell.pageCache.spec.tsx +67 -0
  176. package/src/styles.css +31 -0
  177. package/src/table/DataTable.tsx +1 -1
  178. package/src/table/DataTableFilterBar.tsx +2 -2
  179. package/src/table/__tests__/DataTableFilterDateRange.browser.spec.tsx +1 -1
  180. package/src/table/__tests__/DataTableQuerySeed.browser.spec.tsx +1 -1
  181. package/src/table/__tests__/DataTableShareFilters.browser.spec.tsx +1 -1
  182. package/src/table/dataTableBaseProps.ts +1 -1
  183. package/src/table/dataTableTypes.ts +3 -3
  184. package/src/table/useDataTableData.ts +2 -0
  185. package/src/table/useDataTableRefresh.ts +3 -3
  186. package/src/table/useDataTableSummary.ts +2 -1
@@ -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
- const [uploading, setUploading] = useState(false);
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 = async (event: ChangeEvent<HTMLInputElement>) => {
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
- setUploading(true);
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 = async () => {
115
- const code = await dialog.prompt({
116
- title: tr("account.security.mfaDisableTitle", {
117
- default: "Turn off two-factor authentication?",
118
- }),
119
- description: tr("account.security.mfaDisableDescription", {
120
- default:
121
- "Enter a code from your authenticator app, or one of your recovery codes.",
122
- }),
123
- confirmLabel: tr("account.security.mfaTurnOff", { default: "Turn off" }),
124
- });
125
- if (!code) {
126
- return;
127
- }
128
- try {
129
- await mfaApi.disableTotp({ body: { code: String(code) } });
130
- await reloadMfa();
131
- toaster.show(
132
- tr("account.security.mfaDisabled", {
133
- default: "Two-factor authentication is off",
134
- }),
135
- "success",
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
- "danger",
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
- const unlink = async (identity: MyIdentity) => {
185
- const label = PROVIDER_LABELS[identity.provider] ?? identity.provider;
186
- const ok = await dialog.confirm({
187
- title: tr("account.security.unlinkTitle", {
188
- default: "Remove $1?",
189
- args: [label],
190
- }),
191
- description: tr("account.security.unlinkDescription", {
192
- default: "You will no longer be able to sign in with $1.",
193
- args: [label],
194
- }),
195
- confirmLabel: tr("account.security.unlink", { default: "Remove" }),
196
- destructive: true,
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
- "danger",
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
- try {
179
- const created: any = await api.createApiKey({
180
- body: {
181
- name,
182
- description: values.description?.trim() || undefined,
183
- expiresIn: values.expiresIn as never,
184
- permissions,
185
- },
186
- });
187
- await props.onCreated(created.token);
188
- props.onOpenChange(false);
189
- } catch (error: any) {
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
@@ -1,4 +1,5 @@
1
- import { Alepha, OPTIONS } from "alepha";
1
+ import { Alepha } from "alepha";
2
+ import { OPTIONS } from "alepha/internal";
2
3
  import {
3
4
  $page,
4
5
  AlephaReactRouter,
@@ -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.
@@ -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", {
@@ -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={rollback.run}
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: () => void | Promise<void>;
13
- onImport: (file: File) => void | Promise<void>;
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: () => void | Promise<void>;
21
- onImport: (file: File) => void | Promise<void>;
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
- * Both permissions are required, matching `AdminPaymentController`, which
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", "payments: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, useState } from "react";
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
- const [busy, setBusy] = useState(false);
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",
@@ -154,7 +154,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
154
154
 
155
155
  const setRoles = useAction<[UserEntity, string[]]>(
156
156
  {
157
- handler: async (user, roles) => {
157
+ handler: async (_ctx, user, roles) => {
158
158
  await client.updateUser({
159
159
  params: { id: user.id },
160
160
  query: { userRealmName: props.userRealmName },
@@ -172,7 +172,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
172
172
 
173
173
  const toggleEnabled = useAction<[UserEntity]>(
174
174
  {
175
- handler: async (user) => {
175
+ handler: async (_ctx, user) => {
176
176
  if (isSelf(user)) {
177
177
  toast.error(
178
178
  tr("admin.users.cantDisableSelf", {
@@ -216,7 +216,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
216
216
 
217
217
  const deleteUser = useAction<[UserEntity]>(
218
218
  {
219
- handler: async (user) => {
219
+ handler: async (_ctx, user) => {
220
220
  const label = userLabel(user);
221
221
  const ok = await dialog.confirm({
222
222
  title: tr("admin.users.deleteTitle", { default: "Delete user" }),
@@ -239,7 +239,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
239
239
 
240
240
  const bulkDelete = useAction<[UserEntity[]]>(
241
241
  {
242
- handler: async (items) => {
242
+ handler: async (_ctx, items) => {
243
243
  const targets = items.filter((u) => !isSelf(u));
244
244
  if (targets.length === 0) {
245
245
  toast.error(
@@ -275,7 +275,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
275
275
 
276
276
  const bulkDisable = useAction<[UserEntity[]]>(
277
277
  {
278
- handler: async (items) => {
278
+ handler: async (_ctx, items) => {
279
279
  const enabled = items.filter((u) => u.enabled && !isSelf(u));
280
280
  if (enabled.length === 0) {
281
281
  toast.error(
@@ -329,7 +329,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
329
329
  icon: UserX,
330
330
  destructive: true,
331
331
  onClick: async (items, ctx) => {
332
- await bulkDisable.run(items);
332
+ if (!(await bulkDisable.run(items)).ok) return;
333
333
  ctx.clearSelection();
334
334
  ctx.refresh();
335
335
  },
@@ -341,7 +341,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
341
341
  icon: Trash2,
342
342
  destructive: true,
343
343
  onClick: async (items, ctx) => {
344
- await bulkDelete.run(items);
344
+ if (!(await bulkDelete.run(items)).ok) return;
345
345
  ctx.clearSelection();
346
346
  ctx.refresh();
347
347
  },
@@ -422,7 +422,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
422
422
  <AdminUsersRolesPicker
423
423
  user={u}
424
424
  availableRoles={availableRoles}
425
- onToggle={(roles) => setRoles.run(u, roles)}
425
+ onToggle={async (roles) => (await setRoles.run(u, roles)).ok}
426
426
  rolesLabel={tr("admin.users.rolesLabel", { default: "Roles" })}
427
427
  noRolesLabel={tr("admin.users.noRoles", {
428
428
  default: "No roles",
@@ -477,8 +477,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
477
477
  _u: UserEntity,
478
478
  { refresh }: { refresh: () => void },
479
479
  ) => {
480
- await toggleEnabled.run(u);
481
- refresh();
480
+ if ((await toggleEnabled.run(u)).ok) refresh();
482
481
  },
483
482
  },
484
483
  {
@@ -491,8 +490,7 @@ export const AdminUsers = (props: AdminUsersProps) => {
491
490
  _u: UserEntity,
492
491
  { refresh }: { refresh: () => void },
493
492
  ) => {
494
- await deleteUser.run(u);
495
- refresh();
493
+ if ((await deleteUser.run(u)).ok) refresh();
496
494
  },
497
495
  },
498
496
  ]