@coffre/ui 0.1.10 → 0.1.11

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 (167) hide show
  1. package/dist/client/_coffre/assets/account-BJAdDvZf.js +2 -0
  2. package/dist/client/_coffre/assets/account-D0jLpk5c.js +1 -0
  3. package/dist/client/_coffre/assets/affordances-Bq2-oUB5.js +1 -0
  4. package/dist/client/_coffre/assets/audit-C-pcBgKe.js +2 -0
  5. package/dist/client/_coffre/assets/audit-CHGlDeBB.js +1 -0
  6. package/dist/client/_coffre/assets/{auth.device-BP5FY0K1.js → auth.device-BndOUjse.js} +1 -1
  7. package/dist/client/_coffre/assets/auth.device-CWHNQn9W.js +2 -0
  8. package/dist/client/_coffre/assets/directory-nDExpkAz.js +1 -0
  9. package/dist/client/_coffre/assets/dist-QVHMLatb.js +1 -0
  10. package/dist/client/_coffre/assets/globals-CKBoTlyH.css +1 -0
  11. package/dist/client/_coffre/assets/grants-CjoOnxzz.js +1 -0
  12. package/dist/client/_coffre/assets/icons-BQ27Ds9u.js +1 -0
  13. package/dist/client/_coffre/assets/index-CUGytaO3.js +12 -0
  14. package/dist/client/_coffre/assets/link-DP8SVWon.js +1 -0
  15. package/dist/client/_coffre/assets/login-CeaxDMcr.js +2 -0
  16. package/dist/client/_coffre/assets/login-DrMgvqZn.js +1 -0
  17. package/dist/client/_coffre/assets/offboarding-CNr_1tnl.js +1 -0
  18. package/dist/client/_coffre/assets/page-CGmvjSy4.js +1 -0
  19. package/dist/client/_coffre/assets/preload-helper-ClBkJ19f.js +1 -0
  20. package/dist/client/_coffre/assets/principal-page-DNLb_q_e.js +1 -0
  21. package/dist/client/_coffre/assets/projects._project._environment-CHzbboGp.js +3 -0
  22. package/dist/client/_coffre/assets/projects._project._environment-DDxu_HHD.js +2 -0
  23. package/dist/client/_coffre/assets/projects._project.index-CIAsjvg6.js +2 -0
  24. package/dist/client/_coffre/assets/projects._project.index-DZ9l6d-1.js +1 -0
  25. package/dist/client/_coffre/assets/projects.index-4eUXreE_.js +1 -0
  26. package/dist/client/_coffre/assets/row-state-ByET1OKX.js +1 -0
  27. package/dist/client/_coffre/assets/settings-D2zp1Ssu.js +1 -0
  28. package/dist/client/_coffre/assets/suspense-C7KwSnTG.js +1 -0
  29. package/dist/client/_coffre/assets/tokens._token-DWmbqzNk.js +2 -0
  30. package/dist/client/_coffre/assets/tokens._token-Dui_4KfS.js +1 -0
  31. package/dist/client/_coffre/assets/tokens.index-CSi5Wxwf.js +1 -0
  32. package/dist/client/_coffre/assets/ui-BdipqGpP.js +46 -0
  33. package/dist/client/_coffre/assets/unregistered-CA7B4C1m.js +1 -0
  34. package/dist/client/_coffre/assets/use-action-DRm9yVhV.js +1 -0
  35. package/dist/client/_coffre/assets/use-change-BRRMJocl.js +1 -0
  36. package/dist/client/_coffre/assets/use-shell-BMGlJ25Q.js +1 -0
  37. package/dist/client/_coffre/assets/useQuery-D__2KBOs.js +1 -0
  38. package/dist/client/_coffre/assets/useSuspenseQuery-CSXyDALB.js +1 -0
  39. package/dist/client/_coffre/assets/users._user-BkNrX7Qf.js +1 -0
  40. package/dist/client/_coffre/assets/users._user-jbSvtdOg.js +2 -0
  41. package/dist/client/_coffre/assets/users.index-CKnQ1G76.js +1 -0
  42. package/dist/server/.vite/manifest.json +343 -246
  43. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-Dx-c3XVk.js +162 -0
  44. package/dist/server/_coffre/assets/{account-CUQYGCYh.js → account-BocTPU1J.js} +150 -117
  45. package/dist/server/_coffre/assets/{account-DMlUoBxQ.js → account-CL8hOGhO.js} +10 -24
  46. package/dist/server/_coffre/assets/{affordances-BNaXjMOb.js → affordances-CKANXDTG.js} +2 -22
  47. package/dist/server/_coffre/assets/{async-local-storage-C0cwgkEr.js → async-local-storage-C10uQtMM.js} +3 -2
  48. package/dist/server/_coffre/assets/{audit-CCdSLmvK.js → audit-Bcka4vA6.js} +46 -16
  49. package/dist/server/_coffre/assets/audit-CSRQYIhu.js +31 -0
  50. package/dist/server/_coffre/assets/{auth.device-C05u5ROO.js → auth.device-CMcUISZY.js} +7 -5
  51. package/dist/server/_coffre/assets/{auth.device-BoFM1jcf.js → auth.device-DqO0T-rU.js} +5 -5
  52. package/dist/server/_coffre/assets/{directory-GsnYkse0.js → directory-CyYx6Jx1.js} +87 -112
  53. package/dist/server/_coffre/assets/{use-action-DwEmf58L.js → dist-CnnV3t2g.js} +3 -48
  54. package/dist/server/_coffre/assets/globals-CKBoTlyH.css +1 -0
  55. package/dist/server/_coffre/assets/grants-CRijabX0.js +158 -0
  56. package/dist/server/_coffre/assets/{page-BdnhpwvH.js → icons-Dy-5ccDF.js} +3 -196
  57. package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +480 -0
  58. package/dist/server/_coffre/assets/link-42ZWdjzZ.js +422 -0
  59. package/dist/server/_coffre/assets/{login-DUtCQju5.js → login-BI9tzJEy.js} +7 -5
  60. package/dist/server/_coffre/assets/{login-B2njIq_o.js → login-C-v88YwP.js} +2 -2
  61. package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +56 -0
  62. package/dist/server/_coffre/assets/{offboarding-8yMa7ViM.js → offboarding-1H0LavTd.js} +6 -4
  63. package/dist/server/_coffre/assets/page-D_mO0-sn.js +3592 -0
  64. package/dist/server/_coffre/assets/{principal-page-B8zPcS2b.js → principal-page-DQDoXute.js} +51 -42
  65. package/dist/server/_coffre/assets/{projects._project._environment-BZ5Z80V8.js → projects._project._environment-C-yVwC92.js} +168 -248
  66. package/dist/server/_coffre/assets/{projects._project._environment-DdIOc7wx.js → projects._project._environment-D_5R40of.js} +4 -11
  67. package/dist/server/_coffre/assets/{projects._project.index-CuEAUwGn.js → projects._project.index-A2BImFIT.js} +134 -96
  68. package/dist/server/_coffre/assets/{projects._project.index-DvbcU1kh.js → projects._project.index-BPPKxKrt.js} +5 -4
  69. package/dist/server/_coffre/assets/{projects.index-5HI0wOuG.js → projects.index-543IsPzY.js} +57 -55
  70. package/dist/server/_coffre/assets/{react-dom-qCTiwGGR.js → react-dom-bBoJXlK2.js} +417 -51
  71. package/dist/server/_coffre/assets/{router-CQDoql8s.js → router-CM3vK8QO.js} +376 -92
  72. package/dist/server/_coffre/assets/row-state-XBtDoIA4.js +117 -0
  73. package/dist/server/_coffre/assets/{settings-BVz78wjP.js → settings-BLVU74ym.js} +8 -6
  74. package/dist/server/_coffre/assets/suspense-CzYTwxOj.js +602 -0
  75. package/dist/server/_coffre/assets/tokens._token-B-hBgwBW.js +10 -0
  76. package/dist/server/_coffre/assets/{tokens._token-CWs3Mtki.js → tokens._token-aubAUonP.js} +97 -79
  77. package/dist/server/_coffre/assets/{tokens.index-Ck0LN7aC.js → tokens.index-4D3jwp5v.js} +9 -6
  78. package/dist/server/_coffre/assets/{ui-D_slKpSF.js → ui-BI3Bf72q.js} +7 -836
  79. package/dist/server/_coffre/assets/{unregistered-Z17da4Rc.js → unregistered-CagDxMyw.js} +5 -3
  80. package/dist/server/_coffre/assets/use-action-tzBZvjjQ.js +47 -0
  81. package/dist/server/_coffre/assets/use-change-Dggqxy5y.js +1212 -0
  82. package/dist/server/_coffre/assets/use-shell-CwStDfzX.js +462 -0
  83. package/dist/server/_coffre/assets/useQuery-C6_dBjem.js +8 -0
  84. package/dist/server/_coffre/assets/{useStore-DWGPqzXR.js → useRouter-CaUSUNsw.js} +1 -420
  85. package/dist/server/_coffre/assets/useSuspenseQuery-BuapQt_P.js +117 -0
  86. package/dist/server/_coffre/assets/{users._user-CMwj-VI9.js → users._user-137WNyxn.js} +4 -5
  87. package/dist/server/_coffre/assets/users._user-C252Iilj.js +10 -0
  88. package/dist/server/_coffre/assets/{users.index-fWHv6A30.js → users.index-DQHsfnal.js} +9 -6
  89. package/dist/server/index.js +6 -5
  90. package/package.json +5 -3
  91. package/src/components/directory.tsx +75 -104
  92. package/src/components/grants.tsx +60 -112
  93. package/src/components/principal-page.tsx +54 -67
  94. package/src/components/principal-picker.tsx +7 -16
  95. package/src/components/row-state.tsx +95 -0
  96. package/src/components/service-tokens.tsx +75 -64
  97. package/src/components/shell.tsx +1 -1
  98. package/src/components/syncs.tsx +42 -26
  99. package/src/lib/announce.ts +36 -0
  100. package/src/lib/changes.ts +498 -0
  101. package/src/lib/optimistic.ts +233 -0
  102. package/src/lib/queries.ts +393 -0
  103. package/src/lib/use-action.ts +20 -15
  104. package/src/lib/use-change.ts +42 -0
  105. package/src/lib/use-shell.ts +17 -0
  106. package/src/router.tsx +17 -9
  107. package/src/routes/__root.tsx +8 -38
  108. package/src/routes/account.tsx +163 -154
  109. package/src/routes/audit.tsx +51 -72
  110. package/src/routes/auth.device.tsx +4 -2
  111. package/src/routes/login.tsx +3 -2
  112. package/src/routes/projects.$project.$environment.tsx +226 -231
  113. package/src/routes/projects.$project.index.tsx +136 -118
  114. package/src/routes/projects.index.tsx +117 -145
  115. package/src/routes/settings.tsx +7 -7
  116. package/src/routes/tokens.$token.tsx +14 -17
  117. package/src/routes/tokens.index.tsx +8 -4
  118. package/src/routes/unregistered.tsx +3 -2
  119. package/src/routes/users.$user.tsx +4 -4
  120. package/src/routes/users.index.tsx +8 -4
  121. package/src/styles/globals.css +78 -1
  122. package/dist/client/_coffre/assets/account-B48wuSF8.js +0 -1
  123. package/dist/client/_coffre/assets/account-BkNyIDT7.js +0 -2
  124. package/dist/client/_coffre/assets/affordances-CmoY-8Xf.js +0 -1
  125. package/dist/client/_coffre/assets/audit-BvwKYb-5.js +0 -2
  126. package/dist/client/_coffre/assets/audit-D02H-zxS.js +0 -1
  127. package/dist/client/_coffre/assets/auth.device-DYOONgFF.js +0 -2
  128. package/dist/client/_coffre/assets/coffre-BBp7cKVa.js +0 -1
  129. package/dist/client/_coffre/assets/directory-Bu0EIxqI.js +0 -1
  130. package/dist/client/_coffre/assets/globals-Bh2x1gBM.css +0 -1
  131. package/dist/client/_coffre/assets/grants-DavcwofW.js +0 -1
  132. package/dist/client/_coffre/assets/index-CDPlq5rM.js +0 -12
  133. package/dist/client/_coffre/assets/login-C-wTm_t1.js +0 -2
  134. package/dist/client/_coffre/assets/login-CLLv1om9.js +0 -1
  135. package/dist/client/_coffre/assets/offboarding-DWsE2FSa.js +0 -1
  136. package/dist/client/_coffre/assets/page-DbSS7pYH.js +0 -1
  137. package/dist/client/_coffre/assets/preload-helper-DduCCcmc.js +0 -46
  138. package/dist/client/_coffre/assets/principal-page-Bp_iwuSd.js +0 -1
  139. package/dist/client/_coffre/assets/projects._project._environment-BMeX_B8l.js +0 -2
  140. package/dist/client/_coffre/assets/projects._project._environment-CT0A-hIU.js +0 -3
  141. package/dist/client/_coffre/assets/projects._project.index-C_xYOGLT.js +0 -2
  142. package/dist/client/_coffre/assets/projects._project.index-Chcf-cUd.js +0 -1
  143. package/dist/client/_coffre/assets/projects.index-CfOtb1X5.js +0 -2
  144. package/dist/client/_coffre/assets/projects.index-DSjOhLDh.js +0 -1
  145. package/dist/client/_coffre/assets/settings-BC9cUJNK.js +0 -1
  146. package/dist/client/_coffre/assets/settings-Bkj_E21y.js +0 -2
  147. package/dist/client/_coffre/assets/tokens._token-BA0KqvaW.js +0 -1
  148. package/dist/client/_coffre/assets/tokens._token-Dh9jLOkm.js +0 -2
  149. package/dist/client/_coffre/assets/tokens.index-BgAMWkHT.js +0 -2
  150. package/dist/client/_coffre/assets/tokens.index-CHueIAv1.js +0 -1
  151. package/dist/client/_coffre/assets/unregistered-D5go1AfR.js +0 -1
  152. package/dist/client/_coffre/assets/use-action-l__xZDYY.js +0 -1
  153. package/dist/client/_coffre/assets/users._user-Dwqa0gv5.js +0 -1
  154. package/dist/client/_coffre/assets/users._user-xJAb3T6Y.js +0 -2
  155. package/dist/client/_coffre/assets/users.index-BJoF-L37.js +0 -2
  156. package/dist/client/_coffre/assets/users.index-YUjtbTGy.js +0 -1
  157. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-BKg2AlPu.js +0 -133
  158. package/dist/server/_coffre/assets/audit-CThXn2v7.js +0 -74
  159. package/dist/server/_coffre/assets/coffre-C2ANsTAz.js +0 -281
  160. package/dist/server/_coffre/assets/globals-Bh2x1gBM.css +0 -1
  161. package/dist/server/_coffre/assets/grants-B6k4Fu9z.js +0 -243
  162. package/dist/server/_coffre/assets/projects.index-uiomWX_l.js +0 -54
  163. package/dist/server/_coffre/assets/settings-4oRyDizv.js +0 -18
  164. package/dist/server/_coffre/assets/tokens._token-CF_deAwq.js +0 -18
  165. package/dist/server/_coffre/assets/tokens.index-DF_07KEe.js +0 -10
  166. package/dist/server/_coffre/assets/users._user-DUzwkSKT.js +0 -10
  167. package/dist/server/_coffre/assets/users.index-BbuweTwH.js +0 -10
@@ -1,8 +1,21 @@
1
1
  import { useEffect, useState, type ReactNode } from 'react';
2
- import { createFileRoute, Link, useLoaderData, useRouter } from '@tanstack/react-router';
2
+ import { useSuspenseQuery } from '@tanstack/react-query';
3
+ import { createFileRoute, Link, useRouter } from '@tanstack/react-router';
4
+ import { useShell } from '../lib/use-shell';
3
5
  import { DropdownMenu } from 'radix-ui';
4
6
  import { toast } from 'sonner';
5
- import { Refusal, useCoffre } from '../lib/coffre';
7
+ import { useCoffre } from '../lib/coffre';
8
+ import {
9
+ archiveEnvironment,
10
+ createEnvironment,
11
+ environmentId,
12
+ grantAccess,
13
+ grantId,
14
+ renameEnvironment,
15
+ } from '../lib/changes';
16
+ import { affects, keys, loadProject, projectOf, queries } from '../lib/queries';
17
+ import { useChange, useChangeStatus } from '../lib/use-change';
18
+ import { ItemFailure, RowPending, rowClass } from '../components/row-state';
6
19
  import { useAction } from '../lib/use-action';
7
20
  import type { GrantRow, ProjectSummary } from '../shared/models';
8
21
  import {
@@ -19,7 +32,7 @@ import {
19
32
  Spinner,
20
33
  } from '../components/ui';
21
34
  import { Card, ClosedDoor, PageHeader } from '../components/page';
22
- import { ensureGrant, GrantRowView, GrantsTable, loadProject } from '../components/grants';
35
+ import { GrantRowView, GrantsTable, RefusedGrants, useRefusedGrants } from '../components/grants';
23
36
  import { PrincipalLink } from '../components/principal';
24
37
  import { PrincipalPicker } from '../components/principal-picker';
25
38
  import {
@@ -51,7 +64,7 @@ export const Route = createFileRoute('/projects/$project/')({
51
64
  ? search.tab
52
65
  : undefined,
53
66
  }),
54
- loader: ({ context: { client }, params }) => loadProject(client, params.project),
67
+ loader: ({ context: { client, queryClient }, params }) => loadProject(queryClient, client, params.project),
55
68
  component: ProjectPage,
56
69
  });
57
70
 
@@ -63,9 +76,9 @@ const TABS: { key: ProjectTab; label: string; icon: ReactNode }[] = [
63
76
  ];
64
77
 
65
78
  function ProjectPage() {
66
- const result = Route.useLoaderData();
67
79
  const { project: projectSlug } = Route.useParams();
68
- const search = Route.useSearch();
80
+ const { data: projects } = useSuspenseQuery(queries.projects(useCoffre()));
81
+ const result = projectOf(projects, projectSlug);
69
82
 
70
83
  if (!result.ok) {
71
84
  return (
@@ -85,7 +98,33 @@ function ProjectPage() {
85
98
  );
86
99
  }
87
100
 
88
- const { project, grants, grantsError } = result;
101
+ return result.managesAccess ? (
102
+ <ManagedProject project={result.project} />
103
+ ) : (
104
+ <ProjectView project={result.project} grants={[]} grantsError={null} />
105
+ );
106
+ }
107
+
108
+ /** A project whose access you manage, with its grants. */
109
+ function ManagedProject({ project }: { project: ProjectSummary }) {
110
+ const { data: result } = useSuspenseQuery(queries.grants(useCoffre(), project.slug));
111
+ return result.ok ? (
112
+ <ProjectView project={project} grants={result.grants} grantsError={null} />
113
+ ) : (
114
+ <ProjectView project={project} grants={[]} grantsError={result.error} />
115
+ );
116
+ }
117
+
118
+ function ProjectView({
119
+ project,
120
+ grants,
121
+ grantsError,
122
+ }: {
123
+ project: ProjectSummary;
124
+ grants: GrantRow[];
125
+ grantsError: string | null;
126
+ }) {
127
+ const search = Route.useSearch();
89
128
 
90
129
  // Each tab is gated on its own permission, not on one blanket "admin".
91
130
  // That is what lets an access manager administer grants without being able
@@ -194,10 +233,14 @@ function EnvironmentsPanel({
194
233
  const current = project.environments.filter(
195
234
  (environment) => environment.details === null || environment.details.archivedAt === null,
196
235
  );
236
+ const { failedAdds, dismiss } = useChangeStatus(keys.projects);
237
+ const refused = failedAdds<{ slug: string; name: string }>(
238
+ project.environments.map((environment) => environmentId(project.slug, environment.slug)),
239
+ ).filter(({ ids }) => ids.every((id) => id.startsWith(`${project.slug}/`)));
197
240
 
198
241
  return (
199
242
  <>
200
- {current.length === 0 ? (
243
+ {current.length === 0 && refused.length === 0 ? (
201
244
  <div className="card">
202
245
  <EmptyState title="No environments yet">
203
246
  {canManage
@@ -216,6 +259,21 @@ function EnvironmentsPanel({
216
259
  />
217
260
  </li>
218
261
  ))}
262
+ {refused.map(({ mutationId, vars, status }) => (
263
+ <li key={mutationId}>
264
+ <div className="env-card is-muted is-failed">
265
+ <div className="env-card-text">
266
+ <span className="env-card-name">{vars.name}</span>
267
+ <span className="env-card-meta">
268
+ <span className="mono">{vars.slug}</span>
269
+ </span>
270
+ </div>
271
+ <ItemFailure status={status} onDismiss={() => dismiss(mutationId)}>
272
+ Not added.
273
+ </ItemFailure>
274
+ </div>
275
+ </li>
276
+ ))}
219
277
  </ul>
220
278
  )}
221
279
 
@@ -259,20 +317,20 @@ function EnvironmentCard({
259
317
  const [slug, setSlug] = useState(environment.slug);
260
318
  const [name, setName] = useState(environment.name);
261
319
  const coffre = useCoffre();
262
- const { pending, error, setError, run } = useAction();
320
+ const rename = useChange(renameEnvironment(coffre, project));
321
+ const archive = useChange(archiveEnvironment(coffre, project));
322
+ const { status, dismiss } = useChangeStatus(keys.projects);
323
+ const state = status(environmentId(project, environment.slug));
324
+ const pending = state.state === 'pending';
263
325
  const details = environment.details;
264
326
  const isArchived = details !== null && details.archivedAt !== null;
265
327
  const secretCount = details?.secretCount ?? null;
266
- const opens = details !== null && !isArchived && environment.accessible;
328
+ const opens = details !== null && !isArchived && environment.accessible && !pending;
267
329
  const manageable = isAdmin && details !== null;
268
330
  const slugError = slug === '' ? null : slugProblem(slug);
269
331
 
270
- useEffect(() => {
271
- if (error !== null && !renaming) toast.error(error);
272
- }, [error, renaming]);
273
-
274
332
  return (
275
- <div className={`env-card${opens ? ' is-link' : ' is-muted'}`}>
333
+ <div className={`env-card${opens ? ' is-link' : ' is-muted'} ${rowClass(state)}`}>
276
334
  <div className="env-card-text">
277
335
  {opens ? (
278
336
  <Link
@@ -289,7 +347,7 @@ function EnvironmentCard({
289
347
  <span className="mono">{environment.slug}</span>
290
348
  {isArchived ? (
291
349
  <span className="tag tag-red">archived</span>
292
- ) : !environment.accessible ? (
350
+ ) : !environment.accessible && !pending ? (
293
351
  <span className="tag tag-outline">no secret access</span>
294
352
  ) : (
295
353
  secretCount !== null && (
@@ -301,15 +359,16 @@ function EnvironmentCard({
301
359
  </span>
302
360
  </div>
303
361
 
304
- {manageable && (
362
+ {pending && <RowPending status={state} />}
363
+
364
+ {manageable && !pending && (
305
365
  <DropdownMenu.Root>
306
366
  <DropdownMenu.Trigger asChild>
307
367
  <button
308
368
  className="act act-quiet env-card-menu"
309
369
  aria-label={`Actions for ${environment.slug}`}
310
- disabled={pending}
311
370
  >
312
- {pending ? <Spinner size={14} /> : <MoreHorizontal size={16} />}
371
+ <MoreHorizontal size={16} />
313
372
  </button>
314
373
  </DropdownMenu.Trigger>
315
374
  <DropdownMenu.Portal>
@@ -342,10 +401,7 @@ function EnvironmentCard({
342
401
  <>
343
402
  <Modal
344
403
  open={renaming}
345
- onOpenChange={(open) => {
346
- setRenaming(open);
347
- if (!open) setError(null);
348
- }}
404
+ onOpenChange={setRenaming}
349
405
  title={
350
406
  <>
351
407
  Rename{' '}
@@ -359,14 +415,9 @@ function EnvironmentCard({
359
415
  className="form"
360
416
  onSubmit={(event) => {
361
417
  event.preventDefault();
362
- run(
363
- () =>
364
- coffre.environments.update(`${project}/${environment.slug}`, { slug, name }),
365
- () => {
366
- setRenaming(false);
367
- toast.success('Environment renamed');
368
- },
369
- );
418
+ // Shown on the card at once; the card says if the server refuses.
419
+ rename({ from: environment.slug, slug, name: name.trim() });
420
+ setRenaming(false);
370
421
  }}
371
422
  >
372
423
  <label className="field">
@@ -393,8 +444,6 @@ function EnvironmentCard({
393
444
  />
394
445
  </label>
395
446
 
396
- <ErrorLine error={error} />
397
-
398
447
  <div className="dialog-actions">
399
448
  <button className="btn" type="button" onClick={() => setRenaming(false)}>
400
449
  Cancel
@@ -402,9 +451,8 @@ function EnvironmentCard({
402
451
  <button
403
452
  className="btn btn-primary"
404
453
  type="submit"
405
- disabled={pending || slug === '' || slugError !== null || name.trim() === ''}
454
+ disabled={slug === '' || slugError !== null || name.trim() === ''}
406
455
  >
407
- {pending && <Spinner />}
408
456
  Save
409
457
  </button>
410
458
  </div>
@@ -448,19 +496,15 @@ function EnvironmentCard({
448
496
  }
449
497
  confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
450
498
  destructive={!isArchived}
451
- onConfirm={() =>
452
- run(
453
- () =>
454
- coffre.environments.update(`${project}/${environment.slug}`, { archived: !isArchived }),
455
- () =>
456
- toast.success(
457
- isArchived ? `${environment.slug} restored` : `${environment.slug} archived`,
458
- ),
459
- )
460
- }
499
+ onConfirm={() => archive({ slug: environment.slug, archived: !isArchived })}
461
500
  />
462
501
  </>
463
502
  )}
503
+
504
+ <ItemFailure
505
+ status={state}
506
+ onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
507
+ />
464
508
  </div>
465
509
  );
466
510
  }
@@ -469,13 +513,11 @@ function NewEnvironment({ project }: { project: string }) {
469
513
  const [open, setOpen] = useState(false);
470
514
  const [slug, setSlug] = useState('');
471
515
  const [name, setName] = useState('');
472
- const coffre = useCoffre();
473
- const { pending, error, setError, run } = useAction();
516
+ const create = useChange(createEnvironment(useCoffre(), project));
474
517
  const slugError = slug === '' ? null : slugProblem(slug);
475
518
 
476
519
  function close() {
477
520
  setOpen(false);
478
- setError(null);
479
521
  }
480
522
 
481
523
  return (
@@ -498,18 +540,11 @@ function NewEnvironment({ project }: { project: string }) {
498
540
  className="form"
499
541
  onSubmit={(event) => {
500
542
  event.preventDefault();
501
- run(
502
- async () => {
503
- const { created } = await coffre.environments.create(`${project}/${slug}`, { name });
504
- if (!created) throw new Refusal(`An environment named "${slug}" already exists.`);
505
- },
506
- () => {
507
- toast.success(`Environment ${slug} added`);
508
- setSlug('');
509
- setName('');
510
- close();
511
- },
512
- );
543
+ // Listed at once, as saving; the list says if the server refuses.
544
+ create({ slug, name: name.trim() });
545
+ setSlug('');
546
+ setName('');
547
+ close();
513
548
  }}
514
549
  >
515
550
  <label className="field">
@@ -546,8 +581,6 @@ function NewEnvironment({ project }: { project: string }) {
546
581
  />
547
582
  </label>
548
583
 
549
- <ErrorLine error={error} />
550
-
551
584
  <div className="dialog-actions">
552
585
  <button className="btn" type="button" onClick={close}>
553
586
  Cancel
@@ -555,9 +588,8 @@ function NewEnvironment({ project }: { project: string }) {
555
588
  <button
556
589
  className="btn btn-primary"
557
590
  type="submit"
558
- disabled={pending || slug === '' || slugError !== null || name.trim() === ''}
591
+ disabled={slug === '' || slugError !== null || name.trim() === ''}
559
592
  >
560
- {pending && <Spinner />}
561
593
  Add environment
562
594
  </button>
563
595
  </div>
@@ -577,9 +609,10 @@ function AccessPanel({
577
609
  grants: GrantRow[];
578
610
  }) {
579
611
  const people = principalType === 'user';
612
+ const refused = useRefusedGrants(project, grants, principalType);
580
613
  return (
581
614
  <section className="card" aria-label={people ? 'Users with access' : 'Tokens with access'}>
582
- {grants.length === 0 ? (
615
+ {grants.length === 0 && refused.length === 0 ? (
583
616
  <EmptyState title={people ? 'No user has access' : 'No token has access'}>
584
617
  Add {people ? 'a user' : 'a token'} with permissions on the whole project or on one
585
618
  environment.
@@ -595,7 +628,7 @@ function AccessPanel({
595
628
  >
596
629
  {grants.map((grant, index) => (
597
630
  <GrantRowView
598
- key={grant.id}
631
+ key={grantId(grant)}
599
632
  number={index + 1}
600
633
  project={project}
601
634
  grant={grant}
@@ -603,6 +636,7 @@ function AccessPanel({
603
636
  lead={<PrincipalLink type={grant.principalType} id={grant.principalId} />}
604
637
  />
605
638
  ))}
639
+ <RefusedGrants refused={refused} />
606
640
  </GrantsTable>
607
641
  )}
608
642
  </section>
@@ -620,19 +654,17 @@ function NewGrant({
620
654
  environments: ProjectSummary['environments'];
621
655
  grants: GrantRow[];
622
656
  }) {
623
- const { capabilities } = useLoaderData({ from: '__root__' });
657
+ const { capabilities } = useShell();
624
658
  const [open, setOpen] = useState(false);
625
659
  const [principalId, setPrincipalId] = useState('');
626
660
  const [permission, setPermission] = useState('viewer:');
627
661
  const [expiresAt, setExpiresAt] = useState('');
628
- const coffre = useCoffre();
629
- const { pending, error, setError, run } = useAction();
662
+ const grant = useChange(grantAccess(useCoffre(), project));
630
663
  const permissionOptions = projectAccessOptions(environments);
631
664
  const kind = principalType === 'user' ? 'user' : 'token';
632
665
 
633
666
  function close() {
634
667
  setOpen(false);
635
- setError(null);
636
668
  }
637
669
 
638
670
  return (
@@ -658,32 +690,19 @@ function NewGrant({
658
690
  onSubmit={(event) => {
659
691
  event.preventDefault();
660
692
  const access = parseProjectAccess(permission);
661
- run(
662
- () =>
663
- ensureGrant(coffre, {
664
- project,
665
- principalType,
666
- principalId: principalId.trim(),
667
- role: access.role,
668
- environmentSlug: access.environmentSlug,
669
- expiresAt:
670
- expiresAt === '' ? null : new Date(`${expiresAt}T23:59:59Z`).toISOString(),
671
- }),
672
- ({ existed }) => {
673
- const label =
674
- permissionOptions.find((option) => option.value === permission)?.label ??
675
- 'access';
676
- toast.success(
677
- existed
678
- ? `${principalId} already has ${label}`
679
- : `${principalId} granted ${label.toLowerCase()}`,
680
- );
681
- setPrincipalId('');
682
- setExpiresAt('');
683
- setPermission('viewer:');
684
- close();
685
- },
686
- );
693
+ // Shown in the list at once, marked as saving; the list says if the server refuses.
694
+ grant({
695
+ principalType,
696
+ principalId: principalId.trim(),
697
+ role: access.role,
698
+ roleName: permissionOptions.find((option) => option.value === permission)?.label ?? access.role,
699
+ environmentSlug: access.environmentSlug,
700
+ expiresAt: expiresAt === '' ? null : new Date(`${expiresAt}T23:59:59Z`).toISOString(),
701
+ });
702
+ setPrincipalId('');
703
+ setExpiresAt('');
704
+ setPermission('viewer:');
705
+ close();
687
706
  }}
688
707
  >
689
708
  <PrincipalPicker
@@ -723,18 +742,11 @@ function NewGrant({
723
742
  </label>
724
743
  </div>
725
744
 
726
- <ErrorLine error={error} />
727
-
728
745
  <div className="dialog-actions">
729
746
  <button className="btn" type="button" onClick={close}>
730
747
  Cancel
731
748
  </button>
732
- <button
733
- className="btn btn-primary"
734
- type="submit"
735
- disabled={pending || principalId.trim() === ''}
736
- >
737
- {pending && <Spinner />}
749
+ <button className="btn btn-primary" type="submit" disabled={principalId.trim() === ''}>
738
750
  Grant access
739
751
  </button>
740
752
  </div>
@@ -781,16 +793,19 @@ function GeneralSettings({ project }: { project: ProjectSummary }) {
781
793
  event.preventDefault();
782
794
  run(
783
795
  () => coffre.projects.update(project.slug, { slug, name }),
784
- async () => {
785
- toast.success('Project renamed');
786
- // The slug is part of the URL, so a rename has to navigate.
787
- if (slug !== project.slug) {
788
- await router.navigate({
789
- to: '/projects/$project',
790
- params: { project: slug },
791
- search: { tab: 'settings' },
792
- });
793
- }
796
+ {
797
+ affects: affects.places(),
798
+ onSuccess: async () => {
799
+ toast.success('Project renamed');
800
+ // The slug is part of the URL, so a rename has to navigate.
801
+ if (slug !== project.slug) {
802
+ await router.navigate({
803
+ to: '/projects/$project',
804
+ params: { project: slug },
805
+ search: { tab: 'settings' },
806
+ });
807
+ }
808
+ },
794
809
  },
795
810
  );
796
811
  }}
@@ -905,10 +920,13 @@ function DangerZone({ project }: { project: ProjectSummary }) {
905
920
  run(
906
921
  () =>
907
922
  coffre.projects.update(project.slug, { archived: !isArchived }),
908
- () =>
909
- toast.success(
910
- isArchived ? `${project.slug} restored` : `${project.slug} archived`,
911
- ),
923
+ {
924
+ affects: affects.places(),
925
+ onSuccess: () =>
926
+ toast.success(
927
+ isArchived ? `${project.slug} restored` : `${project.slug} archived`,
928
+ ),
929
+ },
912
930
  )
913
931
  }
914
932
  />