@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.
- package/LICENSE +21 -0
- package/README.md +70 -1
- package/WORDS.md +198 -0
- package/actions/code.d.ts +4 -0
- package/actions/code.js +135 -0
- package/actions/host.d.ts +2 -0
- package/actions/host.js +55 -0
- package/actions/invite.d.ts +5 -0
- package/actions/invite.js +129 -0
- package/actions/org.d.ts +10 -0
- package/actions/org.js +273 -0
- package/collections/credit-code.d.ts +107 -0
- package/collections/credit-code.js +28 -0
- package/collections/invite.d.ts +74 -0
- package/collections/invite.js +20 -0
- package/collections/membership.d.ts +65 -0
- package/collections/membership.js +22 -0
- package/collections/org-host.d.ts +55 -0
- package/collections/org-host.js +30 -0
- package/collections/org.d.ts +134 -0
- package/collections/org.js +58 -0
- package/collections/staff.d.ts +35 -0
- package/collections/staff.js +12 -0
- package/contract.d.ts +8 -0
- package/contract.js +8 -0
- package/mod.d.ts +67 -0
- package/mod.js +123 -0
- package/package.json +63 -3
- package/routes/console.d.ts +26 -0
- package/routes/console.js +129 -0
- package/routes/enter.d.ts +18 -0
- package/routes/enter.js +47 -0
- package/routes/forward.d.ts +35 -0
- package/routes/forward.js +120 -0
- package/routes/orgs.d.ts +25 -0
- package/routes/orgs.js +113 -0
- package/routes/signout.d.ts +11 -0
- package/routes/signout.js +36 -0
- package/shared/enter.d.ts +36 -0
- package/shared/enter.js +82 -0
- package/shared/http.d.ts +44 -0
- package/shared/http.js +79 -0
- package/shared/member.d.ts +21 -0
- package/shared/member.js +73 -0
- package/shared/settings.d.ts +53 -0
- package/shared/settings.js +16 -0
- package/shared/state.d.ts +74 -0
- package/shared/state.js +101 -0
- package/views/web/codes.d.ts +27 -0
- package/views/web/codes.js +50 -0
- package/views/web/console-codes.d.ts +37 -0
- package/views/web/console-codes.js +166 -0
- package/views/web/console.d.ts +37 -0
- package/views/web/console.js +224 -0
- package/views/web/lists.d.ts +48 -0
- package/views/web/lists.js +42 -0
- package/views/web/org.d.ts +12 -0
- package/views/web/org.js +62 -0
- package/views/web/orgs.d.ts +148 -0
- package/views/web/orgs.js +253 -0
- package/views/web/style.d.ts +6 -0
- package/views/web/style.js +197 -0
- package/views/web/switcher.d.ts +81 -0
- package/views/web/switcher.js +367 -0
- package/views/web/words.d.ts +10 -0
- package/views/web/words.js +206 -0
- package/web.d.ts +36 -0
- package/web.js +57 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Gift codes in staff's console (at `/console?tab=codes`): making one (how many
|
|
4
|
+
* dollars of credits, when they lapse, the last day it can be claimed, what
|
|
5
|
+
* it's for), which shows the code just this once, with a way to copy it and a
|
|
6
|
+
* clear word that it won't be shown again, since only its hash is kept. Then
|
|
7
|
+
* every code, newest first: how much, for what, where it stands, which org
|
|
8
|
+
* claimed it; and taking back one nobody has claimed.
|
|
9
|
+
*/
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import { Badge, Button, CopyButton, Dialog, EmptyState, Field, Input, message, Notice, Skeleton, Time, } from "pairz/web";
|
|
12
|
+
import { createGiftCode, giftCodes, revokeGiftCode, } from "./orgs.js";
|
|
13
|
+
import { codeStatus, dayOf, dollarsOf, newCodeOf, statusOf } from "./codes.js";
|
|
14
|
+
import { say } from "./words.js";
|
|
15
|
+
const STYLE = `
|
|
16
|
+
.console-tabs { display: flex; margin-bottom: 18px; }
|
|
17
|
+
.codes { container: codes / inline-size; display: grid; gap: 14px; }
|
|
18
|
+
.codes-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
|
|
19
|
+
.codes-tools p { margin: 0; color: var(--muted-foreground); font-size: 13px; }
|
|
20
|
+
.codes-list { display: grid; margin: 0; padding: 0; list-style: none; border: 1px solid var(--border);
|
|
21
|
+
border-radius: var(--radius-lg); background: var(--card); overflow: hidden; }
|
|
22
|
+
.codes-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) minmax(120px, .8fr) 104px; align-items: center;
|
|
23
|
+
gap: 8px 16px; min-height: 56px; padding: 10px 14px; }
|
|
24
|
+
.codes-row + .codes-row { border-top: 1px solid var(--border); }
|
|
25
|
+
.codes-amount { font-family: var(--font-display); font-size: 17px; font-weight: 650; letter-spacing: -.01em;
|
|
26
|
+
font-variant-numeric: tabular-nums; }
|
|
27
|
+
.codes-what { display: grid; gap: 1px; min-width: 0; font-size: 13.5px; line-height: 1.4; }
|
|
28
|
+
.codes-what code { color: var(--secondary-foreground); font-size: 12px; }
|
|
29
|
+
.codes-what small { color: var(--muted-foreground); font-size: 12.5px; }
|
|
30
|
+
.codes-note { overflow: hidden; font-weight: 560; text-overflow: ellipsis; white-space: nowrap; }
|
|
31
|
+
.codes-end { display: flex; justify-content: flex-end; }
|
|
32
|
+
.codes-status { display: grid; justify-items: start; gap: 2px; min-width: 0; color: var(--muted-foreground); font-size: 12.5px; }
|
|
33
|
+
.codes-status span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
34
|
+
.codes-form { display: grid; gap: 14px; }
|
|
35
|
+
.codes-two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; align-items: start; }
|
|
36
|
+
.codes-money::before { content: "$"; color: var(--muted-foreground); font-size: 14.5px; }
|
|
37
|
+
.codes-shown { display: flex; align-items: center; gap: 6px; padding: 12px 8px 12px 14px; border: 1px solid var(--border);
|
|
38
|
+
border-radius: var(--radius-lg); background: var(--muted); }
|
|
39
|
+
.codes-shown code { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 14.5px; font-weight: 600; line-height: 1.5;
|
|
40
|
+
overflow-wrap: anywhere; user-select: all; }
|
|
41
|
+
.codes-once { display: grid; gap: 12px; }
|
|
42
|
+
.codes-text { margin: 0; color: var(--secondary-foreground); font-size: 14px; line-height: 1.55; }
|
|
43
|
+
@container codes (max-width: 620px) {
|
|
44
|
+
.codes-row { grid-template-columns: minmax(0, 1fr) auto; min-height: 0; }
|
|
45
|
+
.codes-what { grid-column: 1 / -1; grid-row: 2; }
|
|
46
|
+
.codes-status { grid-column: 1; grid-row: 3; }
|
|
47
|
+
.codes-end { grid-column: 2; grid-row: 1; }
|
|
48
|
+
}
|
|
49
|
+
@media (max-width: 480px) {
|
|
50
|
+
.codes-two { grid-template-columns: minmax(0, 1fr); }
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
export function GiftCodes({ orgs, ready }) {
|
|
54
|
+
const [codes, setCodes] = useState();
|
|
55
|
+
const [error, setError] = useState();
|
|
56
|
+
const [making, setMaking] = useState(false);
|
|
57
|
+
const [made, setMade] = useState();
|
|
58
|
+
const [revoking, setRevoking] = useState();
|
|
59
|
+
const load = async () => {
|
|
60
|
+
try {
|
|
61
|
+
setCodes(await giftCodes());
|
|
62
|
+
setError(undefined);
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
setError(message(e));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (ready)
|
|
70
|
+
void load();
|
|
71
|
+
}, [ready]);
|
|
72
|
+
const orgName = (id) => orgs.find((o) => o.id === id)?.name ?? id;
|
|
73
|
+
return (_jsxs("div", { className: "codes", children: [_jsx("style", { href: "console-codes", precedence: "pairz", children: STYLE }), _jsxs("div", { className: "codes-tools", children: [_jsx("p", { children: codes ? say("codesCount", { count: codes.length }) : " " }), _jsx(Button, { variant: "primary", icon: "plus", onClick: () => setMaking(true), children: say("newGiftCode") })] }), error && !codes
|
|
74
|
+
? (_jsx(Notice, { tone: "destructive", role: "alert", action: _jsx(Button, { size: "sm", onClick: () => void load(), children: say("tryAgain") }), children: error }))
|
|
75
|
+
: null, !codes && !error
|
|
76
|
+
? (_jsx("div", { className: "codes-list", "aria-busy": "true", children: [0, 1, 2].map((i) => _jsx(Skeleton, { height: 56, radius: "sm" }, i)) }))
|
|
77
|
+
: null, codes && !codes.length
|
|
78
|
+
? (_jsx(EmptyState, { icon: "star", title: say("noCodes"), action: _jsx(Button, { icon: "plus", onClick: () => setMaking(true), children: say("newGiftCode") }), children: say("noCodesAbout") }))
|
|
79
|
+
: null, codes?.length
|
|
80
|
+
? (_jsx("ul", { className: "codes-list", children: codes.map((code) => (_jsx(Row, { code: code, orgName: orgName, onRevoke: () => setRevoking(code) }, code.id))) }))
|
|
81
|
+
: null, _jsx(NewCode, { open: making, close: () => setMaking(false), onMade: (code, amount) => {
|
|
82
|
+
setMaking(false);
|
|
83
|
+
setMade({ code, amount });
|
|
84
|
+
void load();
|
|
85
|
+
} }), _jsx(ShownOnce, { made: made, close: () => setMade(undefined) }), _jsx(Revoke, { code: revoking, close: () => setRevoking(undefined), onDone: () => {
|
|
86
|
+
setRevoking(undefined);
|
|
87
|
+
void load();
|
|
88
|
+
} })] }));
|
|
89
|
+
}
|
|
90
|
+
export function Row({ code, orgName, onRevoke }) {
|
|
91
|
+
const status = codeStatus(code);
|
|
92
|
+
const { label, tone } = statusOf(status);
|
|
93
|
+
const claimBy = status === "waiting" && code.until ? dayOf(code.until) : undefined;
|
|
94
|
+
const terms = say(code.expires
|
|
95
|
+
? claimBy ? "termsLapseClaim" : "termsLapse"
|
|
96
|
+
: claimBy
|
|
97
|
+
? "termsNoLapseClaim"
|
|
98
|
+
: "termsNoLapse", { lapse: code.expires ? dayOf(code.expires) : "", until: claimBy ?? "" });
|
|
99
|
+
return (_jsxs("li", { className: "codes-row", children: [_jsx("span", { className: "codes-amount", children: dollarsOf(code.amount) }), _jsxs("span", { className: "codes-what", children: [code.note ? _jsx("span", { className: "codes-note", title: code.note, children: code.note }) : null, _jsx("small", { children: terms }), _jsxs("small", { children: [_jsx("code", { title: say("codeShortTitle"), children: code.short }), " ", say.nodes("codeMade", { time: _jsx(Time, { at: code.at }) })] })] }), _jsxs("span", { className: "codes-status", children: [_jsx(Badge, { tone: tone === "neutral" ? undefined : tone, children: label }), code.org
|
|
100
|
+
? (_jsx("span", { title: code.org, children: say("claimedBy", {
|
|
101
|
+
org: orgName(code.org),
|
|
102
|
+
day: code.claimed ? dayOf(code.claimed) : "",
|
|
103
|
+
}) }))
|
|
104
|
+
: null] }), _jsx("span", { className: "codes-end", children: status === "waiting"
|
|
105
|
+
? _jsx(Button, { size: "sm", onClick: onRevoke, children: say("takeBack") })
|
|
106
|
+
: null })] }));
|
|
107
|
+
}
|
|
108
|
+
const EMPTY = { amount: "", expires: "", until: "", note: "" };
|
|
109
|
+
export function NewCode({ open, close, onMade }) {
|
|
110
|
+
const [form, setForm] = useState(EMPTY);
|
|
111
|
+
const [busy, setBusy] = useState(false);
|
|
112
|
+
const [error, setError] = useState();
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!open)
|
|
115
|
+
return;
|
|
116
|
+
setForm(EMPTY);
|
|
117
|
+
setBusy(false);
|
|
118
|
+
setError(undefined);
|
|
119
|
+
}, [open]);
|
|
120
|
+
const asked = newCodeOf(form);
|
|
121
|
+
const ready = !("error" in asked);
|
|
122
|
+
const set = (field) => (event) => setForm((now) => ({ ...now, [field]: event.target.value }));
|
|
123
|
+
const go = async (event) => {
|
|
124
|
+
event?.preventDefault();
|
|
125
|
+
if ("error" in asked || busy)
|
|
126
|
+
return;
|
|
127
|
+
setBusy(true);
|
|
128
|
+
setError(undefined);
|
|
129
|
+
try {
|
|
130
|
+
const { code } = await createGiftCode(asked);
|
|
131
|
+
onMade(code, asked.amount);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
setError(message(e));
|
|
135
|
+
setBusy(false);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return (_jsx(Dialog, { open: open, onClose: close, title: say("newGiftCode"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "primary", loading: busy, disabled: !ready, onClick: () => void go(), children: ready ? say("makeCode", { amount: dollarsOf(asked.amount) }) : say("makeTheCode") })] }), children: _jsxs("form", { className: "codes-form", onSubmit: (event) => void go(event), children: [_jsx(Field, { label: say("credits"), children: (control) => (_jsx(Input, { ...control, autoFocus: true, inputMode: "decimal", placeholder: "25", className: "codes-money", value: form.amount, onChange: set("amount") })) }), _jsxs("div", { className: "codes-two", children: [_jsx(Field, { label: say("lapseOn"), hint: say("lapseHint"), children: (control) => (_jsx(Input, { ...control, type: "date", value: form.expires, onChange: set("expires") })) }), _jsx(Field, { label: say("claimBy"), hint: say("claimHint"), children: (control) => (_jsx(Input, { ...control, type: "date", value: form.until, onChange: set("until") })) })] }), _jsx(Field, { label: say("whatFor"), hint: say("whatForHint"), children: (control) => (_jsx(Input, { ...control, maxLength: 200, placeholder: say("notePlaceholder"), value: form.note, onChange: set("note") })) }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null] }) }));
|
|
139
|
+
}
|
|
140
|
+
/** The code, just this once. */
|
|
141
|
+
export function ShownOnce({ made, close }) {
|
|
142
|
+
return (_jsx(Dialog, { open: !!made, onClose: close, title: made ? say("yourCode", { amount: dollarsOf(made.amount) }) : "", footer: _jsx(Button, { variant: "primary", onClick: close, children: say("keptIt") }), children: made
|
|
143
|
+
? (_jsxs("div", { className: "codes-once", children: [_jsxs("div", { className: "codes-shown", children: [_jsx("code", { children: made.code }), _jsx(CopyButton, { text: made.code, label: say("copyCode") })] }), _jsx(Notice, { tone: "warning", title: say("notShownAgain"), children: say("notShownAgainAbout") })] }))
|
|
144
|
+
: null }));
|
|
145
|
+
}
|
|
146
|
+
export function Revoke({ code, close, onDone }) {
|
|
147
|
+
const [busy, setBusy] = useState(false);
|
|
148
|
+
const [error, setError] = useState();
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
setBusy(false);
|
|
151
|
+
setError(undefined);
|
|
152
|
+
}, [code]);
|
|
153
|
+
return (_jsxs(Dialog, { open: !!code, onClose: close, size: "sm", title: code ? say("takeBackTitle", { amount: dollarsOf(code.amount) }) : "", footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "destructive", loading: busy, onClick: async () => {
|
|
154
|
+
if (!code)
|
|
155
|
+
return;
|
|
156
|
+
setBusy(true);
|
|
157
|
+
try {
|
|
158
|
+
await revokeGiftCode(code.id);
|
|
159
|
+
onDone();
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
setError(message(e));
|
|
163
|
+
setBusy(false);
|
|
164
|
+
}
|
|
165
|
+
}, children: say("takeItBack") })] }), children: [_jsx("p", { className: "codes-text", children: say("takeBackAbout") }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null] }));
|
|
166
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform console (kind `console`, at `/console`), for staff where the
|
|
3
|
+
* app serves many orgs: every org, with what it last reported (its people,
|
|
4
|
+
* spaces, when it was last active), where its rows live and whether it's
|
|
5
|
+
* suspended; searched by name, id, schema or maker, and filtered by kind or
|
|
6
|
+
* status. For each: entering it as staff (on its record, as theirs), and
|
|
7
|
+
* from its menu renaming it, suspending it (nobody but staff goes in) or
|
|
8
|
+
* lifting that, moving its rows to a schema of its own, downloading them as
|
|
9
|
+
* SQL, and deleting it for good, which its exact name confirms. The console
|
|
10
|
+
* reads no org's content: only what the directory keeps. Its other tab (`?tab=codes`,
|
|
11
|
+
* console-codes.tsx): gift codes of credits, made, listed and taken back.
|
|
12
|
+
*/
|
|
13
|
+
import { type ReactNode } from "react";
|
|
14
|
+
import type { ViewContext } from "pairz";
|
|
15
|
+
import { type ConsoleOrg } from "./orgs.js";
|
|
16
|
+
export declare const consoleView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
|
|
17
|
+
/** What staff are doing to an org, in a dialog. */
|
|
18
|
+
export type Doing = {
|
|
19
|
+
what: "rename" | "suspend" | "move" | "delete";
|
|
20
|
+
org: ConsoleOrg;
|
|
21
|
+
};
|
|
22
|
+
/** One org in the console's table. */
|
|
23
|
+
export declare function Row({ org, here, inAsStaff, onDo }: {
|
|
24
|
+
org: ConsoleOrg;
|
|
25
|
+
here: boolean;
|
|
26
|
+
inAsStaff: boolean;
|
|
27
|
+
onDo(what: Doing["what"]): void;
|
|
28
|
+
}): ReactNode;
|
|
29
|
+
export type DialogProps = {
|
|
30
|
+
doing?: Doing;
|
|
31
|
+
close(): void;
|
|
32
|
+
finished(note: string): void;
|
|
33
|
+
};
|
|
34
|
+
export declare function RenameDialog({ doing, close, finished }: DialogProps): ReactNode;
|
|
35
|
+
export declare function SuspendDialog({ doing, close, finished }: DialogProps): ReactNode;
|
|
36
|
+
export declare function MoveDialog({ doing, close, finished }: DialogProps): ReactNode;
|
|
37
|
+
export declare function DeleteDialog({ doing, close, finished }: DialogProps): ReactNode;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The platform console (kind `console`, at `/console`), for staff where the
|
|
4
|
+
* app serves many orgs: every org, with what it last reported (its people,
|
|
5
|
+
* spaces, when it was last active), where its rows live and whether it's
|
|
6
|
+
* suspended; searched by name, id, schema or maker, and filtered by kind or
|
|
7
|
+
* status. For each: entering it as staff (on its record, as theirs), and
|
|
8
|
+
* from its menu renaming it, suspending it (nobody but staff goes in) or
|
|
9
|
+
* lifting that, moving its rows to a schema of its own, downloading them as
|
|
10
|
+
* SQL, and deleting it for good, which its exact name confirms. The console
|
|
11
|
+
* reads no org's content: only what the directory keeps. Its other tab (`?tab=codes`,
|
|
12
|
+
* console-codes.tsx): gift codes of credits, made, listed and taken back.
|
|
13
|
+
*/
|
|
14
|
+
import { useEffect, useMemo, useState } from "react";
|
|
15
|
+
import { Avatar, Badge, Button, CopyButton, Dialog, EmptyState, Field, formatNumber, go, Icon, Input, Menu, message, Notice, Page, Skeleton, Tabs, Time, Title, } from "pairz/web";
|
|
16
|
+
import { consoleOrgs, deleteOrg, enterOrg, exportOrgUrl, moveOrg, updateOrg, useOrgs, } from "./orgs.js";
|
|
17
|
+
import { consoleList, consoleTotals, SCHEMA } from "./lists.js";
|
|
18
|
+
import { GiftCodes } from "./console-codes.js";
|
|
19
|
+
import { style } from "./switcher.js";
|
|
20
|
+
import { say } from "./words.js";
|
|
21
|
+
export const consoleView = (_, ctx) => (_jsxs(_Fragment, { children: [style, _jsx(Console, { tab: ctx.hints.query?.tab })] }));
|
|
22
|
+
const filters = () => [
|
|
23
|
+
{ value: "all", label: say("filterAll") },
|
|
24
|
+
{ value: "team", label: say("filterTeams") },
|
|
25
|
+
{ value: "personal", label: say("personal") },
|
|
26
|
+
{ value: "suspended", label: say("suspended") },
|
|
27
|
+
];
|
|
28
|
+
/** The console's tabs: the address says which (`?tab=codes`). */
|
|
29
|
+
const consoleTabs = () => [
|
|
30
|
+
{ value: "orgs", label: say("organizations"), icon: "building", href: "/console" },
|
|
31
|
+
{ value: "codes", label: say("giftCodes"), icon: "star", href: "/console?tab=codes" },
|
|
32
|
+
];
|
|
33
|
+
function Console({ tab }) {
|
|
34
|
+
const orgs = useOrgs();
|
|
35
|
+
const staff = orgs.status === "ready" && orgs.value.staff;
|
|
36
|
+
const [list, setList] = useState();
|
|
37
|
+
const [error, setError] = useState();
|
|
38
|
+
const [loading, setLoading] = useState(false);
|
|
39
|
+
const [search, setSearch] = useState("");
|
|
40
|
+
const [filter, setFilter] = useState("all");
|
|
41
|
+
const [doing, setDoing] = useState();
|
|
42
|
+
const [done, setDone] = useState();
|
|
43
|
+
const load = async () => {
|
|
44
|
+
setLoading(true);
|
|
45
|
+
try {
|
|
46
|
+
setList(await consoleOrgs());
|
|
47
|
+
setError(undefined);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
setError(message(e));
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
setLoading(false);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (staff)
|
|
58
|
+
void load();
|
|
59
|
+
}, [staff]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!done)
|
|
62
|
+
return;
|
|
63
|
+
const gone = setTimeout(() => setDone(undefined), 4000);
|
|
64
|
+
return () => clearTimeout(gone);
|
|
65
|
+
}, [done]);
|
|
66
|
+
const shown = useMemo(() => consoleList(list ?? [], search, filter), [list, search, filter]);
|
|
67
|
+
const totals = useMemo(() => consoleTotals(list ?? []), [list]);
|
|
68
|
+
if (orgs.status !== "loading" && !staff) {
|
|
69
|
+
return (_jsxs("div", { className: "pairz-org-missing", children: [_jsx(Title, { text: say("consoleTitle") }), _jsx(EmptyState, { icon: "lock", heading: "h1", title: say("forStaff"), action: _jsx(Button, { variant: "primary", href: "/", children: say("goHome") }), children: say("forStaffAbout") })] }));
|
|
70
|
+
}
|
|
71
|
+
const current = orgs.status === "ready" ? orgs.value.current : null;
|
|
72
|
+
const inAsStaff = orgs.status === "ready" && orgs.value.asStaff;
|
|
73
|
+
/** A dialog's closing ends what it was for, and nothing that started since. */
|
|
74
|
+
const closer = (what) => () => setDoing((now) => now?.what === what ? undefined : now);
|
|
75
|
+
const finished = (note) => {
|
|
76
|
+
setDoing(undefined);
|
|
77
|
+
setDone(note);
|
|
78
|
+
void load();
|
|
79
|
+
};
|
|
80
|
+
const tabs = (_jsx(Tabs, { label: say("consoleShows"), variant: "line", className: "console-tabs", value: tab === "codes" ? "codes" : "orgs", onChange: (next) => go(next === "codes" ? "/console?tab=codes" : "/console"), tabs: [...consoleTabs()] }));
|
|
81
|
+
if (tab === "codes") {
|
|
82
|
+
return (_jsxs(Page, { title: say("giftCodes"), icon: "server", width: "full", className: "console", badges: _jsx(Badge, { tone: "warning", children: say("staff") }), description: say("giftCodesAbout"), children: [_jsx(Title, { text: say("giftCodes") }), tabs, _jsx(GiftCodes, { orgs: list ?? [], ready: staff })] }));
|
|
83
|
+
}
|
|
84
|
+
return (_jsxs(Page, { title: say("organizations"), icon: "server", width: "full", className: "console", badges: _jsx(Badge, { tone: "warning", children: say("staff") }), description: say("consoleAbout"), actions: _jsx(Button, { size: "sm", icon: "refresh", loading: loading, onClick: () => void load(), children: say("refresh") }), children: [_jsx(Title, { text: say("consoleTitle") }), tabs, _jsxs("div", { className: "console-stats", "aria-busy": !list || undefined, children: [_jsx(Stat, { label: say("organizations"), value: list ? totals.orgs : undefined }), _jsx(Stat, { label: say("teamOrgs"), value: list ? totals.teams : undefined }), _jsx(Stat, { label: say("people"), value: list ? totals.people : undefined }), _jsx(Stat, { label: say("suspended"), value: list ? totals.suspended : undefined, tone: totals.suspended ? "warning" : undefined })] }), _jsxs("div", { className: "console-tools", children: [_jsx(Input, { icon: "search", type: "search", size: "sm", className: "console-search", placeholder: say("searchPlaceholder"), "aria-label": say("searchOrgs"), value: search, onChange: (e) => setSearch(e.target.value) }), _jsx(Tabs, { label: say("whichOrgs"), value: filter, onChange: setFilter, tabs: filters().map((f) => ({
|
|
85
|
+
...f,
|
|
86
|
+
...(list && f.value === "suspended" && totals.suspended
|
|
87
|
+
? { count: totals.suspended }
|
|
88
|
+
: {}),
|
|
89
|
+
})) })] }), error
|
|
90
|
+
? (_jsx(Notice, { tone: "destructive", role: "alert", className: "console-notice", children: error }))
|
|
91
|
+
: null, done
|
|
92
|
+
? (_jsx(Notice, { tone: "success", className: "console-notice", role: "status", children: done }))
|
|
93
|
+
: null, !list
|
|
94
|
+
? (_jsx("div", { className: "console-loading", "aria-busy": "true", children: [0, 1, 2, 3].map((i) => _jsx(Skeleton, { height: 52, radius: "md" }, i)) }))
|
|
95
|
+
: shown.length
|
|
96
|
+
? (_jsxs("div", { className: "console-table", role: "table", "aria-label": say("organizations"), children: [_jsxs("div", { className: "console-row console-head", role: "row", children: [_jsx("span", { role: "columnheader", children: say("organization") }), _jsx("span", { role: "columnheader", className: "console-num", children: say("people") }), _jsx("span", { role: "columnheader", className: "console-num", children: say("spaces") }), _jsx("span", { role: "columnheader", children: say("lastActive") }), _jsx("span", { role: "columnheader", children: say("placement") }), _jsx("span", { role: "columnheader", children: say("status") }), _jsx("span", { role: "columnheader", className: "console-sr", children: say("actions") })] }), shown.map((org) => (_jsx(Row, { org: org, here: org.id === current, inAsStaff: org.id === current && inAsStaff, onDo: (what) => setDoing({ what, org }) }, org.id)))] }))
|
|
97
|
+
: (_jsx(EmptyState, { icon: "search", title: say("noMatch"), children: search ? say("nothingMatches", { search: search.trim() }) : say("nothingYet") })), list && shown.length
|
|
98
|
+
? (_jsx("p", { className: "console-foot", children: shown.length === list.length
|
|
99
|
+
? say("footAll", { count: list.length })
|
|
100
|
+
: say("footSome", { shown: shown.length, total: list.length }) }))
|
|
101
|
+
: null, _jsx(RenameDialog, { doing: doing, close: closer("rename"), finished: finished }), _jsx(SuspendDialog, { doing: doing, close: closer("suspend"), finished: finished }), _jsx(MoveDialog, { doing: doing, close: closer("move"), finished: finished }), _jsx(DeleteDialog, { doing: doing, close: closer("delete"), finished: finished })] }));
|
|
102
|
+
}
|
|
103
|
+
function Stat({ label, value, tone }) {
|
|
104
|
+
return (_jsxs("div", { className: "console-stat", "data-tone": tone, children: [_jsx("span", { className: "console-stat-label", children: label }), value === undefined
|
|
105
|
+
? _jsx(Skeleton, { height: 26, width: 48 })
|
|
106
|
+
: _jsx("span", { className: "console-stat-value", children: formatNumber(value) })] }));
|
|
107
|
+
}
|
|
108
|
+
/** One org in the console's table. */
|
|
109
|
+
export function Row({ org, here, inAsStaff, onDo }) {
|
|
110
|
+
const [entering, setEntering] = useState(false);
|
|
111
|
+
const [error, setError] = useState();
|
|
112
|
+
const people = org.summary?.people ?? org.members;
|
|
113
|
+
const enter = () => {
|
|
114
|
+
setEntering(true);
|
|
115
|
+
setError(undefined);
|
|
116
|
+
enterOrg(org, true).catch((e) => {
|
|
117
|
+
setError(message(e));
|
|
118
|
+
setEntering(false);
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
return (_jsxs("div", { className: "console-row", role: "row", "data-suspended": org.suspended || undefined, children: [_jsxs("span", { role: "cell", className: "console-org", children: [org.kind === "personal"
|
|
122
|
+
? _jsx(Avatar, { name: org.by, size: 30 })
|
|
123
|
+
: _jsx(Avatar, { name: org.name, kind: "org", size: 30, tint: org.id }), _jsxs("span", { className: "console-org-text", children: [_jsxs("span", { className: "console-org-name", children: [org.name, here
|
|
124
|
+
? _jsx(Badge, { tone: "primary", children: inAsStaff ? say("hereAsStaff") : say("youreHere") })
|
|
125
|
+
: null] }), _jsxs("span", { className: "console-org-meta", children: [_jsx("span", { className: "console-kind", children: org.kind === "personal" ? say("personal") : say("team") }), _jsx("span", { "aria-hidden": "true", children: "\u00B7" }), _jsx("code", { title: org.id, children: org.id }), _jsx(CopyButton, { text: org.id, label: say("copyOrgId") })] }), error ? _jsx("span", { className: "console-error", children: error }) : null] })] }), _jsx("span", { role: "cell", className: "console-num", "data-label": say("people"), children: formatNumber(people) }), _jsx("span", { role: "cell", className: "console-num", "data-label": say("spaces"), children: org.summary?.spaces === undefined ? "—" : formatNumber(org.summary.spaces) }), _jsx("span", { role: "cell", className: "console-active", "data-label": say("lastActive"), children: org.summary?.active ? _jsx(Time, { at: org.summary.active }) : _jsx("span", { children: say("notYet") }) }), _jsxs("span", { role: "cell", className: "console-placement", "data-label": say("placement"), children: [_jsx(Icon, { name: "server", size: 13 }), _jsx("code", { children: org.placement?.schema ?? "—" })] }), _jsx("span", { role: "cell", "data-label": say("status"), children: org.suspended
|
|
126
|
+
? _jsx(Badge, { tone: "warning", variant: "soft", children: say("suspended") })
|
|
127
|
+
: _jsx(Badge, { tone: "success", variant: "soft", children: say("active") }) }), _jsxs("span", { role: "cell", className: "console-actions", children: [_jsx(Button, { size: "sm", icon: "enter", loading: entering, disabled: inAsStaff, onClick: enter, title: inAsStaff ? say("inItAsStaff") : say("goIntoAsStaff", { name: org.name }), children: say("enterAsStaff") }), _jsx(Menu, { label: say("moreOf", { name: org.name }), align: "end", size: "sm", items: [
|
|
128
|
+
{ label: say("renameMore"), icon: "pencil", onSelect: () => onDo("rename") },
|
|
129
|
+
org.suspended
|
|
130
|
+
? { label: say("liftMore"), icon: "play", onSelect: () => onDo("suspend") }
|
|
131
|
+
: { label: say("suspendMore"), icon: "pause", onSelect: () => onDo("suspend") },
|
|
132
|
+
{ label: say("moveMore"), icon: "move", onSelect: () => onDo("move") },
|
|
133
|
+
{ label: say("exportRows"), icon: "download", href: exportOrgUrl(org.id) },
|
|
134
|
+
"separator",
|
|
135
|
+
{
|
|
136
|
+
label: say("deleteMore"),
|
|
137
|
+
icon: "trash",
|
|
138
|
+
tone: "destructive",
|
|
139
|
+
onSelect: () => onDo("delete"),
|
|
140
|
+
},
|
|
141
|
+
] })] })] }));
|
|
142
|
+
}
|
|
143
|
+
/** Doing something to an org in a dialog: busy while it goes, and why it failed if it does. */
|
|
144
|
+
function useAct(doing) {
|
|
145
|
+
const [busy, setBusy] = useState(false);
|
|
146
|
+
const [error, setError] = useState();
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
setBusy(false);
|
|
149
|
+
setError(undefined);
|
|
150
|
+
}, [doing]);
|
|
151
|
+
const act = async (run, then) => {
|
|
152
|
+
setBusy(true);
|
|
153
|
+
setError(undefined);
|
|
154
|
+
try {
|
|
155
|
+
await run();
|
|
156
|
+
then();
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
const code = e.code;
|
|
160
|
+
setError(code === "unsupported" ? say("unsupported", { reason: message(e) }) : message(e));
|
|
161
|
+
setBusy(false);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
return { busy, error, act };
|
|
165
|
+
}
|
|
166
|
+
export function RenameDialog({ doing, close, finished }) {
|
|
167
|
+
const open = doing?.what === "rename";
|
|
168
|
+
const org = doing?.org;
|
|
169
|
+
const [name, setName] = useState("");
|
|
170
|
+
const { busy, error, act } = useAct(doing);
|
|
171
|
+
useEffect(() => setName(org?.name ?? ""), [doing]);
|
|
172
|
+
const typed = name.trim();
|
|
173
|
+
const save = (event) => {
|
|
174
|
+
event?.preventDefault();
|
|
175
|
+
if (!org || !typed || typed === org.name)
|
|
176
|
+
return;
|
|
177
|
+
void act(() => updateOrg(org.id, { name: typed }), () => finished(say("renamedTo", { name: typed })));
|
|
178
|
+
};
|
|
179
|
+
return (_jsx(Dialog, { open: open, onClose: close, size: "sm", title: say("renameOrg"), description: org ? say("renameOrgAbout") : undefined, footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "primary", loading: busy, disabled: !typed || typed === org?.name, onClick: () => save(), children: say("rename") })] }), children: _jsx("form", { onSubmit: save, children: _jsx(Field, { label: say("name"), error: error, children: (control) => (_jsx(Input, { ...control, value: name, onChange: (e) => setName(e.target.value), maxLength: 100, autoFocus: true })) }) }) }));
|
|
180
|
+
}
|
|
181
|
+
export function SuspendDialog({ doing, close, finished }) {
|
|
182
|
+
const open = doing?.what === "suspend";
|
|
183
|
+
const org = doing?.org;
|
|
184
|
+
const lifting = !!org?.suspended;
|
|
185
|
+
const { busy, error, act } = useAct(doing);
|
|
186
|
+
return (_jsxs(Dialog, { open: open, onClose: close, size: "sm", title: org ? say(lifting ? "liftTitle" : "suspendTitle", { name: org.name }) : "", footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: lifting ? "primary" : "destructive", loading: busy, onClick: () => org &&
|
|
187
|
+
void act(() => updateOrg(org.id, { suspended: !lifting }), () => finished(say(lifting ? "openAgain" : "isSuspended", { name: org.name }))), children: lifting ? say("lift") : say("suspend") })] }), children: [_jsx("p", { className: "console-dialog-text", children: lifting ? say("liftAbout") : say("suspendAbout") }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null] }));
|
|
188
|
+
}
|
|
189
|
+
export function MoveDialog({ doing, close, finished }) {
|
|
190
|
+
const open = doing?.what === "move";
|
|
191
|
+
const org = doing?.org;
|
|
192
|
+
const [schema, setSchema] = useState("");
|
|
193
|
+
const { busy, error, act } = useAct(doing);
|
|
194
|
+
useEffect(() => setSchema(org ? `org_${org.id.replace(/[^a-z0-9]/gi, "_").toLowerCase()}` : ""), [
|
|
195
|
+
doing,
|
|
196
|
+
]);
|
|
197
|
+
const typed = schema.trim();
|
|
198
|
+
const bad = typed !== "" && !SCHEMA.test(typed);
|
|
199
|
+
const same = typed === org?.placement?.schema;
|
|
200
|
+
const move = (event) => {
|
|
201
|
+
event?.preventDefault();
|
|
202
|
+
if (!org || !typed || bad || same)
|
|
203
|
+
return;
|
|
204
|
+
void act(() => moveOrg(org.id, typed), () => finished(say("nowLivesIn", { name: org.name, schema: typed })));
|
|
205
|
+
};
|
|
206
|
+
return (_jsx(Dialog, { open: open, onClose: close, title: org ? say("moveTitle", { name: org.name }) : "", description: say("moveAbout"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "primary", loading: busy, disabled: !typed || bad || same, onClick: () => move(), children: say("moveRows") })] }), children: _jsxs("form", { onSubmit: move, className: "console-move", children: [_jsx("p", { className: "console-dialog-text", children: say("moveText") }), _jsxs("div", { className: "console-move-from", children: [_jsx("span", { children: say("nowIn") }), _jsx("code", { children: org?.placement?.schema ?? "—" })] }), _jsx(Field, { label: say("newSchema"), hint: same ? say("sameSchema") : say("schemaRule"), error: bad ? say("schemaRule") : error, children: (control) => (_jsx(Input, { ...control, value: schema, onChange: (e) => setSchema(e.target.value), spellCheck: false, autoCapitalize: "none", className: "console-mono", autoFocus: true })) })] }) }));
|
|
207
|
+
}
|
|
208
|
+
export function DeleteDialog({ doing, close, finished }) {
|
|
209
|
+
const open = doing?.what === "delete";
|
|
210
|
+
const org = doing?.org;
|
|
211
|
+
const [typed, setTyped] = useState("");
|
|
212
|
+
const { busy, error, act } = useAct(doing);
|
|
213
|
+
useEffect(() => setTyped(""), [doing]);
|
|
214
|
+
const matches = !!org && typed === org.name;
|
|
215
|
+
const remove = (event) => {
|
|
216
|
+
event?.preventDefault();
|
|
217
|
+
if (!org || !matches)
|
|
218
|
+
return;
|
|
219
|
+
void act(() => deleteOrg(org.id, typed), () => finished(say("isDeleted", { name: org.name })));
|
|
220
|
+
};
|
|
221
|
+
return (_jsx(Dialog, { open: open, onClose: close, title: org ? say("deleteTitle", { name: org.name }) : "", footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", onClick: close, disabled: busy, children: say("cancel") }), _jsx(Button, { variant: "destructive", icon: "trash", loading: busy, disabled: !matches, onClick: () => remove(), children: say("deleteForGood") })] }), children: _jsxs("form", { onSubmit: remove, className: "console-delete", children: [_jsx(Notice, { tone: "destructive", icon: "alert", title: say("cantUndo"), children: say("deleteAbout") }), org
|
|
222
|
+
? (_jsxs("a", { className: "console-export", href: exportOrgUrl(org.id), download: true, children: [_jsx(Icon, { name: "download", size: 15 }), say("exportFirst")] }))
|
|
223
|
+
: null, _jsx(Field, { label: say.nodes("typeToConfirm", { name: _jsx("b", { className: "console-name", children: org?.name }) }), error: error, children: (control) => (_jsx(Input, { ...control, value: typed, onChange: (e) => setTyped(e.target.value), autoComplete: "off", spellCheck: false, autoFocus: true })) })] }) }));
|
|
224
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orgs as the directory's front end lists them: someone's standing in a word,
|
|
3
|
+
* the org page's sections (the shell's `orgSettings` resource) in their order
|
|
4
|
+
* and for whom, and the console's orgs as staff search and sort them. Pure.
|
|
5
|
+
*/
|
|
6
|
+
import { type OrgSection, type Standing } from "pairz/plugins/interfaces/contract";
|
|
7
|
+
/** How someone stands, in a word: their role ("Owner"), or "Staff" for staff who aren't in it. */
|
|
8
|
+
export declare const standingName: (standing: Standing | undefined) => string;
|
|
9
|
+
/** The sections someone sees, in their order (lowest first), each with its key. */
|
|
10
|
+
export declare function sectionsOf(given: unknown, standing: Standing | undefined): (OrgSection & {
|
|
11
|
+
key: string;
|
|
12
|
+
})[];
|
|
13
|
+
/** The section the address asks for (`?tab=`), or the first. */
|
|
14
|
+
export declare const chosenSection: <S extends {
|
|
15
|
+
key: string;
|
|
16
|
+
}>(sections: S[], asked?: string) => S;
|
|
17
|
+
/** An org as staff's console lists it. */
|
|
18
|
+
export type Listed = {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
members: number;
|
|
23
|
+
suspended?: boolean;
|
|
24
|
+
placement?: {
|
|
25
|
+
schema: string;
|
|
26
|
+
};
|
|
27
|
+
summary?: {
|
|
28
|
+
people?: number;
|
|
29
|
+
spaces?: number;
|
|
30
|
+
active?: string;
|
|
31
|
+
};
|
|
32
|
+
at: string;
|
|
33
|
+
};
|
|
34
|
+
/** Which orgs the console shows. */
|
|
35
|
+
export type ConsoleFilter = "all" | "team" | "personal" | "suspended";
|
|
36
|
+
/** The orgs matching what's typed (name, id, schema, who made it) and the filter, busiest first. */
|
|
37
|
+
export declare function consoleList<O extends Listed & {
|
|
38
|
+
by?: string;
|
|
39
|
+
}>(orgs: O[], search: string, filter: ConsoleFilter): O[];
|
|
40
|
+
/** The console's totals: orgs, those of teams, people across them, and those suspended. */
|
|
41
|
+
export declare function consoleTotals(orgs: Listed[]): {
|
|
42
|
+
orgs: number;
|
|
43
|
+
teams: number;
|
|
44
|
+
people: number;
|
|
45
|
+
suspended: number;
|
|
46
|
+
};
|
|
47
|
+
/** A schema name the console takes for moving an org: lowercase letters, digits and `_`. */
|
|
48
|
+
export declare const SCHEMA: RegExp;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Orgs as the directory's front end lists them: someone's standing in a word,
|
|
3
|
+
* the org page's sections (the shell's `orgSettings` resource) in their order
|
|
4
|
+
* and for whom, and the console's orgs as staff search and sort them. Pure.
|
|
5
|
+
*/
|
|
6
|
+
import { orgRoleName } from "pairz/plugins/interfaces/contract";
|
|
7
|
+
import { say } from "./words.js";
|
|
8
|
+
/** How someone stands, in a word: their role ("Owner"), or "Staff" for staff who aren't in it. */
|
|
9
|
+
export const standingName = (standing) => !standing ? "" : standing.role ? orgRoleName(standing.role) : standing.staff ? say("staff") : "";
|
|
10
|
+
/** The sections someone sees, in their order (lowest first), each with its key. */
|
|
11
|
+
export function sectionsOf(given, standing) {
|
|
12
|
+
return Object.entries((given ?? {}))
|
|
13
|
+
.flatMap(([key, section]) => section?.view && section.title ? [{ ...section, key }] : [])
|
|
14
|
+
.filter((section) => standing?.staff || !section.roles ||
|
|
15
|
+
(!!standing?.role && section.roles.includes(standing.role)))
|
|
16
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0) || a.key.localeCompare(b.key));
|
|
17
|
+
}
|
|
18
|
+
/** The section the address asks for (`?tab=`), or the first. */
|
|
19
|
+
export const chosenSection = (sections, asked) => sections.find((s) => s.key === asked) ?? sections[0];
|
|
20
|
+
/** The orgs matching what's typed (name, id, schema, who made it) and the filter, busiest first. */
|
|
21
|
+
export function consoleList(orgs, search, filter) {
|
|
22
|
+
const words = search.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
23
|
+
return orgs
|
|
24
|
+
.filter((o) => filter === "all" || (filter === "suspended" ? !!o.suspended : o.kind === filter))
|
|
25
|
+
.filter((o) => {
|
|
26
|
+
const text = [o.name, o.id, o.placement?.schema ?? "", o.by ?? ""].join(" ").toLowerCase();
|
|
27
|
+
return words.every((word) => text.includes(word));
|
|
28
|
+
})
|
|
29
|
+
.sort((a, b) => (b.summary?.active ?? b.at).localeCompare(a.summary?.active ?? a.at) ||
|
|
30
|
+
a.name.localeCompare(b.name));
|
|
31
|
+
}
|
|
32
|
+
/** The console's totals: orgs, those of teams, people across them, and those suspended. */
|
|
33
|
+
export function consoleTotals(orgs) {
|
|
34
|
+
return {
|
|
35
|
+
orgs: orgs.length,
|
|
36
|
+
teams: orgs.filter((o) => o.kind === "team").length,
|
|
37
|
+
people: orgs.reduce((n, o) => n + (o.summary?.people ?? o.members), 0),
|
|
38
|
+
suspended: orgs.filter((o) => o.suspended).length,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** A schema name the console takes for moving an org: lowercase letters, digits and `_`. */
|
|
42
|
+
export const SCHEMA = /^[a-z][a-z0-9_]{0,62}$/;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The org's page (kind `org`, at `/org`), where the app serves many orgs:
|
|
3
|
+
* its name and face, your standing there, then its sections, which front
|
|
4
|
+
* ends add (the `orgSettings` resource: spaces' About and Members, usage's
|
|
5
|
+
* Usage), each a tab the address says (`?tab=members`). A section's View
|
|
6
|
+
* gets item `{ _id }` (the org's id) and hints `{ org, role, staff, mode }`;
|
|
7
|
+
* each shows only to the roles it names (staff see them all). Owners and
|
|
8
|
+
* admins run it from here; the others see what it is, and who's in it.
|
|
9
|
+
*/
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
import type { ViewContext } from "pairz";
|
|
12
|
+
export declare const orgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
|
package/views/web/org.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Badge, Button, EmptyState, go, Icon, LazyView, Notice, Page, Skeleton, Tabs, Title, } from "pairz/web";
|
|
3
|
+
import { orgName, useOrgs } from "./orgs.js";
|
|
4
|
+
import { runs, useStanding } from "pairz/plugins/interfaces/contract";
|
|
5
|
+
import { chosenSection, sectionsOf, standingName } from "./lists.js";
|
|
6
|
+
import { OrgFace, style } from "./switcher.js";
|
|
7
|
+
import { say } from "./words.js";
|
|
8
|
+
export const orgView = (_, ctx) => (_jsxs(_Fragment, { children: [style, _jsx(OrgPage, { given: ctx.resources.orgSettings, tab: ctx.hints.query?.tab, call: ctx.call })] }));
|
|
9
|
+
/** The section's address. */
|
|
10
|
+
const tabPath = (key) => `/org?tab=${encodeURIComponent(key)}`;
|
|
11
|
+
function OrgPage({ given, tab, call }) {
|
|
12
|
+
const orgs = useOrgs();
|
|
13
|
+
const ready = orgs.status === "ready";
|
|
14
|
+
const standing = useStanding(call, ready);
|
|
15
|
+
if (orgs.status === "none") {
|
|
16
|
+
return (_jsxs("div", { className: "pairz-org-missing", children: [_jsx(Title, { text: say("organization") }), _jsx(EmptyState, { icon: "building", heading: "h1", title: say("oneOrg"), children: say("oneOrgAbout") })] }));
|
|
17
|
+
}
|
|
18
|
+
if (!ready || !standing) {
|
|
19
|
+
return (_jsx(Page, { title: _jsx(Skeleton, { width: 200, height: 30 }), width: "lg", children: _jsxs("div", { className: "pairz-org-loading", "aria-busy": "true", children: [_jsx(Skeleton, { height: 36, width: "60%" }), _jsx(Skeleton, { height: 72, radius: "xl" }), _jsx(Skeleton, { height: 72, radius: "xl" })] }) }));
|
|
20
|
+
}
|
|
21
|
+
const here = orgs.here;
|
|
22
|
+
if (!here) {
|
|
23
|
+
return (_jsxs("div", { className: "pairz-org-missing", children: [_jsx(Title, { text: say("organization") }), _jsx(EmptyState, { icon: "building", heading: "h1", title: say("notInOrg"), action: _jsx(Button, { variant: "primary", href: "/", children: say("goHome") }), children: say("chooseOrg") })] }));
|
|
24
|
+
}
|
|
25
|
+
const name = orgName(here);
|
|
26
|
+
const sections = sectionsOf(given, standing);
|
|
27
|
+
const section = chosenSection(sections, tab);
|
|
28
|
+
// Sent to a section that isn't theirs (a link in a message, for everyone): said, not silent.
|
|
29
|
+
const heldBack = tab && !sections.some((s) => s.key === tab)
|
|
30
|
+
? (given ?? {})[tab]?.title
|
|
31
|
+
: undefined;
|
|
32
|
+
const personal = here.kind === "personal";
|
|
33
|
+
return (_jsxs(Page, { title: name, width: "lg", className: "pairz-org-page", leading: _jsx(OrgFace, { org: here, person: orgs.value.person, size: 44 }), badges: _jsxs(_Fragment, { children: [_jsx(Badge, { variant: "outline", children: personal ? say("personalOrg") : say("teamOrg") }), standing.staff
|
|
34
|
+
? (_jsxs(Badge, { tone: "warning", children: [_jsx(Icon, { name: "shield", size: 12 }), say("staffAccess")] }))
|
|
35
|
+
: null, standing.role
|
|
36
|
+
? _jsx(Badge, { tone: runs(standing) ? "primary" : "neutral", children: standingName(standing) })
|
|
37
|
+
: null] }), description: standing.staff
|
|
38
|
+
? say("orgAboutStaff", { name: here.name })
|
|
39
|
+
: personal
|
|
40
|
+
? say("orgAboutPersonal")
|
|
41
|
+
: runs(standing)
|
|
42
|
+
? say("orgAboutRuns", { name: here.name })
|
|
43
|
+
: standing.role === "guest"
|
|
44
|
+
? say("orgAboutGuest", { name: here.name })
|
|
45
|
+
: say("orgAboutMember", { name: here.name }), children: [_jsx(Title, { text: section ? say("orgSection", { name, section: section.title }) : name }), heldBack
|
|
46
|
+
? (_jsx(Notice, { tone: "info", className: "pairz-org-held", children: say("heldBack", { section: heldBack }) }))
|
|
47
|
+
: null, sections.length
|
|
48
|
+
? (_jsxs(_Fragment, { children: [_jsx(Tabs, { label: say("orgSettingsOf", { name }), variant: "line", className: "pairz-org-tabs", value: section?.key ?? "", panel: "pairz-org-section", onChange: (key) => go(tabPath(key)), tabs: sections.map((s) => ({
|
|
49
|
+
value: s.key,
|
|
50
|
+
label: s.title,
|
|
51
|
+
...(s.icon ? { icon: s.icon } : {}),
|
|
52
|
+
href: tabPath(s.key),
|
|
53
|
+
})) }), _jsx("div", { id: "pairz-org-section", role: "tabpanel", className: "pairz-org-section", "data-section": section?.key, children: section
|
|
54
|
+
? (_jsx(LazyView, { kind: section.view, item: { _id: here.id }, hints: {
|
|
55
|
+
org: here,
|
|
56
|
+
role: standing.role,
|
|
57
|
+
staff: standing.staff,
|
|
58
|
+
mode: "page",
|
|
59
|
+
}, fallback: _jsxs("div", { className: "pairz-org-loading", "aria-busy": "true", children: [_jsx(Skeleton, { height: 64, radius: "xl" }), _jsx(Skeleton, { height: 64, radius: "xl" })] }) }, section.key))
|
|
60
|
+
: null })] }))
|
|
61
|
+
: (_jsx(EmptyState, { icon: "settings", title: say("nothingToSet"), children: say("nothingToSetAbout") }))] }));
|
|
62
|
+
}
|