@milesroxas/design-hub 0.12.0 → 0.14.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 +5 -5
- package/core/prototype.test.ts +12 -1
- package/core/prototype.ts +21 -2
- package/core/review/model.ts +71 -6
- package/core/review/service.test.ts +575 -39
- package/core/review/service.ts +452 -25
- package/core/review/store.ts +47 -6
- package/core/review/suite-kv.ts +17 -0
- package/dist/core/prototype.d.ts +20 -2
- package/dist/core/prototype.js +17 -2
- package/dist/core/review/model.d.ts +42 -3
- package/dist/core/review/model.js +52 -3
- package/dist/core/review/service.d.ts +81 -7
- package/dist/core/review/service.js +407 -23
- package/dist/core/review/store.d.ts +29 -2
- package/dist/core/review/store.js +6 -2
- package/dist/core/review/suite-kv.d.ts +7 -0
- package/dist/core/review/suite-kv.js +12 -0
- package/dist/scripts/client.d.ts +1 -1
- package/dist/scripts/client.js +4 -4
- package/dist/scripts/lib/cli.js +5 -0
- package/dist/scripts/lib/dns.d.ts +16 -2
- package/dist/scripts/lib/dns.js +66 -3
- package/dist/scripts/lib/fake-host.d.ts +17 -3
- package/dist/scripts/lib/fake-host.js +56 -10
- package/dist/scripts/lib/host.d.ts +15 -25
- package/dist/scripts/lib/host.js +15 -324
- package/dist/scripts/lib/resend.d.ts +36 -0
- package/dist/scripts/lib/resend.js +66 -0
- package/dist/scripts/lib/studio-deps.d.ts +23 -0
- package/dist/scripts/lib/studio-deps.js +46 -16
- package/dist/scripts/lib/studios.d.ts +16 -6
- package/dist/scripts/lib/studios.js +28 -10
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +416 -0
- package/dist/scripts/people.d.ts +16 -4
- package/dist/scripts/people.js +67 -17
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +26 -4
- package/dist/scripts/studio.js +364 -19
- package/dist/server/api.d.ts +20 -7
- package/dist/server/api.js +83 -27
- package/dist/server/dev.js +21 -1
- package/dist/server/gate.d.ts +120 -0
- package/dist/server/gate.js +808 -0
- package/dist/server/mailer.d.ts +60 -0
- package/dist/server/mailer.js +104 -0
- package/dist/server/mailers/fake.d.ts +8 -0
- package/dist/server/mailers/fake.js +16 -0
- package/dist/server/mailers/resend.d.ts +21 -0
- package/dist/server/mailers/resend.js +49 -0
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +2 -1
- package/dist/server/session.js +6 -3
- package/dist/server/stores/backends.d.ts +22 -0
- package/dist/server/stores/backends.js +96 -0
- package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
- package/dist/server/stores/index.d.ts +41 -0
- package/dist/server/stores/index.js +63 -0
- package/dist/server/stores/pglite.d.ts +16 -0
- package/dist/server/stores/pglite.js +98 -0
- package/dist/server/stores/postgres.d.ts +63 -0
- package/dist/server/stores/postgres.js +153 -0
- package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
- package/dist/vercel/files.js +1 -1
- package/dist/vercel/proxy.d.ts +6 -82
- package/dist/vercel/proxy.js +24 -524
- package/dist/vite/plugin.js +4 -2
- package/kit/ui/Menu.tsx +29 -18
- package/kit/ui/layer.ts +41 -0
- package/package.json +3 -1
- package/shell/review/Bar.tsx +1 -0
- package/shell/review/Card.tsx +17 -7
- package/shell/review/People.tsx +908 -134
- package/shell/review/Review.tsx +2 -2
- package/shell/review/anchor.ts +6 -1
- package/shell/review/client.ts +41 -7
- package/shell/review/menu-place.test.ts +41 -0
- package/shell/review/place.test.ts +26 -1
- package/shell/review/place.ts +17 -0
- package/shell/review/review.css +97 -11
- package/shell/review/view.test.ts +115 -1
- package/shell/review/view.ts +92 -2
- package/shell/studio/StudioHub.tsx +1 -0
- package/shell/studio/hub.css +99 -13
- package/skills/miles-deploy/SKILL.md +26 -4
- package/templates/studio/.env.example +9 -0
- package/templates/studio/README.md +13 -0
- package/templates/studio/package.json +1 -1
- /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
- /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
package/shell/review/People.tsx
CHANGED
|
@@ -1,15 +1,43 @@
|
|
|
1
|
-
// The People card, for Studio:
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// out everywhere, a
|
|
1
|
+
// The People card, for Studio: who can comment, and until when. The list
|
|
2
|
+
// leads; adding someone waits behind one Add person button, and a row's
|
|
3
|
+
// actions behind its one trailing menu (a new link, their address, access,
|
|
4
|
+
// sign out everywhere, Revoke). Whatever a row opens (an editor, a question,
|
|
5
|
+
// a new link) opens inside the row, and the row's menu steps aside meanwhile,
|
|
6
|
+
// so a row never shows two groups of controls at once. When the studio sends
|
|
7
|
+
// mail, an add with an address mails the person their link, once Studio has
|
|
8
|
+
// seen the address again (a typo would hand a working link to a stranger).
|
|
5
9
|
import { fmtDate } from '@kit/format';
|
|
6
|
-
import { Button, Select } from '@kit/ui';
|
|
7
|
-
import {
|
|
10
|
+
import { Badge, Button, Checkbox, Chevron, type MenuEntry, Select, useMenu } from '@kit/ui';
|
|
11
|
+
import {
|
|
12
|
+
createContext,
|
|
13
|
+
type FormEvent,
|
|
14
|
+
type KeyboardEvent,
|
|
15
|
+
type MouseEvent,
|
|
16
|
+
type ReactNode,
|
|
17
|
+
type Ref,
|
|
18
|
+
useContext,
|
|
19
|
+
useEffect,
|
|
20
|
+
useId,
|
|
21
|
+
useRef,
|
|
22
|
+
useState,
|
|
23
|
+
} from 'react';
|
|
8
24
|
import { type Access, LIMITS, LINK_DAYS, type PersonKind } from '../../core/review/model';
|
|
9
25
|
import { Action } from './Card';
|
|
10
|
-
import { act, type Me, type ReviewStore } from './client';
|
|
26
|
+
import { act, type Mailed, type MailState, type Me, type ReviewStore } from './client';
|
|
27
|
+
import {
|
|
28
|
+
checkSettled,
|
|
29
|
+
type Failure,
|
|
30
|
+
formFailure,
|
|
31
|
+
groupPeople,
|
|
32
|
+
menuActions,
|
|
33
|
+
openAfterAdd,
|
|
34
|
+
type RowAction,
|
|
35
|
+
shownOf,
|
|
36
|
+
stateBadge,
|
|
37
|
+
} from './view';
|
|
11
38
|
|
|
12
|
-
|
|
39
|
+
/** A link to hand over, and, for a new person, what became of their invite and which group they joined. */
|
|
40
|
+
type Link = { name: string; href: string; mailed?: Mailed; kind?: PersonKind };
|
|
13
41
|
|
|
14
42
|
const KIND_NAMES: Record<PersonKind, string> = { studio: 'Studio', client: 'Client' };
|
|
15
43
|
|
|
@@ -41,7 +69,89 @@ function accessOptions(kind: PersonKind, clientDefault: Access | null) {
|
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
/** The People ops the card calls: the review store's, wherever it runs. */
|
|
44
|
-
type PeopleStore = Pick<
|
|
72
|
+
type PeopleStore = Pick<
|
|
73
|
+
ReviewStore,
|
|
74
|
+
'addPerson' | 'newLink' | 'signOut' | 'setAccess' | 'setEmail' | 'revoke' | 'clearError'
|
|
75
|
+
>;
|
|
76
|
+
|
|
77
|
+
/** What an email field leaves empty: links only. */
|
|
78
|
+
const emailValue = (f: FormData) => String(f.get('email') ?? '').trim() || null;
|
|
79
|
+
|
|
80
|
+
type Shown = { text: string; field: string | null };
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A form's failure, kept beside the form that met it (formFailure) and taken
|
|
84
|
+
* out of the panel's own error slot, so it is said once, where it was typed.
|
|
85
|
+
* Editing the form again clears it.
|
|
86
|
+
*/
|
|
87
|
+
function useFailure(store: PeopleStore) {
|
|
88
|
+
const [failure, setFailure] = useState<Shown | null>(null);
|
|
89
|
+
/** Shows a form's failure beside the form; false when it is not the form's to show. */
|
|
90
|
+
const caught = (error: unknown) => {
|
|
91
|
+
const shown = formFailure(error as Failure);
|
|
92
|
+
if (!shown) return false;
|
|
93
|
+
setFailure(shown);
|
|
94
|
+
store.clearError();
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
return { failure, caught, clear: () => setFailure(null) };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A form's failure, read out as it appears. */
|
|
101
|
+
function FormError({ id, text }: { id: string; text: string }) {
|
|
102
|
+
return (
|
|
103
|
+
<p id={id} className="rv-form-error" role="alert">
|
|
104
|
+
{text}
|
|
105
|
+
</p>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* An email field: its label, the input, and what goes under it (a hint, or
|
|
111
|
+
* the refusal that names this field), so a refusal sits under its own field
|
|
112
|
+
* at every width. Studio types someone else's address, so the browser's own
|
|
113
|
+
* autofill and a password manager's are kept out of it.
|
|
114
|
+
*/
|
|
115
|
+
function EmailField({
|
|
116
|
+
label,
|
|
117
|
+
defaultValue,
|
|
118
|
+
inputRef,
|
|
119
|
+
below,
|
|
120
|
+
belowId,
|
|
121
|
+
invalid,
|
|
122
|
+
}: {
|
|
123
|
+
label: ReactNode;
|
|
124
|
+
defaultValue?: string;
|
|
125
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
126
|
+
below?: ReactNode;
|
|
127
|
+
belowId?: string;
|
|
128
|
+
invalid?: boolean;
|
|
129
|
+
}) {
|
|
130
|
+
const id = useId();
|
|
131
|
+
return (
|
|
132
|
+
<div className="field">
|
|
133
|
+
<label className="field-label" htmlFor={id}>
|
|
134
|
+
{label}
|
|
135
|
+
</label>
|
|
136
|
+
<input
|
|
137
|
+
id={id}
|
|
138
|
+
ref={inputRef}
|
|
139
|
+
className="input"
|
|
140
|
+
aria-describedby={below ? belowId : undefined}
|
|
141
|
+
aria-invalid={invalid || undefined}
|
|
142
|
+
type="email"
|
|
143
|
+
name="email"
|
|
144
|
+
maxLength={254}
|
|
145
|
+
defaultValue={defaultValue}
|
|
146
|
+
autoComplete="off"
|
|
147
|
+
spellCheck={false}
|
|
148
|
+
data-1p-ignore=""
|
|
149
|
+
data-lpignore="true"
|
|
150
|
+
/>
|
|
151
|
+
{below}
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
45
155
|
|
|
46
156
|
/** Who the form adds: a choice of kind, or the one kind a section holds (`only`), with no choice shown. */
|
|
47
157
|
function KindField({ kind, onKind }: { kind: PersonKind; onKind: (k: PersonKind) => void }) {
|
|
@@ -63,73 +173,442 @@ function KindField({ kind, onKind }: { kind: PersonKind; onKind: (k: PersonKind)
|
|
|
63
173
|
);
|
|
64
174
|
}
|
|
65
175
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
176
|
+
/** Escape steps back out of a form or what a row opened, unless a menu inside it owns the key. */
|
|
177
|
+
function escapeTo(back: () => void) {
|
|
178
|
+
return (e: KeyboardEvent<HTMLElement>) => {
|
|
179
|
+
if (e.key !== 'Escape' || e.defaultPrevented || document.querySelector('.menu.is-open')) return;
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
back();
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Whether an add here can mail an invite: the studio sends mail, and this
|
|
188
|
+
* place mails this kind. The review panel is on a client's host, which mails
|
|
189
|
+
* its Client people only: a Studio person signs in by email on the studio's
|
|
190
|
+
* own host, so the studio hub (`only` set) mails them.
|
|
191
|
+
*/
|
|
192
|
+
const mailsHere = (mail: MailState | null, kind: PersonKind, only?: PersonKind) =>
|
|
193
|
+
(mail === 'on' || mail === 'failing') && (only !== undefined || kind === 'client');
|
|
194
|
+
|
|
195
|
+
/** What the form holds while its address is checked: kept, so Back returns to it as it was. */
|
|
196
|
+
type Draft = { name: string; email: string };
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Before an invite goes, the address shown back: Send link adds the person
|
|
200
|
+
* and mails them; Back returns to the form to change it, Escape closes the
|
|
201
|
+
* check onto Create link. Focus moves to the question, so a held Enter cannot
|
|
202
|
+
* send it; Send link is the next Tab. A pointer press in the first moments
|
|
203
|
+
* is ignored (checkSettled): it is the second half of a double press on
|
|
204
|
+
* Create link, which this opened under. While it sends, nothing goes back.
|
|
205
|
+
*/
|
|
206
|
+
function AddressCheck({
|
|
207
|
+
email,
|
|
208
|
+
busy,
|
|
209
|
+
onSend,
|
|
210
|
+
onBack,
|
|
211
|
+
onEscape,
|
|
71
212
|
}: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
213
|
+
email: string;
|
|
214
|
+
busy: boolean;
|
|
215
|
+
onSend: () => void;
|
|
216
|
+
onBack: () => void;
|
|
217
|
+
onEscape: () => void;
|
|
76
218
|
}) {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
219
|
+
const box = useRef<HTMLFieldSetElement>(null);
|
|
220
|
+
const [opened] = useState(() => performance.now());
|
|
221
|
+
const question = useId();
|
|
222
|
+
const address = useId();
|
|
223
|
+
useEffect(() => box.current?.focus(), []);
|
|
224
|
+
// A keyboard press has detail 0: it reached Send link by Tab, after the check opened.
|
|
225
|
+
const send = (e: MouseEvent<HTMLButtonElement>) => {
|
|
226
|
+
if (e.detail > 0 && !checkSettled(opened, e.timeStamp)) return;
|
|
227
|
+
onSend();
|
|
228
|
+
};
|
|
229
|
+
return (
|
|
230
|
+
<fieldset
|
|
231
|
+
ref={box}
|
|
232
|
+
className="rv-invite rv-check"
|
|
233
|
+
aria-labelledby={question}
|
|
234
|
+
aria-describedby={address}
|
|
235
|
+
tabIndex={-1}
|
|
236
|
+
onKeyDown={escapeTo(() => {
|
|
237
|
+
if (!busy) onEscape();
|
|
238
|
+
})}
|
|
239
|
+
>
|
|
240
|
+
<div className="rv-check-text">
|
|
241
|
+
<p id={question} className="rv-check-question">
|
|
242
|
+
Send to this address?
|
|
243
|
+
</p>
|
|
244
|
+
<p id={address} className="rv-check-address">
|
|
245
|
+
{email}
|
|
246
|
+
</p>
|
|
247
|
+
</div>
|
|
248
|
+
<div className="rv-row rv-form-actions">
|
|
249
|
+
<Button kind="primary" size={null} label="Send link" busy={busy} onClick={send} />
|
|
250
|
+
<Button
|
|
251
|
+
kind="tertiary"
|
|
252
|
+
size={null}
|
|
253
|
+
className="rv-act"
|
|
254
|
+
label="Back"
|
|
255
|
+
disabled={busy}
|
|
256
|
+
onClick={onBack}
|
|
257
|
+
/>
|
|
258
|
+
</div>
|
|
259
|
+
</fieldset>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** What the form holds as typed: its name and address, the address empty for links only. */
|
|
264
|
+
const draftOf = (f: FormData): Draft => ({ name: String(f.get('name') ?? ''), email: emailValue(f) ?? '' });
|
|
265
|
+
|
|
266
|
+
/** Who a new person is, besides their name and address: their kind, and their access (null takes the default). */
|
|
267
|
+
type Choice = { kind: PersonKind; access: Access | null };
|
|
268
|
+
|
|
269
|
+
/** Where focus goes when the form shows again: the address, to change it, or Create link, which opened the check. */
|
|
270
|
+
type FocusTo = { to: 'address' | 'create' };
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The add's sending half: the values kept while the address is checked, the
|
|
274
|
+
* add itself (busy, so a second press is ignored), and its failure, which
|
|
275
|
+
* shows the form with focus on the address and the whole field, its refusal
|
|
276
|
+
* under it, scrolled into view.
|
|
277
|
+
*/
|
|
278
|
+
function useAdd(store: PeopleStore, onLink: (link: Link) => void) {
|
|
279
|
+
const [draft, setDraft] = useState<Draft | null>(null);
|
|
280
|
+
const [checking, setChecking] = useState(false);
|
|
81
281
|
const [busy, setBusy] = useState(false);
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
282
|
+
const [focus, setFocus] = useState<FocusTo | null>(null);
|
|
283
|
+
const failed = useFailure(store);
|
|
284
|
+
const email = useRef<HTMLInputElement>(null);
|
|
285
|
+
const create = useRef<HTMLButtonElement>(null);
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
if (focus?.to === 'create') return create.current?.focus();
|
|
288
|
+
if (!focus) return;
|
|
289
|
+
email.current?.focus({ preventScroll: true });
|
|
290
|
+
email.current?.closest('.field')?.scrollIntoView({ block: 'nearest' });
|
|
291
|
+
}, [focus]);
|
|
292
|
+
// A new object each time, so the same target twice still moves focus.
|
|
293
|
+
const toForm = (to: FocusTo['to']) => {
|
|
294
|
+
setChecking(false);
|
|
295
|
+
setFocus({ to });
|
|
296
|
+
};
|
|
297
|
+
const send = (d: Draft, choice: Choice, mailIt: boolean) => {
|
|
298
|
+
// A second press while the add is out would send it twice: a busy button is not a disabled one.
|
|
299
|
+
if (busy) return;
|
|
88
300
|
setBusy(true);
|
|
301
|
+
failed.clear();
|
|
89
302
|
act(
|
|
90
303
|
store
|
|
91
|
-
.addPerson(name, kind, access
|
|
92
|
-
.then((href) => {
|
|
93
|
-
|
|
94
|
-
form.reset();
|
|
95
|
-
})
|
|
304
|
+
.addPerson(d.name, choice.kind, choice.access, d.email || null, mailIt)
|
|
305
|
+
.then(({ href, mailed }) => onLink({ name: d.name, href, mailed, kind: choice.kind }))
|
|
306
|
+
.catch((error: unknown) => toForm(failed.caught(error) ? 'address' : 'create'))
|
|
96
307
|
.finally(() => setBusy(false)),
|
|
97
308
|
);
|
|
98
309
|
};
|
|
310
|
+
/** Keeps what was typed; with `check`, shows the address back before anything is sent. */
|
|
311
|
+
const keep = (d: Draft, check: boolean) => {
|
|
312
|
+
setDraft(d);
|
|
313
|
+
setChecking(check);
|
|
314
|
+
};
|
|
315
|
+
return { draft, checking, busy, failed, email, create, toForm, send, keep };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* The form's fields and buttons: the name (focused when the form first
|
|
320
|
+
* opens), the address with its refusal under it, Options, and Create link.
|
|
321
|
+
*/
|
|
322
|
+
function AddFields({
|
|
323
|
+
draft,
|
|
324
|
+
emailRef,
|
|
325
|
+
createRef,
|
|
326
|
+
failure,
|
|
327
|
+
onClear,
|
|
328
|
+
busy,
|
|
329
|
+
options,
|
|
330
|
+
onSubmit,
|
|
331
|
+
onCancel,
|
|
332
|
+
}: {
|
|
333
|
+
draft: Draft | null;
|
|
334
|
+
emailRef: Ref<HTMLInputElement>;
|
|
335
|
+
createRef: Ref<HTMLButtonElement>;
|
|
336
|
+
failure: Shown | null;
|
|
337
|
+
onClear: () => void;
|
|
338
|
+
busy: boolean;
|
|
339
|
+
options: ReactNode;
|
|
340
|
+
onSubmit: (e: FormEvent<HTMLFormElement>) => void;
|
|
341
|
+
onCancel: () => void;
|
|
342
|
+
}) {
|
|
343
|
+
const name = useRef<HTMLInputElement>(null);
|
|
344
|
+
const errorId = useId();
|
|
345
|
+
// Only when the form first opens: back from the address check, focus goes to the address.
|
|
346
|
+
const first = draft === null;
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
if (first) name.current?.focus();
|
|
349
|
+
}, [first]);
|
|
350
|
+
const onEmail = failure?.field === 'email';
|
|
99
351
|
return (
|
|
100
|
-
<form
|
|
352
|
+
<form
|
|
353
|
+
className="rv-invite"
|
|
354
|
+
aria-label="Add a person"
|
|
355
|
+
onSubmit={onSubmit}
|
|
356
|
+
onKeyDown={escapeTo(onCancel)}
|
|
357
|
+
onInput={failure ? onClear : undefined}
|
|
358
|
+
>
|
|
101
359
|
<label className="field">
|
|
102
360
|
<span className="field-label">Name</span>
|
|
103
361
|
<input
|
|
362
|
+
ref={name}
|
|
104
363
|
className="input"
|
|
105
364
|
name="name"
|
|
106
365
|
required
|
|
107
366
|
maxLength={LIMITS.name}
|
|
108
367
|
autoComplete="off"
|
|
109
|
-
|
|
368
|
+
defaultValue={draft?.name}
|
|
110
369
|
/>
|
|
111
370
|
</label>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
371
|
+
<EmailField
|
|
372
|
+
label={
|
|
373
|
+
<>
|
|
374
|
+
Email <span className="rv-optional">(optional)</span>
|
|
375
|
+
</>
|
|
376
|
+
}
|
|
377
|
+
defaultValue={draft?.email}
|
|
378
|
+
inputRef={emailRef}
|
|
379
|
+
invalid={onEmail}
|
|
380
|
+
belowId={errorId}
|
|
381
|
+
below={onEmail && failure ? <FormError id={errorId} text={failure.text} /> : null}
|
|
382
|
+
/>
|
|
383
|
+
{options}
|
|
384
|
+
{failure && !onEmail ? <FormError id={errorId} text={failure.text} /> : null}
|
|
385
|
+
<div className="rv-row rv-form-actions">
|
|
386
|
+
<Button ref={createRef} type="submit" kind="primary" size={null} label="Create link" busy={busy} />
|
|
387
|
+
<Action label="Cancel" onClick={onCancel} />
|
|
124
388
|
</div>
|
|
125
|
-
<
|
|
389
|
+
<p className="rv-muted rv-disclosure">
|
|
390
|
+
A link signs one person in on one device, then stops. Unused, it lasts {LINK_DAYS} days.
|
|
391
|
+
</p>
|
|
126
392
|
</form>
|
|
127
393
|
);
|
|
128
394
|
}
|
|
129
395
|
|
|
130
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Adding someone, once Add person is pressed: their name and address first;
|
|
398
|
+
* kind, access and the invite keep their defaults behind Options. Create
|
|
399
|
+
* link hands the new link back (`onLink`), after the address check when an
|
|
400
|
+
* invite will go; Cancel or Escape closes the form.
|
|
401
|
+
*/
|
|
402
|
+
function AddForm({
|
|
403
|
+
store,
|
|
404
|
+
clientDefault,
|
|
405
|
+
mail,
|
|
406
|
+
only,
|
|
407
|
+
onLink,
|
|
408
|
+
onCancel,
|
|
409
|
+
}: {
|
|
410
|
+
store: PeopleStore;
|
|
411
|
+
clientDefault: Access | null;
|
|
412
|
+
mail: MailState | null;
|
|
413
|
+
only?: PersonKind;
|
|
414
|
+
onLink: (link: Link) => void;
|
|
415
|
+
onCancel: () => void;
|
|
416
|
+
}) {
|
|
417
|
+
const [chosen, setKind] = useState<PersonKind>('client');
|
|
418
|
+
const kind = only ?? chosen;
|
|
419
|
+
const [access, setAccess] = useState('default');
|
|
420
|
+
const [invite, setInvite] = useState(true);
|
|
421
|
+
const add = useAdd(store, onLink);
|
|
422
|
+
const choice: Choice = { kind, access: access === 'default' ? null : (access as Access) };
|
|
423
|
+
const mailable = mailsHere(mail, kind, only);
|
|
424
|
+
const submit = (e: FormEvent<HTMLFormElement>) => {
|
|
425
|
+
e.preventDefault();
|
|
426
|
+
if (add.busy) return;
|
|
427
|
+
const d = draftOf(new FormData(e.currentTarget));
|
|
428
|
+
const check = mailable && invite && d.email !== '';
|
|
429
|
+
add.keep(d, check);
|
|
430
|
+
if (!check) add.send(d, choice, false);
|
|
431
|
+
};
|
|
432
|
+
const { draft } = add;
|
|
433
|
+
if (add.checking && draft)
|
|
434
|
+
return (
|
|
435
|
+
<AddressCheck
|
|
436
|
+
email={draft.email}
|
|
437
|
+
busy={add.busy}
|
|
438
|
+
onSend={() => add.send(draft, choice, true)}
|
|
439
|
+
onBack={() => add.toForm('address')}
|
|
440
|
+
onEscape={() => add.toForm('create')}
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
return (
|
|
444
|
+
<AddFields
|
|
445
|
+
draft={draft}
|
|
446
|
+
emailRef={add.email}
|
|
447
|
+
createRef={add.create}
|
|
448
|
+
failure={add.failed.failure}
|
|
449
|
+
onClear={add.failed.clear}
|
|
450
|
+
busy={add.busy}
|
|
451
|
+
onSubmit={submit}
|
|
452
|
+
onCancel={onCancel}
|
|
453
|
+
options={
|
|
454
|
+
<AddOptions
|
|
455
|
+
kind={kind}
|
|
456
|
+
onKind={only ? null : setKind}
|
|
457
|
+
access={access}
|
|
458
|
+
onAccess={setAccess}
|
|
459
|
+
clientDefault={clientDefault}
|
|
460
|
+
invite={mailable ? invite : null}
|
|
461
|
+
onInvite={setInvite}
|
|
462
|
+
/>
|
|
463
|
+
}
|
|
464
|
+
/>
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Options: the kind (unless the list holds one), the access, and whether to
|
|
470
|
+
* email the link (only where an invite can go, `invite` null elsewhere), at
|
|
471
|
+
* their defaults until asked for.
|
|
472
|
+
*/
|
|
473
|
+
function AddOptions({
|
|
474
|
+
kind,
|
|
475
|
+
onKind,
|
|
476
|
+
access,
|
|
477
|
+
onAccess,
|
|
478
|
+
clientDefault,
|
|
479
|
+
invite,
|
|
480
|
+
onInvite,
|
|
481
|
+
}: {
|
|
482
|
+
kind: PersonKind;
|
|
483
|
+
onKind: ((k: PersonKind) => void) | null;
|
|
484
|
+
access: string;
|
|
485
|
+
onAccess: (a: string) => void;
|
|
486
|
+
clientDefault: Access | null;
|
|
487
|
+
invite: boolean | null;
|
|
488
|
+
onInvite: (on: boolean) => void;
|
|
489
|
+
}) {
|
|
490
|
+
const [open, setOpen] = useState(false);
|
|
491
|
+
const menu = useContext(MenuClass);
|
|
492
|
+
const accessLabel = useId();
|
|
493
|
+
const id = useId();
|
|
494
|
+
return (
|
|
495
|
+
<div className="rv-options">
|
|
496
|
+
<Button
|
|
497
|
+
kind="tertiary"
|
|
498
|
+
size={null}
|
|
499
|
+
className="rv-act rv-disclose"
|
|
500
|
+
label="Options"
|
|
501
|
+
aria-expanded={open}
|
|
502
|
+
aria-controls={id}
|
|
503
|
+
trailing={<Chevron />}
|
|
504
|
+
onClick={() => setOpen(!open)}
|
|
505
|
+
/>
|
|
506
|
+
{open ? (
|
|
507
|
+
<div id={id} className="rv-options-fields">
|
|
508
|
+
{onKind ? <KindField kind={kind} onKind={onKind} /> : null}
|
|
509
|
+
<div className="field">
|
|
510
|
+
<span id={accessLabel} className="field-label">
|
|
511
|
+
Access
|
|
512
|
+
</span>
|
|
513
|
+
<Select
|
|
514
|
+
labelId={accessLabel}
|
|
515
|
+
menuClassName={menu}
|
|
516
|
+
value={access}
|
|
517
|
+
options={accessOptions(kind, clientDefault)}
|
|
518
|
+
onChange={onAccess}
|
|
519
|
+
/>
|
|
520
|
+
</div>
|
|
521
|
+
{invite === null ? null : (
|
|
522
|
+
<label className="rv-check-row">
|
|
523
|
+
<Checkbox checked={invite} onChange={(e) => onInvite(e.currentTarget.checked)} />
|
|
524
|
+
<span>Email them the link</span>
|
|
525
|
+
</label>
|
|
526
|
+
)}
|
|
527
|
+
</div>
|
|
528
|
+
) : null}
|
|
529
|
+
</div>
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Add person, a quiet row at the end of the list it adds to: it opens the
|
|
535
|
+
* form in its place, the form hands over the new link, and Done closes it.
|
|
536
|
+
* Focus goes back to Add person.
|
|
537
|
+
*/
|
|
538
|
+
function AddPerson({
|
|
539
|
+
store,
|
|
540
|
+
clientDefault,
|
|
541
|
+
mail,
|
|
542
|
+
only,
|
|
543
|
+
onAdded,
|
|
544
|
+
}: {
|
|
545
|
+
store: PeopleStore;
|
|
546
|
+
clientDefault: Access | null;
|
|
547
|
+
mail: MailState | null;
|
|
548
|
+
only?: PersonKind;
|
|
549
|
+
/** The new person's kind, so the list opens their group (openAfterAdd). */
|
|
550
|
+
onAdded: (kind: PersonKind) => void;
|
|
551
|
+
}) {
|
|
552
|
+
const [stage, setStage] = useState<'closed' | 'form' | 'link'>('closed');
|
|
553
|
+
const [link, setLink] = useState<Link | null>(null);
|
|
554
|
+
const button = useRef<HTMLButtonElement>(null);
|
|
555
|
+
const back = useRef(false);
|
|
556
|
+
useEffect(() => {
|
|
557
|
+
if (stage !== 'closed' || !back.current) return;
|
|
558
|
+
back.current = false;
|
|
559
|
+
button.current?.focus();
|
|
560
|
+
}, [stage]);
|
|
561
|
+
const close = () => {
|
|
562
|
+
back.current = true;
|
|
563
|
+
setStage('closed');
|
|
564
|
+
};
|
|
565
|
+
if (stage === 'form')
|
|
566
|
+
return (
|
|
567
|
+
<AddForm
|
|
568
|
+
store={store}
|
|
569
|
+
clientDefault={clientDefault}
|
|
570
|
+
mail={mail}
|
|
571
|
+
only={only}
|
|
572
|
+
onCancel={close}
|
|
573
|
+
onLink={(made) => {
|
|
574
|
+
if (made.kind) onAdded(made.kind);
|
|
575
|
+
setLink(made);
|
|
576
|
+
setStage('link');
|
|
577
|
+
}}
|
|
578
|
+
/>
|
|
579
|
+
);
|
|
580
|
+
if (stage === 'link' && link) return <ShareLink key={link.href} link={link} onDone={close} />;
|
|
581
|
+
return (
|
|
582
|
+
<Button
|
|
583
|
+
ref={button}
|
|
584
|
+
kind="tertiary"
|
|
585
|
+
size={null}
|
|
586
|
+
icon="plus"
|
|
587
|
+
iconSize={16}
|
|
588
|
+
className="rv-act rv-add-person"
|
|
589
|
+
label="Add person"
|
|
590
|
+
onClick={() => setStage('form')}
|
|
591
|
+
/>
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** What the share box says first: how to hand the link over, or what became of the invite. */
|
|
596
|
+
const SHARE_LINE: Record<Mailed, (link: Link) => string> = {
|
|
597
|
+
off: ({ name }) => `Send this link to ${name} only. It signs in one device, then stops working.`,
|
|
598
|
+
sent: ({ name }) => `Emailed to ${name}. If it does not arrive, have them check spam.`,
|
|
599
|
+
refused: ({ name }) => `The email was not sent. Send this link to ${name} yourself.`,
|
|
600
|
+
down: ({ name }) => `The email service did not answer. Send this link to ${name} yourself.`,
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* A new link to hand over, with Copy, and, for a new person, whether their
|
|
605
|
+
* invite went; Done closes it. Copy takes focus, so the link is one key away.
|
|
606
|
+
*/
|
|
607
|
+
function ShareLink({ link, onDone }: { link: Link; onDone: () => void }) {
|
|
131
608
|
const [copied, setCopied] = useState(false);
|
|
132
609
|
const field = useRef<HTMLInputElement>(null);
|
|
610
|
+
const copyButton = useRef<HTMLButtonElement>(null);
|
|
611
|
+
useEffect(() => copyButton.current?.focus(), []);
|
|
133
612
|
const copy = () =>
|
|
134
613
|
navigator.clipboard.writeText(link.href).then(
|
|
135
614
|
() => setCopied(true),
|
|
@@ -137,11 +616,8 @@ function ShareLink({ link }: { link: Link }) {
|
|
|
137
616
|
() => field.current?.select(),
|
|
138
617
|
);
|
|
139
618
|
return (
|
|
140
|
-
<div className="rv-share" role="status">
|
|
141
|
-
<p>
|
|
142
|
-
Send this link to {link.name} only. It signs in one device, then stops working. Unused, it lasts{' '}
|
|
143
|
-
{LINK_DAYS} days.
|
|
144
|
-
</p>
|
|
619
|
+
<div className="rv-share" role="status" onKeyDown={escapeTo(onDone)}>
|
|
620
|
+
<p>{SHARE_LINE[link.mailed ?? 'off'](link)}</p>
|
|
145
621
|
<div className="rv-share-row">
|
|
146
622
|
<input
|
|
147
623
|
ref={field}
|
|
@@ -151,33 +627,24 @@ function ShareLink({ link }: { link: Link }) {
|
|
|
151
627
|
aria-label={`Sign-in link for ${link.name}`}
|
|
152
628
|
onFocus={(e) => e.currentTarget.select()}
|
|
153
629
|
/>
|
|
154
|
-
<Button
|
|
630
|
+
<Button
|
|
631
|
+
ref={copyButton}
|
|
632
|
+
size={null}
|
|
633
|
+
className="rv-copy"
|
|
634
|
+
label={copied ? 'Copied' : 'Copy'}
|
|
635
|
+
onClick={copy}
|
|
636
|
+
/>
|
|
637
|
+
</div>
|
|
638
|
+
<div className="rv-row">
|
|
639
|
+
<Action label="Done" onClick={onDone} />
|
|
155
640
|
</div>
|
|
156
641
|
</div>
|
|
157
642
|
);
|
|
158
643
|
}
|
|
159
644
|
|
|
160
|
-
/** How links behave, said once where Studio shares them. */
|
|
161
|
-
function HowLinksWork() {
|
|
162
|
-
return (
|
|
163
|
-
<p className="rv-muted rv-disclosure">
|
|
164
|
-
Each person gets their own link. A link signs in one device, then stops working, so a second device
|
|
165
|
-
needs a new link. An unused link lasts {LINK_DAYS} days. Revoking someone ends their access everywhere.
|
|
166
|
-
</p>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
645
|
const ended = (p: Me) => p.accessEndsAt !== null && p.accessEndsAt <= new Date().toISOString();
|
|
171
646
|
|
|
172
|
-
/**
|
|
173
|
-
function accessText(p: Me): string {
|
|
174
|
-
if (p.accessEndsAt === null) return 'open-ended';
|
|
175
|
-
const day = fmtDate(p.accessEndsAt.slice(0, 10));
|
|
176
|
-
return ended(p) ? `access ended ${day}` : `until ${day}`;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
type Mode = 'idle' | 'signOut' | 'revoke' | 'access';
|
|
180
|
-
|
|
647
|
+
/** A question with its answer and a way out, in the row. Keep takes focus, never the destructive answer. */
|
|
181
648
|
function Confirm({
|
|
182
649
|
text,
|
|
183
650
|
label,
|
|
@@ -189,11 +656,15 @@ function Confirm({
|
|
|
189
656
|
onYes: () => void;
|
|
190
657
|
onNo: () => void;
|
|
191
658
|
}) {
|
|
659
|
+
const keep = useRef<HTMLButtonElement>(null);
|
|
660
|
+
useEffect(() => keep.current?.focus(), []);
|
|
192
661
|
return (
|
|
193
662
|
<>
|
|
194
|
-
<
|
|
195
|
-
<
|
|
196
|
-
|
|
663
|
+
<p className="rv-confirm">{text}</p>
|
|
664
|
+
<div className="rv-row">
|
|
665
|
+
<Button kind="tertiary" size={null} className="rv-act rv-act-danger" label={label} onClick={onYes} />
|
|
666
|
+
<Button ref={keep} kind="tertiary" size={null} className="rv-act" label="Keep" onClick={onNo} />
|
|
667
|
+
</div>
|
|
197
668
|
</>
|
|
198
669
|
);
|
|
199
670
|
}
|
|
@@ -201,53 +672,218 @@ function Confirm({
|
|
|
201
672
|
function AccessPicker({ person, store, onDone }: { person: Me; store: PeopleStore; onDone: () => void }) {
|
|
202
673
|
const label = useId();
|
|
203
674
|
const menu = useContext(MenuClass);
|
|
675
|
+
const row = useRef<HTMLDivElement>(null);
|
|
676
|
+
useEffect(() => row.current?.querySelector<HTMLElement>('.select')?.focus(), []);
|
|
204
677
|
return (
|
|
205
678
|
<>
|
|
206
|
-
<
|
|
679
|
+
<p id={label} className="rv-confirm">
|
|
207
680
|
Access from today
|
|
208
|
-
</
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
681
|
+
</p>
|
|
682
|
+
<div ref={row} className="rv-row">
|
|
683
|
+
<Select
|
|
684
|
+
labelId={label}
|
|
685
|
+
menuClassName={menu}
|
|
686
|
+
value={null}
|
|
687
|
+
placeholder="Choose"
|
|
688
|
+
options={LENGTH_OPTIONS}
|
|
689
|
+
onChange={(next) => act(store.setAccess(person.id, next as Access).then(onDone))}
|
|
690
|
+
/>
|
|
691
|
+
<Action label="Cancel" onClick={onDone} />
|
|
692
|
+
</div>
|
|
218
693
|
</>
|
|
219
694
|
);
|
|
220
695
|
}
|
|
221
696
|
|
|
222
|
-
|
|
697
|
+
/**
|
|
698
|
+
* Sets, changes or clears the address someone signs in with by email. Left
|
|
699
|
+
* empty, they sign in by link only. Focus moves to the field where a mouse
|
|
700
|
+
* opened it, never on touch, where it would raise the keyboard. A refusal
|
|
701
|
+
* takes the hint's place under the field, so the editor keeps its height.
|
|
702
|
+
*/
|
|
703
|
+
function EmailEditor({ person, store, onDone }: { person: Me; store: PeopleStore; onDone: () => void }) {
|
|
704
|
+
const [busy, setBusy] = useState(false);
|
|
705
|
+
const { failure, caught, clear } = useFailure(store);
|
|
706
|
+
const field = useRef<HTMLInputElement>(null);
|
|
707
|
+
const below = useId();
|
|
708
|
+
useEffect(() => {
|
|
709
|
+
if (matchMedia('(pointer: fine)').matches) field.current?.focus();
|
|
710
|
+
}, []);
|
|
711
|
+
const save = (e: FormEvent<HTMLFormElement>) => {
|
|
712
|
+
e.preventDefault();
|
|
713
|
+
if (busy) return;
|
|
714
|
+
setBusy(true);
|
|
715
|
+
clear();
|
|
716
|
+
act(
|
|
717
|
+
store
|
|
718
|
+
.setEmail(person.id, emailValue(new FormData(e.currentTarget)))
|
|
719
|
+
.then(onDone, caught)
|
|
720
|
+
.finally(() => setBusy(false)),
|
|
721
|
+
);
|
|
722
|
+
};
|
|
723
|
+
return (
|
|
724
|
+
<form className="rv-email-edit" onSubmit={save} onInput={failure ? clear : undefined}>
|
|
725
|
+
<EmailField
|
|
726
|
+
label="Email"
|
|
727
|
+
defaultValue={person.email ?? ''}
|
|
728
|
+
inputRef={field}
|
|
729
|
+
belowId={below}
|
|
730
|
+
invalid={failure?.field === 'email'}
|
|
731
|
+
below={
|
|
732
|
+
failure ? (
|
|
733
|
+
<FormError id={below} text={failure.text} />
|
|
734
|
+
) : (
|
|
735
|
+
<p id={below} className="rv-muted rv-disclosure">
|
|
736
|
+
Leave it empty for links only.
|
|
737
|
+
</p>
|
|
738
|
+
)
|
|
739
|
+
}
|
|
740
|
+
/>
|
|
741
|
+
<div className="rv-row">
|
|
742
|
+
<Button type="submit" size={null} label="Save email" busy={busy} />
|
|
743
|
+
<Action label="Cancel" onClick={onDone} />
|
|
744
|
+
</div>
|
|
745
|
+
</form>
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** What each action is called in a row's menu. */
|
|
750
|
+
const ACTION_LABEL: Record<Exclude<RowAction, 'email'>, string> = {
|
|
751
|
+
link: 'New link',
|
|
752
|
+
access: 'Change access',
|
|
753
|
+
signOut: 'Sign out everywhere',
|
|
754
|
+
revoke: 'Revoke',
|
|
755
|
+
};
|
|
756
|
+
const labelOf = (a: RowAction, person: Me) =>
|
|
757
|
+
a === 'email' ? (person.email ? 'Change email' : 'Add email') : ACTION_LABEL[a];
|
|
223
758
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
759
|
+
/**
|
|
760
|
+
* A row's one trailing control: an icon button that opens its menu, Revoke
|
|
761
|
+
* last and set apart, or the action itself by name when there is only one.
|
|
762
|
+
* Busy while a new link is on its way.
|
|
763
|
+
*/
|
|
764
|
+
function RowMenu({
|
|
765
|
+
person,
|
|
766
|
+
own,
|
|
767
|
+
busy,
|
|
768
|
+
run,
|
|
769
|
+
buttonRef,
|
|
770
|
+
}: {
|
|
771
|
+
person: Me;
|
|
772
|
+
own: boolean;
|
|
773
|
+
busy: boolean;
|
|
774
|
+
run: (a: RowAction) => void;
|
|
775
|
+
buttonRef: Ref<HTMLButtonElement>;
|
|
776
|
+
}) {
|
|
777
|
+
const menuClass = useContext(MenuClass);
|
|
778
|
+
const actions = menuActions({ own, ended: ended(person) });
|
|
779
|
+
const items: MenuEntry[] = actions.flatMap((a): MenuEntry[] => [
|
|
780
|
+
...(a === 'revoke' ? (['-'] as const) : []),
|
|
781
|
+
{ label: labelOf(a, person), value: a, danger: a === 'revoke' },
|
|
782
|
+
]);
|
|
783
|
+
const { triggerProps, menu } = useMenu({
|
|
784
|
+
items,
|
|
785
|
+
align: 'end',
|
|
786
|
+
within: '.rv-card, .studio-people',
|
|
787
|
+
className: menuClass,
|
|
788
|
+
label: `Actions for ${person.name}`,
|
|
789
|
+
onSelect: (value) => run(value as RowAction),
|
|
790
|
+
});
|
|
791
|
+
// One action needs no menu: the row shows it by name.
|
|
792
|
+
if (actions.length === 1)
|
|
229
793
|
return (
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
794
|
+
<Button
|
|
795
|
+
ref={buttonRef}
|
|
796
|
+
kind="tertiary"
|
|
797
|
+
size={null}
|
|
798
|
+
className="rv-act rv-row-act"
|
|
799
|
+
label={labelOf(actions[0], person)}
|
|
800
|
+
busy={busy}
|
|
801
|
+
onClick={() => run(actions[0])}
|
|
802
|
+
/>
|
|
234
803
|
);
|
|
235
804
|
return (
|
|
236
805
|
<>
|
|
237
|
-
<
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
806
|
+
<Button
|
|
807
|
+
{...triggerProps}
|
|
808
|
+
ref={(el: HTMLButtonElement | null) => {
|
|
809
|
+
triggerProps.ref(el);
|
|
810
|
+
if (typeof buttonRef === 'function') buttonRef(el);
|
|
811
|
+
else if (buttonRef) buttonRef.current = el;
|
|
812
|
+
}}
|
|
813
|
+
kind="tertiary"
|
|
814
|
+
size={null}
|
|
815
|
+
className="rv-row-menu"
|
|
816
|
+
icon="dots-horizontal"
|
|
817
|
+
iconSize={20}
|
|
818
|
+
busy={busy}
|
|
819
|
+
aria-label={`Actions for ${person.name}`}
|
|
820
|
+
/>
|
|
821
|
+
{menu}
|
|
241
822
|
</>
|
|
242
823
|
);
|
|
243
824
|
}
|
|
244
825
|
|
|
245
|
-
|
|
826
|
+
type Mode = 'idle' | Exclude<RowAction, 'link'> | 'link';
|
|
827
|
+
|
|
828
|
+
/** Where access stands: Ended or Revoked as a badge, a running end date as plain words. */
|
|
829
|
+
function AccessState({ state }: { state: NonNullable<ReturnType<typeof stateBadge>> }) {
|
|
830
|
+
if (!state.chip) return <span className="rv-until">{state.text}</span>;
|
|
831
|
+
return <Badge tone={state.tone ?? undefined}>{state.text}</Badge>;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/** Where a row's access stands, when it says anything: its group already says who they are. */
|
|
835
|
+
function Badges({ person }: { person: Me }) {
|
|
836
|
+
const state = stateBadge(
|
|
837
|
+
{ endsAt: person.accessEndsAt, revoked: !!person.revokedAt, now: new Date().toISOString() },
|
|
838
|
+
person.accessEndsAt ? fmtDate(person.accessEndsAt.slice(0, 10)) : '',
|
|
839
|
+
);
|
|
840
|
+
if (!state) return null;
|
|
841
|
+
return (
|
|
842
|
+
<div className="rv-tags">
|
|
843
|
+
<AccessState state={state} />
|
|
844
|
+
</div>
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* One person: the name, the address under it, their badges, the one menu.
|
|
850
|
+
* A revoked person has no menu.
|
|
851
|
+
*/
|
|
852
|
+
function PersonRow({ person, store, own }: { person: Me; store: PeopleStore; own: boolean }) {
|
|
246
853
|
const [mode, setMode] = useState<Mode>('idle');
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
|
|
854
|
+
const [link, setLink] = useState<Link | null>(null);
|
|
855
|
+
const [busy, setBusy] = useState(false);
|
|
856
|
+
const button = useRef<HTMLButtonElement | null>(null);
|
|
857
|
+
const back = useRef(false);
|
|
858
|
+
// Whatever closes in the row hands focus back to the menu button that opened it.
|
|
859
|
+
useEffect(() => {
|
|
860
|
+
if (mode !== 'idle' || !back.current) return;
|
|
861
|
+
back.current = false;
|
|
862
|
+
button.current?.focus();
|
|
863
|
+
}, [mode]);
|
|
864
|
+
const idle = () => {
|
|
865
|
+
back.current = true;
|
|
866
|
+
setMode('idle');
|
|
867
|
+
};
|
|
868
|
+
const showLink = (href: string) => {
|
|
869
|
+
setLink({ name: person.name, href });
|
|
870
|
+
setMode('link');
|
|
871
|
+
};
|
|
872
|
+
const run = (a: RowAction) => {
|
|
873
|
+
if (a !== 'link') return setMode(a);
|
|
874
|
+
if (busy) return;
|
|
875
|
+
setBusy(true);
|
|
876
|
+
act(
|
|
877
|
+
store
|
|
878
|
+
.newLink(person.id)
|
|
879
|
+
.then(showLink)
|
|
880
|
+
.finally(() => setBusy(false)),
|
|
881
|
+
);
|
|
882
|
+
};
|
|
883
|
+
const views: Record<Exclude<Mode, 'idle'>, () => ReactNode> = {
|
|
884
|
+
email: () => <EmailEditor person={person} store={store} onDone={idle} />,
|
|
250
885
|
access: () => <AccessPicker person={person} store={store} onDone={idle} />,
|
|
886
|
+
link: () => (link ? <ShareLink key={link.href} link={link} onDone={idle} /> : null),
|
|
251
887
|
revoke: () => (
|
|
252
888
|
<Confirm
|
|
253
889
|
text={`Remove ${person.name}’s access everywhere?`}
|
|
@@ -260,31 +896,162 @@ function PersonRow({ person, store, onLink }: RowProps) {
|
|
|
260
896
|
<Confirm
|
|
261
897
|
text={`Sign ${person.name} out of every device? They get one new link.`}
|
|
262
898
|
label="Sign out"
|
|
263
|
-
onYes={() =>
|
|
264
|
-
act(
|
|
265
|
-
store.signOut(person.id).then((href) => {
|
|
266
|
-
onLink({ name: person.name, href });
|
|
267
|
-
idle();
|
|
268
|
-
}),
|
|
269
|
-
)
|
|
270
|
-
}
|
|
899
|
+
onYes={() => act(store.signOut(person.id).then(showLink))}
|
|
271
900
|
onNo={idle}
|
|
272
901
|
/>
|
|
273
902
|
),
|
|
274
903
|
};
|
|
275
|
-
|
|
904
|
+
const editing = mode === 'email';
|
|
905
|
+
return (
|
|
906
|
+
<li data-revoked={person.revokedAt ? '' : undefined}>
|
|
907
|
+
<div className="rv-who">
|
|
908
|
+
<strong className="rv-name">{person.name}</strong>
|
|
909
|
+
{person.email && !editing ? (
|
|
910
|
+
<span className="rv-muted rv-email" title={person.email}>
|
|
911
|
+
{person.email}
|
|
912
|
+
</span>
|
|
913
|
+
) : null}
|
|
914
|
+
</div>
|
|
915
|
+
<Badges person={person} />
|
|
916
|
+
{person.revokedAt || mode !== 'idle' ? null : (
|
|
917
|
+
<RowMenu person={person} own={own} busy={busy} run={run} buttonRef={button} />
|
|
918
|
+
)}
|
|
919
|
+
{mode === 'idle' ? null : (
|
|
920
|
+
<fieldset className="rv-inline" aria-label={person.name} onKeyDown={escapeTo(idle)}>
|
|
921
|
+
{views[mode]()}
|
|
922
|
+
</fieldset>
|
|
923
|
+
)}
|
|
924
|
+
</li>
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* One group of the list: its heading, the kind as the Kind menu names it,
|
|
930
|
+
* unless the section around it already names it (`titled` false, the studio
|
|
931
|
+
* hub's), its first rows, and Show N
|
|
932
|
+
* more for the rest, which Show fewer closes again. The button stays where
|
|
933
|
+
* focus is while the rows open and close above it.
|
|
934
|
+
*/
|
|
935
|
+
function PeopleGroup({
|
|
936
|
+
kind,
|
|
937
|
+
people,
|
|
938
|
+
titled,
|
|
939
|
+
open,
|
|
940
|
+
onOpen,
|
|
941
|
+
store,
|
|
942
|
+
me,
|
|
943
|
+
}: {
|
|
944
|
+
kind: PersonKind;
|
|
945
|
+
people: Me[];
|
|
946
|
+
titled: boolean;
|
|
947
|
+
open: boolean;
|
|
948
|
+
onOpen: (open: boolean) => void;
|
|
949
|
+
store: PeopleStore;
|
|
950
|
+
me: Me | null;
|
|
951
|
+
}) {
|
|
952
|
+
const { shown, more } = shownOf(people, open);
|
|
953
|
+
const list = useId();
|
|
954
|
+
return (
|
|
955
|
+
<div className="rv-group">
|
|
956
|
+
{titled ? <h3 className="rv-group-title">{KIND_NAMES[kind]}</h3> : null}
|
|
957
|
+
<ul id={list} className="rv-people">
|
|
958
|
+
{shown.map((p) => (
|
|
959
|
+
<PersonRow key={p.id} person={p} store={store} own={p.id === me?.id} />
|
|
960
|
+
))}
|
|
961
|
+
</ul>
|
|
962
|
+
{more ? (
|
|
963
|
+
<Button
|
|
964
|
+
kind="tertiary"
|
|
965
|
+
size={null}
|
|
966
|
+
className="rv-act rv-disclose rv-more"
|
|
967
|
+
label={open ? 'Show fewer' : `Show ${more} more`}
|
|
968
|
+
aria-expanded={open}
|
|
969
|
+
aria-controls={list}
|
|
970
|
+
trailing={<Chevron />}
|
|
971
|
+
onClick={() => onOpen(!open)}
|
|
972
|
+
/>
|
|
973
|
+
) : null}
|
|
974
|
+
</div>
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
/** What Studio pastes to Claude to turn email sign-in on (the miles-deploy skill runs `design-hub studio email`). */
|
|
979
|
+
const MAIL_PROMPT =
|
|
980
|
+
'Turn on email sign-in for my Design Hub studio, so people with an email can sign in with a code. Use the miles-deploy skill. Ask me first for the sender’s name and address, a file holding a full-access Resend API key, and an address for the test mail.';
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Email off, for Studio: that people sign in by link only, and a prompt to
|
|
984
|
+
* copy for Claude that sets email up. Where the clipboard is out of reach,
|
|
985
|
+
* the prompt shows in a field, selected, to copy by hand.
|
|
986
|
+
*/
|
|
987
|
+
function MailOff() {
|
|
988
|
+
const [copied, setCopied] = useState<'no' | 'yes' | 'by hand'>('no');
|
|
989
|
+
const field = useRef<HTMLInputElement>(null);
|
|
990
|
+
useEffect(() => {
|
|
991
|
+
if (copied === 'by hand') field.current?.select();
|
|
992
|
+
}, [copied]);
|
|
993
|
+
const copy = () =>
|
|
994
|
+
navigator.clipboard.writeText(MAIL_PROMPT).then(
|
|
995
|
+
() => setCopied('yes'),
|
|
996
|
+
() => setCopied('by hand'),
|
|
997
|
+
);
|
|
998
|
+
return (
|
|
999
|
+
<div className="rv-mail" aria-live="polite">
|
|
1000
|
+
<p className="rv-muted">Email sign-in is off, so people sign in by link only.</p>
|
|
1001
|
+
{copied === 'by hand' ? (
|
|
1002
|
+
<input
|
|
1003
|
+
ref={field}
|
|
1004
|
+
className="input rv-mail-prompt"
|
|
1005
|
+
readOnly
|
|
1006
|
+
value={MAIL_PROMPT}
|
|
1007
|
+
aria-label="Prompt for Claude"
|
|
1008
|
+
onFocus={(e) => e.currentTarget.select()}
|
|
1009
|
+
/>
|
|
1010
|
+
) : (
|
|
1011
|
+
<Button
|
|
1012
|
+
kind="tertiary"
|
|
1013
|
+
size={null}
|
|
1014
|
+
className="rv-act rv-mail-copy"
|
|
1015
|
+
label={copied === 'yes' ? 'Copied. Paste it to Claude.' : 'Copy a prompt to turn it on'}
|
|
1016
|
+
onClick={copy}
|
|
1017
|
+
/>
|
|
1018
|
+
)}
|
|
1019
|
+
</div>
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* How people sign in, for Studio only (E14): with email off, by link, and
|
|
1025
|
+
* the prompt that turns it on; with email on, that a person with an address
|
|
1026
|
+
* signs in alone; and, while the last sign-in email failed, that too.
|
|
1027
|
+
*/
|
|
1028
|
+
function MailLines({ mail }: { mail: MailState | null }) {
|
|
1029
|
+
if (mail === null) return null;
|
|
1030
|
+
if (mail === 'off') return <MailOff />;
|
|
1031
|
+
return (
|
|
1032
|
+
<div className="rv-mail">
|
|
1033
|
+
<p className="rv-muted">People with an email can sign in with a code.</p>
|
|
1034
|
+
{mail === 'failing' ? (
|
|
1035
|
+
<p className="rv-mail-failing" role="status">
|
|
1036
|
+
Sign-in emails are failing. Links still work.
|
|
1037
|
+
</p>
|
|
1038
|
+
) : null}
|
|
1039
|
+
</div>
|
|
1040
|
+
);
|
|
276
1041
|
}
|
|
277
1042
|
|
|
278
1043
|
/**
|
|
279
1044
|
* `only` fixes the kind the form adds, for a list that holds one kind (the
|
|
280
1045
|
* studio hub's sections); `menuClassName` is the class of every select's
|
|
281
|
-
* popup, the review panel's harness material unless a page gives
|
|
1046
|
+
* and menu's popup, the review panel's harness material unless a page gives
|
|
1047
|
+
* its own.
|
|
282
1048
|
*/
|
|
283
1049
|
export function People({
|
|
284
1050
|
store,
|
|
285
1051
|
me,
|
|
286
1052
|
people,
|
|
287
1053
|
access,
|
|
1054
|
+
mail,
|
|
288
1055
|
only,
|
|
289
1056
|
menuClassName = 'rv-menu',
|
|
290
1057
|
}: {
|
|
@@ -292,34 +1059,41 @@ export function People({
|
|
|
292
1059
|
me: Me | null;
|
|
293
1060
|
people: Me[] | null;
|
|
294
1061
|
access: Access | null;
|
|
1062
|
+
mail: MailState | null;
|
|
295
1063
|
only?: PersonKind;
|
|
296
1064
|
menuClassName?: string;
|
|
297
1065
|
}) {
|
|
298
|
-
|
|
1066
|
+
// Each group folds on its own; one a person was just added to opens.
|
|
1067
|
+
const [open, setOpen] = useState<Record<PersonKind, boolean>>({ client: false, studio: false });
|
|
299
1068
|
return (
|
|
300
1069
|
<MenuClass.Provider value={menuClassName}>
|
|
301
1070
|
<div className="rv-body">
|
|
302
|
-
<
|
|
303
|
-
{/* Keyed by the link, so a second one starts on Copy again. */}
|
|
304
|
-
{link && <ShareLink key={link.href} link={link} />}
|
|
305
|
-
<HowLinksWork />
|
|
1071
|
+
<MailLines mail={mail} />
|
|
306
1072
|
{people === null ? (
|
|
307
1073
|
<p className="rv-muted">Loading people…</p>
|
|
1074
|
+
) : people.length === 0 ? (
|
|
1075
|
+
<p className="rv-muted">No one here yet.</p>
|
|
308
1076
|
) : (
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
</ul>
|
|
1077
|
+
groupPeople(people).map((g) => (
|
|
1078
|
+
<PeopleGroup
|
|
1079
|
+
key={g.kind}
|
|
1080
|
+
kind={g.kind}
|
|
1081
|
+
people={g.people}
|
|
1082
|
+
titled={!only}
|
|
1083
|
+
open={open[g.kind]}
|
|
1084
|
+
onOpen={(next) => setOpen({ ...open, [g.kind]: next })}
|
|
1085
|
+
store={store}
|
|
1086
|
+
me={me}
|
|
1087
|
+
/>
|
|
1088
|
+
))
|
|
322
1089
|
)}
|
|
1090
|
+
<AddPerson
|
|
1091
|
+
store={store}
|
|
1092
|
+
clientDefault={access}
|
|
1093
|
+
mail={mail}
|
|
1094
|
+
only={only}
|
|
1095
|
+
onAdded={(kind) => setOpen((was) => openAfterAdd(was, kind))}
|
|
1096
|
+
/>
|
|
323
1097
|
</div>
|
|
324
1098
|
</MenuClass.Provider>
|
|
325
1099
|
);
|