@pairz/directory 0.0.1 → 1.0.0-rc.81

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -1
  3. package/WORDS.md +198 -0
  4. package/actions/code.d.ts +4 -0
  5. package/actions/code.js +135 -0
  6. package/actions/host.d.ts +2 -0
  7. package/actions/host.js +55 -0
  8. package/actions/invite.d.ts +5 -0
  9. package/actions/invite.js +129 -0
  10. package/actions/org.d.ts +10 -0
  11. package/actions/org.js +273 -0
  12. package/collections/credit-code.d.ts +107 -0
  13. package/collections/credit-code.js +28 -0
  14. package/collections/invite.d.ts +74 -0
  15. package/collections/invite.js +20 -0
  16. package/collections/membership.d.ts +65 -0
  17. package/collections/membership.js +22 -0
  18. package/collections/org-host.d.ts +55 -0
  19. package/collections/org-host.js +30 -0
  20. package/collections/org.d.ts +134 -0
  21. package/collections/org.js +58 -0
  22. package/collections/staff.d.ts +35 -0
  23. package/collections/staff.js +12 -0
  24. package/contract.d.ts +8 -0
  25. package/contract.js +8 -0
  26. package/mod.d.ts +67 -0
  27. package/mod.js +123 -0
  28. package/package.json +63 -3
  29. package/routes/console.d.ts +26 -0
  30. package/routes/console.js +129 -0
  31. package/routes/enter.d.ts +18 -0
  32. package/routes/enter.js +47 -0
  33. package/routes/forward.d.ts +35 -0
  34. package/routes/forward.js +120 -0
  35. package/routes/orgs.d.ts +25 -0
  36. package/routes/orgs.js +113 -0
  37. package/routes/signout.d.ts +11 -0
  38. package/routes/signout.js +36 -0
  39. package/shared/enter.d.ts +36 -0
  40. package/shared/enter.js +82 -0
  41. package/shared/http.d.ts +44 -0
  42. package/shared/http.js +79 -0
  43. package/shared/member.d.ts +21 -0
  44. package/shared/member.js +73 -0
  45. package/shared/settings.d.ts +53 -0
  46. package/shared/settings.js +16 -0
  47. package/shared/state.d.ts +74 -0
  48. package/shared/state.js +101 -0
  49. package/views/web/codes.d.ts +27 -0
  50. package/views/web/codes.js +50 -0
  51. package/views/web/console-codes.d.ts +37 -0
  52. package/views/web/console-codes.js +166 -0
  53. package/views/web/console.d.ts +37 -0
  54. package/views/web/console.js +224 -0
  55. package/views/web/lists.d.ts +48 -0
  56. package/views/web/lists.js +42 -0
  57. package/views/web/org.d.ts +12 -0
  58. package/views/web/org.js +62 -0
  59. package/views/web/orgs.d.ts +148 -0
  60. package/views/web/orgs.js +253 -0
  61. package/views/web/style.d.ts +6 -0
  62. package/views/web/style.js +197 -0
  63. package/views/web/switcher.d.ts +81 -0
  64. package/views/web/switcher.js +367 -0
  65. package/views/web/words.d.ts +10 -0
  66. package/views/web/words.js +206 -0
  67. package/web.d.ts +36 -0
  68. package/web.js +57 -0
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Orgs in the shell, when the app serves many (`useOrgs`), through the web
3
+ * shell's `orgs` slot: the switcher at the top of the sidebar, where the
4
+ * app's identity sits (`orgs.switcher`: the org you're in, your standing
5
+ * there; opened, your orgs, Personal first-class, invitations waiting with a
6
+ * badge, to join or decline in place, a new org, the org's settings, and for
7
+ * staff, every org); on the rail, the sidebar folded (`orgs.rail`), the same
8
+ * as the org's face, named beside it, opening beside the rail; beside every
9
+ * page (`orgs.overlay`), the small dialog
10
+ * that makes an org and going between them: a short transition while the
11
+ * page starts over in the other org, and a word once it's there; and what
12
+ * the shell's menu and palette list (`useShellOrgs`). Staff in an org that
13
+ * isn't theirs see it, quietly and all the time (a line along the top of
14
+ * the window): what they do is on its record.
15
+ */
16
+ import { type ReactNode } from "react";
17
+ import type { ViewContext } from "pairz";
18
+ import { type PaletteGroup } from "pairz/web";
19
+ import { type Org, type Orgs } from "./orgs.js";
20
+ import { type OrgsShown, type Standing } from "pairz/plugins/interfaces/contract";
21
+ type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
22
+ /** The directory front end's styles, with whatever of it is drawn. */
23
+ export declare const style: import("react").JSX.Element;
24
+ /**
25
+ * The switcher (`orgs.switcher`, the `orgs` slot's): where you are among your orgs, at the top
26
+ * of the sidebar, once they're known (the shell draws it once `useShellOrgs` answers).
27
+ */
28
+ export declare const switcherView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
29
+ /**
30
+ * The switcher on the rail (`orgs.rail`, the `orgs` slot's), the sidebar folded: the org's face,
31
+ * named beside it, its invitations counted at its corner; it opens the same choices, beside it.
32
+ */
33
+ export declare const switcherRailView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
34
+ /**
35
+ * Beside every page (`orgs.overlay`, the `orgs` slot's), outside the sidebar, which is a drawer
36
+ * on a phone: the line along the top while in an org as staff, the dialog that makes an org,
37
+ * and going into one.
38
+ */
39
+ export declare const overlayView: () => ReactNode;
40
+ /**
41
+ * What the shell's own parts list of the person's orgs (the `orgs` slot's hook): their email,
42
+ * the org's page and (for staff) every org in their menu, and orgs in the palette. Nothing until
43
+ * the orgs are known, or where the server serves one.
44
+ */
45
+ export declare function useShellOrgs(call: Call): OrgsShown | undefined;
46
+ /** Opens the dialog that makes an org. */
47
+ export declare const openNewOrg: () => void;
48
+ /** An org's face: yours (Personal) is you; a team's, its initials. */
49
+ export declare function OrgFace({ org, person, size }: {
50
+ org: Pick<Org, "name" | "kind"> & {
51
+ id?: string;
52
+ };
53
+ person: string;
54
+ size?: number;
55
+ }): ReactNode;
56
+ export declare function OrgSwitcher({ orgs, here, standing, staff, onNew, rail }: {
57
+ orgs: Orgs;
58
+ /** The org the person is in. */
59
+ here?: Org;
60
+ standing?: Standing;
61
+ /** In it as platform staff. */
62
+ staff: boolean;
63
+ /** Opens the dialog that makes one. */
64
+ onNew(): void;
65
+ /** On the rail, the sidebar folded: the org's face alone, opening beside it. */
66
+ rail?: boolean;
67
+ }): ReactNode;
68
+ /** The small dialog that makes a team org: its name, then you're in it, its owner. */
69
+ export declare function NewOrg({ open, onClose }: {
70
+ open: boolean;
71
+ onClose(): void;
72
+ }): ReactNode;
73
+ /** While the page goes into another org: its face and name, over everything, until it's there. */
74
+ export declare function Switching(): ReactNode;
75
+ /**
76
+ * What the palette offers for orgs: the others to switch to, invitations to
77
+ * join or decline (with the spaces' own, under one heading), a new org, the
78
+ * org's settings, and for staff, every org.
79
+ */
80
+ export declare function orgsPalette(orgs: Orgs, here: Org | undefined, standing: Standing | undefined): PaletteGroup[];
81
+ export {};
@@ -0,0 +1,367 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Orgs in the shell, when the app serves many (`useOrgs`), through the web
4
+ * shell's `orgs` slot: the switcher at the top of the sidebar, where the
5
+ * app's identity sits (`orgs.switcher`: the org you're in, your standing
6
+ * there; opened, your orgs, Personal first-class, invitations waiting with a
7
+ * badge, to join or decline in place, a new org, the org's settings, and for
8
+ * staff, every org); on the rail, the sidebar folded (`orgs.rail`), the same
9
+ * as the org's face, named beside it, opening beside the rail; beside every
10
+ * page (`orgs.overlay`), the small dialog
11
+ * that makes an org and going between them: a short transition while the
12
+ * page starts over in the other org, and a word once it's there; and what
13
+ * the shell's menu and palette list (`useShellOrgs`). Staff in an org that
14
+ * isn't theirs see it, quietly and all the time (a line along the top of
15
+ * the window): what they do is on its record.
16
+ */
17
+ import { useEffect, useRef, useState, useSyncExternalStore, } from "react";
18
+ import { Avatar, Badge, Button, Dialog, Field, Icon, Input, lang, message, Notice, Popover, RailItem, Spinner, Time, } from "pairz/web";
19
+ import { answerOrgInvite, arrived, asStaff, createOrg, enterOrg, orgName, useOrgs, useSwitching, } from "./orgs.js";
20
+ import { orgRoleName, runs, useStanding, } from "pairz/plugins/interfaces/contract";
21
+ import { standingName } from "./lists.js";
22
+ import { STYLE } from "./style.js";
23
+ import { say } from "./words.js";
24
+ /** The directory front end's styles, with whatever of it is drawn. */
25
+ export const style = _jsx("style", { href: "directory-web", precedence: "pairz", children: STYLE });
26
+ /**
27
+ * The switcher (`orgs.switcher`, the `orgs` slot's): where you are among your orgs, at the top
28
+ * of the sidebar, once they're known (the shell draws it once `useShellOrgs` answers).
29
+ */
30
+ export const switcherView = (_, ctx) => (_jsx(Switcher, { call: ctx.call }));
31
+ /**
32
+ * The switcher on the rail (`orgs.rail`, the `orgs` slot's), the sidebar folded: the org's face,
33
+ * named beside it, its invitations counted at its corner; it opens the same choices, beside it.
34
+ */
35
+ export const switcherRailView = (_, ctx) => (_jsx(Switcher, { call: ctx.call, rail: true }));
36
+ function Switcher({ call, rail }) {
37
+ const orgs = useOrgs();
38
+ const ready = orgs.status === "ready";
39
+ const standing = useStanding(call, ready);
40
+ if (!ready)
41
+ return null;
42
+ return (_jsxs(_Fragment, { children: [style, _jsx(OrgSwitcher, { orgs: orgs.value, here: orgs.here, standing: standing, staff: asStaff(orgs.value), onNew: openNewOrg, rail: rail })] }));
43
+ }
44
+ /**
45
+ * Beside every page (`orgs.overlay`, the `orgs` slot's), outside the sidebar, which is a drawer
46
+ * on a phone: the line along the top while in an org as staff, the dialog that makes an org,
47
+ * and going into one.
48
+ */
49
+ export const overlayView = () => _jsx(Overlay, {});
50
+ function Overlay() {
51
+ const orgs = useOrgs();
52
+ const making = useSyncExternalStore(newOrg.subscribe, newOrg.get, newOrg.get);
53
+ const ready = orgs.status === "ready";
54
+ return (_jsxs(_Fragment, { children: [style, ready && asStaff(orgs.value)
55
+ ? (_jsx("div", { className: "pairz-staff-line", role: "note", children: _jsx("span", { className: "pairz-sr", children: say("staffLine") }) }))
56
+ : null, ready ? _jsx(NewOrg, { open: making, onClose: closeNewOrg }) : null, _jsx(Switching, {})] }));
57
+ }
58
+ /**
59
+ * What the shell's own parts list of the person's orgs (the `orgs` slot's hook): their email,
60
+ * the org's page and (for staff) every org in their menu, and orgs in the palette. Nothing until
61
+ * the orgs are known, or where the server serves one.
62
+ */
63
+ export function useShellOrgs(call) {
64
+ const orgs = useOrgs();
65
+ const ready = orgs.status === "ready";
66
+ const standing = useStanding(call, ready);
67
+ if (!ready)
68
+ return undefined;
69
+ const { value, here } = orgs;
70
+ return {
71
+ email: value.email,
72
+ menu: [
73
+ ...(here
74
+ ? [{
75
+ label: runs(standing) ? say("orgSettings") : say("aboutOrg"),
76
+ icon: "settings",
77
+ href: "/org",
78
+ }]
79
+ : []),
80
+ ...(value.staff
81
+ ? [{ label: say("allOrgsConsole"), icon: "server", href: "/console" }]
82
+ : []),
83
+ ],
84
+ palette: orgsPalette(value, here, standing),
85
+ };
86
+ }
87
+ /** Whether the dialog that makes an org is open: the switcher opens it, the overlay draws it. */
88
+ let making = false;
89
+ const makers = new Set();
90
+ const newOrg = {
91
+ subscribe(listener) {
92
+ makers.add(listener);
93
+ return () => makers.delete(listener);
94
+ },
95
+ get: () => making,
96
+ };
97
+ const setMaking = (open) => {
98
+ making = open;
99
+ for (const listener of makers)
100
+ listener();
101
+ };
102
+ /** Opens the dialog that makes an org. */
103
+ export const openNewOrg = () => setMaking(true);
104
+ const closeNewOrg = () => setMaking(false);
105
+ /** The words a phrase gives to find an item by (its keywords), apart. */
106
+ const keywords = (key) => say(key).split(/\s+/).filter(Boolean);
107
+ /** An org's face: yours (Personal) is you; a team's, its initials. */
108
+ export function OrgFace({ org, person, size = 26 }) {
109
+ return org.kind === "personal"
110
+ ? _jsx(Avatar, { name: person, size: size })
111
+ : _jsx(Avatar, { name: org.name, kind: "org", size: size, ...(org.id ? { tint: org.id } : {}) });
112
+ }
113
+ /** What the switcher says under the org's name: your standing there. */
114
+ function subline(org, standing, staff) {
115
+ if (staff)
116
+ return say("staffAccess");
117
+ if (org?.kind === "personal")
118
+ return say("justYou");
119
+ return standingName(standing) || " ";
120
+ }
121
+ export function OrgSwitcher({ orgs, here, standing, staff, onNew, rail }) {
122
+ const [failed, setFailed] = useState();
123
+ /** Goes in or back as staff: the page starts over, or it stays and says why. */
124
+ const switchTo = (org, staff) => {
125
+ setFailed(undefined);
126
+ enterOrg(org, staff).catch((e) => setFailed(message(e)));
127
+ };
128
+ const waiting = orgs.invites.length;
129
+ const name = here ? orgName(here) : say("organization");
130
+ const mine = [...orgs.orgs].sort((a, b) => Number(b.kind === "personal") - Number(a.kind === "personal") ||
131
+ a.name.localeCompare(b.name, undefined, { sensitivity: "base" }));
132
+ const face = here
133
+ ? _jsx(OrgFace, { org: here, person: orgs.person, size: 28 })
134
+ : _jsx(Avatar, { name: name, kind: "org", size: 28 });
135
+ const title = staff ? say("inAsStaffTitle", { name }) : say("switchOrg", { name });
136
+ return (_jsx(Popover, { label: say("yourOrgs"), width: 312, className: "pairz-orgs", ...(rail ? { side: "end", align: "start" } : {}), trigger: (props) => rail
137
+ ? (_jsx(RailItem, { ...props, className: "pairz-org-rail", "data-staff": staff || undefined, leading: face,
138
+ // Staff hear first that they're in as staff; anyone else, what waits for them.
139
+ label: waiting && !staff ? say("switchOrgWaiting", { name, count: waiting }) : title, badge: waiting, tooltip: !props["aria-expanded"] }))
140
+ : (_jsxs("button", { type: "button", ...props, className: "pairz-org", "data-staff": staff || undefined, title: title, children: [face, _jsxs("span", { className: "pairz-org-text", children: [_jsx("span", { className: "pairz-org-name", children: name }), _jsxs("span", { className: "pairz-org-sub", children: [staff ? _jsx(Icon, { name: "shield", size: 12 }) : null, subline(here, standing, staff)] })] }), waiting
141
+ ? (_jsx("span", { className: "pairz-org-dot", "aria-label": say("invitationsCount", { count: waiting }), children: waiting }))
142
+ : null, _jsx(Icon, { name: "selector", size: 15, className: "pairz-org-chevron" })] })), children: (close) => (_jsxs("div", { className: "pairz-orgs-box", children: [_jsx("p", { className: "pairz-orgs-who", children: say.nodes("signedInAs", { who: _jsx("b", { children: orgs.email ?? orgs.person }) }) }), staff && here
143
+ ? (_jsxs("div", { className: "pairz-orgs-staff", children: [_jsx(Icon, { name: "shield", size: 15 }), _jsxs("span", { children: [say.nodes("inAsStaff", { name: _jsx("b", { children: here.name }) }), standing?.role
144
+ ? (_jsx("button", { type: "button", "data-popover-item": true, className: "pairz-orgs-staff-back", onClick: () => switchTo(here, false), children: say("continueAs", { role: standingName(standing) }) }))
145
+ : null] })] }))
146
+ : null, failed ? _jsx(Notice, { tone: "destructive", role: "alert", children: failed }) : null, _jsx("ul", { className: "pairz-orgs-list", "aria-label": say("organizations"), children: mine.map((org) => (_jsx("li", { children: _jsx(OrgRow, { org: org, person: orgs.person, current: org.id === orgs.current, close: close }) }, org.id))) }), waiting
147
+ ? (_jsxs("section", { className: "pairz-orgs-invites", "aria-labelledby": "pairz-orgs-invites", children: [_jsxs("h3", { id: "pairz-orgs-invites", children: [say("invitations"), " ", _jsx(Badge, { tone: "primary", children: waiting })] }), _jsx("ul", { children: orgs.invites.map((invite) => (_jsx("li", { children: _jsx(InviteRow, { invite: invite, close: close }) }, invite.id))) })] }))
148
+ : null, _jsxs("div", { className: "pairz-orgs-actions", children: [_jsxs("button", { type: "button", "data-popover-item": true, className: "pairz-orgs-action", onClick: () => {
149
+ close();
150
+ onNew();
151
+ }, children: [_jsx("span", { className: "pairz-orgs-icon pairz-orgs-icon-new", children: _jsx(Icon, { name: "plus", size: 15 }) }), say("newOrgMore")] }), here && (runs(standing) || standing?.role)
152
+ ? (_jsxs("a", { "data-popover-item": true, className: "pairz-orgs-action", href: "/org", onClick: close, children: [_jsx("span", { className: "pairz-orgs-icon", children: _jsx(Icon, { name: "settings", size: 15 }) }), runs(standing) ? say("orgSettings") : say("aboutOrg")] }))
153
+ : null, orgs.staff && here && !staff
154
+ ? (_jsxs("button", { type: "button", "data-popover-item": true, className: "pairz-orgs-action", onClick: () => switchTo(here, true), children: [_jsx("span", { className: "pairz-orgs-icon", children: _jsx(Icon, { name: "shield", size: 15 }) }), say("enterAsStaff")] }))
155
+ : null, orgs.staff
156
+ ? (_jsxs("a", { "data-popover-item": true, className: "pairz-orgs-action", href: "/console", onClick: close, children: [_jsx("span", { className: "pairz-orgs-icon", children: _jsx(Icon, { name: "server", size: 15 }) }), say("allOrgsConsole")] }))
157
+ : null] })] })) }));
158
+ }
159
+ /** One of your orgs: going into it, or where you are (a check). A suspended one says so. */
160
+ function OrgRow({ org, person, current, close }) {
161
+ const [error, setError] = useState();
162
+ const suspended = !!org.suspended && !current;
163
+ return (_jsxs("button", { type: "button", "data-popover-item": true, className: "pairz-orgs-row", "aria-current": current || undefined, "aria-disabled": suspended || undefined, title: suspended ? say("suspendedTitle", { name: org.name }) : undefined, onClick: () => {
164
+ if (suspended)
165
+ return;
166
+ if (current)
167
+ return close();
168
+ setError(undefined);
169
+ const going = enterOrg(org);
170
+ close();
171
+ going.catch((e) => setError(message(e)));
172
+ }, children: [_jsx(OrgFace, { org: org, person: person, size: 28 }), _jsxs("span", { className: "pairz-orgs-row-text", children: [_jsx("span", { className: "pairz-orgs-row-name", children: orgName(org) }), error
173
+ ? _jsx("span", { className: "pairz-orgs-row-error", children: error })
174
+ : org.kind === "personal"
175
+ ? _jsx("span", { className: "pairz-orgs-row-sub", children: say("yourOwn") })
176
+ : null] }), suspended ? _jsx(Badge, { tone: "warning", children: say("suspended") }) : null, current ? _jsx(Icon, { name: "check", size: 16, className: "pairz-orgs-check" }) : null] }));
177
+ }
178
+ /** An invitation to an org, answered in place: joining goes into it. */
179
+ function InviteRow({ invite, close }) {
180
+ const [busy, setBusy] = useState();
181
+ const [error, setError] = useState();
182
+ const answer = (accept) => {
183
+ setBusy(accept ? "join" : "decline");
184
+ setError(undefined);
185
+ const answered = answerOrgInvite(invite, accept);
186
+ // Joining goes into it: the transition shows over everything.
187
+ if (accept)
188
+ close();
189
+ answered.catch((e) => {
190
+ setError(message(e));
191
+ setBusy(undefined);
192
+ });
193
+ };
194
+ return (_jsxs("div", { className: "pairz-orgs-invite", children: [_jsx(Avatar, { name: invite.name, kind: "org", size: 28, tint: invite.org }), _jsxs("div", { className: "pairz-orgs-invite-text", children: [_jsx("p", { className: "pairz-orgs-invite-name", children: invite.name }), _jsx("p", { className: "pairz-orgs-invite-meta", children: error ?? say.nodes(invite.from ? "invitedFromAsAt" : "invitedAsAt", {
195
+ from: invite.from ?? "",
196
+ role: orgRoleName(invite.role).toLocaleLowerCase(lang()),
197
+ time: _jsx(Time, { at: invite.at }),
198
+ }) }), _jsxs("div", { className: "pairz-orgs-invite-answers", children: [_jsx(Button, { size: "sm", variant: "primary", "data-popover-item": true, loading: busy === "join", disabled: !!busy, onClick: () => answer(true), children: say("join") }), _jsx(Button, { size: "sm", variant: "ghost", "data-popover-item": true, loading: busy === "decline", disabled: !!busy, onClick: () => answer(false), children: say("decline") })] })] })] }));
199
+ }
200
+ /** Names longer than this aren't taken. */
201
+ const LONGEST = 80;
202
+ /** The small dialog that makes a team org: its name, then you're in it, its owner. */
203
+ export function NewOrg({ open, onClose }) {
204
+ const [name, setName] = useState("");
205
+ const [busy, setBusy] = useState(false);
206
+ const [error, setError] = useState();
207
+ useEffect(() => {
208
+ if (!open) {
209
+ setName("");
210
+ setError(undefined);
211
+ setBusy(false);
212
+ }
213
+ }, [open]);
214
+ const typed = name.trim();
215
+ const long = typed.length > LONGEST;
216
+ const create = async (event) => {
217
+ event?.preventDefault();
218
+ if (!typed || long || busy)
219
+ return;
220
+ setBusy(true);
221
+ setError(undefined);
222
+ try {
223
+ await createOrg(typed);
224
+ }
225
+ catch (e) {
226
+ setError(message(e));
227
+ setBusy(false);
228
+ }
229
+ };
230
+ return (_jsx(Dialog, { open: open, onClose: onClose, size: "sm", title: say("newOrg"), description: say("newOrgAbout"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: onClose, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "primary", loading: busy, disabled: !typed || long, onClick: () => void create(), children: say("createOrg") })] }), children: _jsxs("form", { onSubmit: create, className: "pairz-new-org", children: [_jsx("div", { className: "pairz-new-org-preview", "aria-hidden": "true", children: _jsx(Avatar, { name: typed || "?", kind: "org", size: 44 }) }), _jsx(Field, { label: say("name"), hint: long ? undefined : say("newOrgNameHint"), error: long ? say("atMost", { count: LONGEST }) : error, children: (control) => (_jsx(Input, { ...control, value: name, onChange: (e) => setName(e.target.value), placeholder: say("newOrgPlaceholder"), autoComplete: "organization", maxLength: LONGEST + 20, autoFocus: true })) })] }) }));
231
+ }
232
+ /** While the page goes into another org: its face and name, over everything, until it's there. */
233
+ export function Switching() {
234
+ const to = useSwitching();
235
+ const [welcome, setWelcome] = useState();
236
+ const layer = useRef(null);
237
+ // Over everything, a dialog that started it included: a modal of its own, on top.
238
+ useEffect(() => {
239
+ if (to && !layer.current?.open)
240
+ layer.current?.showModal();
241
+ }, [to]);
242
+ useEffect(() => {
243
+ const came = arrived();
244
+ if (!came)
245
+ return;
246
+ setWelcome(came);
247
+ const done = setTimeout(() => setWelcome(undefined), came.staff || came.moved ? 5200 : 2600);
248
+ return () => clearTimeout(done);
249
+ }, []);
250
+ return (_jsxs(_Fragment, { children: [to
251
+ ? (_jsx("dialog", { ref: layer, className: "pairz-switching", "aria-live": "assertive", "aria-label": say("goingInto", { name: orgName(to) }),
252
+ // It ends when the page starts over, not on Escape.
253
+ onCancel: (event) => event.preventDefault(), children: _jsxs("div", { className: "pairz-switching-box", children: [to.kind === "personal"
254
+ ? (_jsx("span", { className: "pairz-switching-personal", children: _jsx(Icon, { name: "person", size: 26 }) }))
255
+ : (_jsx(Avatar, { name: to.name, kind: "org", size: 56, ...(to.id ? { tint: to.id } : {}) })), _jsx("p", { className: "pairz-switching-label", children: to.staff ? say("enteringAsStaff") : say("switchingTo") }), _jsx("p", { className: "pairz-switching-name", children: orgName(to) }), _jsx(Spinner, { variant: "dots", size: 6 })] }) }))
256
+ : null, welcome && !to
257
+ ? (_jsxs("div", { className: "pairz-arrived", role: "status", "data-staff": welcome.staff || undefined, "data-long": welcome.staff || welcome.moved || undefined, children: [welcome.staff
258
+ ? _jsx(Icon, { name: "shield", size: 16 })
259
+ : _jsx(Icon, { name: welcome.moved ? "info" : "check", size: 16 }), _jsx("span", { children: welcome.staff
260
+ ? say.nodes("inAsStaff", { name: _jsx("b", { children: welcome.name }) })
261
+ : welcome.moved
262
+ ? say.nodes("movedOrg", { name: _jsx("b", { children: orgName(welcome) }) })
263
+ : say.nodes("youreIn", { name: _jsx("b", { children: orgName(welcome) }) }) })] }))
264
+ : null] }));
265
+ }
266
+ /** Making a team org from the palette: its name, then you're in it. */
267
+ const newOrgStep = () => ({
268
+ title: say("newOrg"),
269
+ placeholder: say("nameIt"),
270
+ note: say("newOrgAbout"),
271
+ filter: false,
272
+ items: (search) => {
273
+ const name = search.trim();
274
+ if (!name)
275
+ return [];
276
+ const long = name.length > LONGEST;
277
+ return [{
278
+ title: "",
279
+ items: [{
280
+ key: "org:create",
281
+ label: say("createNamed", { name }),
282
+ icon: "plus",
283
+ disabled: long,
284
+ ...(long ? { description: say("atMost", { count: LONGEST }) } : {}),
285
+ run: () => createOrg(name),
286
+ }],
287
+ }];
288
+ },
289
+ });
290
+ /**
291
+ * What the palette offers for orgs: the others to switch to, invitations to
292
+ * join or decline (with the spaces' own, under one heading), a new org, the
293
+ * org's settings, and for staff, every org.
294
+ */
295
+ export function orgsPalette(orgs, here, standing) {
296
+ const others = orgs.orgs.filter((o) => o.id !== orgs.current);
297
+ const groups = [{
298
+ title: say("organizations"),
299
+ order: 25,
300
+ items: [
301
+ ...others.map((org) => ({
302
+ key: `org:${org.id}`,
303
+ label: say("switchTo", { name: orgName(org) }),
304
+ leading: _jsx(OrgFace, { org: org, person: orgs.person, size: 26 }),
305
+ ...(org.suspended
306
+ ? { description: say("suspended"), disabled: true }
307
+ : org.kind === "personal"
308
+ ? { description: say("yourOwnOrg") }
309
+ : {}),
310
+ keywords: [...keywords("keysSwitch"), org.name],
311
+ run: () => enterOrg(org),
312
+ })),
313
+ {
314
+ key: "org:new",
315
+ label: say("newOrgMore"),
316
+ icon: "plus",
317
+ keywords: keywords("keysNewOrg"),
318
+ step: newOrgStep(),
319
+ },
320
+ ...(here
321
+ ? [{
322
+ key: "org:settings",
323
+ label: runs(standing) ? say("orgSettings") : say("aboutOrg"),
324
+ icon: "settings",
325
+ keywords: keywords("keysOrgSettings"),
326
+ href: "/org",
327
+ }]
328
+ : []),
329
+ ...(orgs.staff
330
+ ? [{
331
+ key: "org:console",
332
+ label: say("allOrgsConsole"),
333
+ icon: "server",
334
+ keywords: keywords("keysConsole"),
335
+ href: "/console",
336
+ }]
337
+ : []),
338
+ ],
339
+ }];
340
+ if (orgs.invites.length) {
341
+ groups.unshift({
342
+ title: say("invitations"),
343
+ order: 5,
344
+ items: orgs.invites.flatMap((invite) => [
345
+ {
346
+ key: `org-invite:${invite.id}`,
347
+ label: say("joinNamed", { name: invite.name }),
348
+ leading: _jsx(Avatar, { name: invite.name, kind: "org", size: 26, tint: invite.org }),
349
+ description: say(invite.from ? "invitedFromAs" : "invitedAs", {
350
+ from: invite.from ?? "",
351
+ role: orgRoleName(invite.role).toLocaleLowerCase(lang()),
352
+ }),
353
+ keywords: keywords("keysAcceptOrgInvite"),
354
+ run: () => answerOrgInvite(invite, true),
355
+ },
356
+ {
357
+ key: `org-decline:${invite.id}`,
358
+ label: say("declineOrgInvite", { name: invite.name }),
359
+ icon: "close",
360
+ keywords: keywords("keysOrgInvite"),
361
+ run: () => answerOrgInvite(invite, false),
362
+ },
363
+ ]),
364
+ });
365
+ }
366
+ return groups;
367
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The words of the directory's front end, in English: the org switcher, going between orgs, the
3
+ * org's page and staff's console keep the keys they had in the web shell (`shell.<key>`), so an
4
+ * app's own words for them still hold; what an org is called where it shows is `directory.<key>`.
5
+ */
6
+ import { type Phrase } from "pairz/web/words";
7
+ export declare const say: import("pairz/web/words").Say<"personal" | "team" | "placement" | "join" | "actions" | "staff" | "cancel" | "name" | "status" | "suspended" | "rename" | "people" | "spaces" | "active" | "goHome" | "staffLine" | "orgSettings" | "aboutOrg" | "allOrgsConsole" | "organization" | "oneOrg" | "oneOrgAbout" | "notInOrg" | "chooseOrg" | "personalOrg" | "teamOrg" | "staffAccess" | "orgAboutStaff" | "orgAboutPersonal" | "orgAboutRuns" | "orgAboutGuest" | "orgAboutMember" | "orgSection" | "heldBack" | "orgSettingsOf" | "nothingToSet" | "nothingToSetAbout" | "justYou" | "yourOrgs" | "organizations" | "inAsStaffTitle" | "switchOrg" | "switchOrgWaiting" | "invitationsCount" | "signedInAs" | "inAsStaff" | "continueAs" | "invitations" | "newOrgMore" | "enterAsStaff" | "suspendedTitle" | "yourOwn" | "invitedFromAsAt" | "invitedAsAt" | "invitedFromAs" | "invitedAs" | "joinNamed" | "decline" | "newOrg" | "newOrgAbout" | "createOrg" | "newOrgNameHint" | "atMost" | "newOrgPlaceholder" | "goingInto" | "enteringAsStaff" | "switchingTo" | "movedOrg" | "youreIn" | "nameIt" | "createNamed" | "switchTo" | "yourOwnOrg" | "declineOrgInvite" | "keysSwitch" | "keysNewOrg" | "keysOrgSettings" | "keysConsole" | "keysAcceptOrgInvite" | "keysOrgInvite" | "filterAll" | "filterTeams" | "giftCodes" | "consoleTitle" | "forStaff" | "forStaffAbout" | "consoleShows" | "giftCodesAbout" | "consoleAbout" | "refresh" | "teamOrgs" | "searchPlaceholder" | "searchOrgs" | "whichOrgs" | "lastActive" | "noMatch" | "nothingMatches" | "nothingYet" | "footAll" | "footSome" | "hereAsStaff" | "youreHere" | "copyOrgId" | "notYet" | "inItAsStaff" | "goIntoAsStaff" | "moreOf" | "renameMore" | "liftMore" | "suspendMore" | "moveMore" | "exportRows" | "deleteMore" | "unsupported" | "renamedTo" | "renameOrg" | "renameOrgAbout" | "liftTitle" | "suspendTitle" | "openAgain" | "isSuspended" | "lift" | "suspend" | "liftAbout" | "suspendAbout" | "nowLivesIn" | "moveTitle" | "moveAbout" | "moveRows" | "moveText" | "nowIn" | "newSchema" | "sameSchema" | "schemaRule" | "isDeleted" | "deleteTitle" | "deleteForGood" | "cantUndo" | "deleteAbout" | "exportFirst" | "typeToConfirm" | "codeWaiting" | "codeClaimed" | "codeRevoked" | "codeExpired" | "sayDollars" | "codesCount" | "newGiftCode" | "tryAgain" | "noCodes" | "noCodesAbout" | "termsLapse" | "termsNoLapse" | "termsLapseClaim" | "termsNoLapseClaim" | "codeShortTitle" | "codeMade" | "claimedBy" | "takeBack" | "makeCode" | "makeTheCode" | "credits" | "lapseOn" | "lapseHint" | "claimBy" | "claimHint" | "whatFor" | "whatForHint" | "notePlaceholder" | "yourCode" | "keptIt" | "copyCode" | "notShownAgain" | "notShownAgainAbout" | "takeBackTitle" | "takeItBack" | "takeBackAbout">;
8
+ export declare const sayOrg: import("pairz/web/words").Say<"personalOrg">;
9
+ /** Every word of the directory's front end, by area (WORDS.md lists them). */
10
+ export declare const PHRASES: Record<string, Record<string, Phrase>>;