@copilotz/directory 1.0.0-rc.79 → 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 +1 -1
- package/README.md +9 -68
- package/contract.d.ts +1 -8
- package/contract.js +1 -8
- package/mod.d.ts +2 -67
- package/mod.js +2 -122
- package/package.json +9 -35
- package/web.d.ts +2 -36
- package/web.js +2 -57
- package/WORDS.md +0 -198
- package/actions/code.d.ts +0 -4
- package/actions/code.js +0 -135
- package/actions/host.d.ts +0 -2
- package/actions/host.js +0 -55
- package/actions/invite.d.ts +0 -5
- package/actions/invite.js +0 -129
- package/actions/org.d.ts +0 -10
- package/actions/org.js +0 -273
- package/collections/credit-code.d.ts +0 -107
- package/collections/credit-code.js +0 -28
- package/collections/invite.d.ts +0 -74
- package/collections/invite.js +0 -20
- package/collections/membership.d.ts +0 -65
- package/collections/membership.js +0 -22
- package/collections/org-host.d.ts +0 -55
- package/collections/org-host.js +0 -30
- package/collections/org.d.ts +0 -134
- package/collections/org.js +0 -58
- package/collections/staff.d.ts +0 -35
- package/collections/staff.js +0 -12
- package/routes/console.d.ts +0 -26
- package/routes/console.js +0 -129
- package/routes/enter.d.ts +0 -18
- package/routes/enter.js +0 -47
- package/routes/forward.d.ts +0 -35
- package/routes/forward.js +0 -119
- package/routes/orgs.d.ts +0 -25
- package/routes/orgs.js +0 -113
- package/routes/signout.d.ts +0 -11
- package/routes/signout.js +0 -36
- package/shared/enter.d.ts +0 -36
- package/shared/enter.js +0 -82
- package/shared/http.d.ts +0 -42
- package/shared/http.js +0 -77
- package/shared/member.d.ts +0 -21
- package/shared/member.js +0 -73
- package/shared/settings.d.ts +0 -53
- package/shared/settings.js +0 -16
- package/shared/state.d.ts +0 -74
- package/shared/state.js +0 -101
- package/views/web/codes.d.ts +0 -27
- package/views/web/codes.js +0 -50
- package/views/web/console-codes.d.ts +0 -37
- package/views/web/console-codes.js +0 -166
- package/views/web/console.d.ts +0 -37
- package/views/web/console.js +0 -224
- package/views/web/lists.d.ts +0 -48
- package/views/web/lists.js +0 -42
- package/views/web/org.d.ts +0 -12
- package/views/web/org.js +0 -62
- package/views/web/orgs.d.ts +0 -148
- package/views/web/orgs.js +0 -253
- package/views/web/style.d.ts +0 -6
- package/views/web/style.js +0 -197
- package/views/web/switcher.d.ts +0 -81
- package/views/web/switcher.js +0 -367
- package/views/web/words.d.ts +0 -10
- package/views/web/words.js +0 -206
package/views/web/console.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
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 "copilotz/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: "copilotz-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
|
-
}
|
package/views/web/lists.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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 "copilotz/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;
|
package/views/web/lists.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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 "copilotz/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}$/;
|
package/views/web/org.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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 "copilotz";
|
|
12
|
-
export declare const orgView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
|
package/views/web/org.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
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 "copilotz/web";
|
|
3
|
-
import { orgName, useOrgs } from "./orgs.js";
|
|
4
|
-
import { runs, useStanding } from "copilotz/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: "copilotz-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: "copilotz-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: "copilotz-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: "copilotz-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: "copilotz-org-held", children: say("heldBack", { section: heldBack }) }))
|
|
47
|
-
: null, sections.length
|
|
48
|
-
? (_jsxs(_Fragment, { children: [_jsx(Tabs, { label: say("orgSettingsOf", { name }), variant: "line", className: "copilotz-org-tabs", value: section?.key ?? "", panel: "copilotz-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: "copilotz-org-section", role: "tabpanel", className: "copilotz-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: "copilotz-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
|
-
}
|
package/views/web/orgs.d.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
export type Org = {
|
|
2
|
-
id: string;
|
|
3
|
-
name: string;
|
|
4
|
-
kind: "personal" | "team";
|
|
5
|
-
suspended?: true;
|
|
6
|
-
};
|
|
7
|
-
/** An invitation to an org, waiting for the person: from whom, as what. */
|
|
8
|
-
export type OrgInvite = {
|
|
9
|
-
id: string;
|
|
10
|
-
org: string;
|
|
11
|
-
name: string;
|
|
12
|
-
role: string;
|
|
13
|
-
from?: string;
|
|
14
|
-
at: string;
|
|
15
|
-
};
|
|
16
|
-
/** What `GET /orgs` answers. */
|
|
17
|
-
export type Orgs = {
|
|
18
|
-
person: string;
|
|
19
|
-
email: string | null;
|
|
20
|
-
/** The org the session is in. */
|
|
21
|
-
current: string | null;
|
|
22
|
-
orgs: Org[];
|
|
23
|
-
invites: OrgInvite[];
|
|
24
|
-
/** Platform staff, who go into any org. */
|
|
25
|
-
staff: boolean;
|
|
26
|
-
/** The session they hold in the org they're in is staff's, one of theirs or not. */
|
|
27
|
-
asStaff: boolean;
|
|
28
|
-
};
|
|
29
|
-
/** An org as staff's console lists it, with what it last reported of itself. */
|
|
30
|
-
export type ConsoleOrg = Org & {
|
|
31
|
-
by: string;
|
|
32
|
-
members: number;
|
|
33
|
-
placement: {
|
|
34
|
-
schema: string;
|
|
35
|
-
};
|
|
36
|
-
summary?: {
|
|
37
|
-
people?: number;
|
|
38
|
-
spaces?: number;
|
|
39
|
-
active?: string;
|
|
40
|
-
at?: string;
|
|
41
|
-
};
|
|
42
|
-
at: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Where the orgs stand: still asking, a server with none (one org), or what
|
|
46
|
-
* it said, with the org the person is in (`here`: one of theirs, or, for
|
|
47
|
-
* staff, one they went into, as the console names it).
|
|
48
|
-
*/
|
|
49
|
-
export type OrgsState = {
|
|
50
|
-
status: "loading";
|
|
51
|
-
} | {
|
|
52
|
-
status: "none";
|
|
53
|
-
} | {
|
|
54
|
-
status: "ready";
|
|
55
|
-
value: Orgs;
|
|
56
|
-
here?: Org;
|
|
57
|
-
};
|
|
58
|
-
/** Asks the server, once (again with `refreshOrgs`); a server that serves one org answers none. */
|
|
59
|
-
export declare function loadOrgs(): Promise<OrgsState>;
|
|
60
|
-
/** Asks the server again: after renaming an org, or answering an invitation. */
|
|
61
|
-
export declare function refreshOrgs(): Promise<OrgsState>;
|
|
62
|
-
/** The orgs, as they stand, kept current. */
|
|
63
|
-
export declare function useOrgs(): OrgsState;
|
|
64
|
-
/** The org the session is in: one of theirs, or (for staff) one they've gone into. */
|
|
65
|
-
export declare const currentOrg: (orgs: Orgs) => Org | undefined;
|
|
66
|
-
/** Whether they're in an org as platform staff, not as one of its people. */
|
|
67
|
-
export declare const asStaff: (orgs: Orgs) => boolean;
|
|
68
|
-
/** What an org is called where it shows: everyone's own is "Personal". */
|
|
69
|
-
export declare const orgName: (org: Pick<Org, "name" | "kind">) => string;
|
|
70
|
-
/**
|
|
71
|
-
* Going into an org: which, while the page starts over there (as staff, or
|
|
72
|
-
* `moved` there because they're no longer in the one they were in).
|
|
73
|
-
*/
|
|
74
|
-
export type Switching = {
|
|
75
|
-
/** The org's id, when known (its face's colour). */
|
|
76
|
-
id?: string;
|
|
77
|
-
name: string;
|
|
78
|
-
kind: "personal" | "team";
|
|
79
|
-
staff?: boolean;
|
|
80
|
-
moved?: boolean;
|
|
81
|
-
};
|
|
82
|
-
/** The org the page is going into, while it does (the shell shows a short transition). */
|
|
83
|
-
export declare function useSwitching(): Switching | undefined;
|
|
84
|
-
/** Goes into an org (one of theirs; any, for staff), and starts over at its home. */
|
|
85
|
-
export declare function enterOrg(org: Pick<Org, "id" | "name" | "kind">, staff?: boolean): Promise<void>;
|
|
86
|
-
/** Makes a team org, its maker its owner, and goes into it. */
|
|
87
|
-
export declare function createOrg(name: string): Promise<void>;
|
|
88
|
-
/** Accepts an invitation (and goes into its org) or declines it. */
|
|
89
|
-
export declare function answerOrgInvite(invite: OrgInvite, accept: boolean): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Where many orgs are served, someone still signed in whose session in this
|
|
92
|
-
* org ended (they were taken out of it, or it was suspended) goes into
|
|
93
|
-
* another of theirs instead of signing in again: the one they were in
|
|
94
|
-
* before, or their own. True when the page is starting over there; never
|
|
95
|
-
* twice in a row, so a page that can't get in shows sign-in.
|
|
96
|
-
*/
|
|
97
|
-
export declare function reenter(): Promise<boolean>;
|
|
98
|
-
/** The org the page just came into, once (its welcome), then forgotten. */
|
|
99
|
-
export declare function arrived(): Switching | undefined;
|
|
100
|
-
/** Every org, for staff's console. */
|
|
101
|
-
export declare function consoleOrgs(): Promise<ConsoleOrg[]>;
|
|
102
|
-
/** Suspends an org or lifts it, or renames it: staff's. */
|
|
103
|
-
export declare function updateOrg(org: string, change: {
|
|
104
|
-
suspended?: boolean;
|
|
105
|
-
name?: string;
|
|
106
|
-
}): Promise<void>;
|
|
107
|
-
/** Moves an org's rows to another schema (for a big org: one of its own). */
|
|
108
|
-
export declare function moveOrg(org: string, schema: string): Promise<{
|
|
109
|
-
schema: string;
|
|
110
|
-
}>;
|
|
111
|
-
/** Where an org's rows download, as SQL. */
|
|
112
|
-
export declare const exportOrgUrl: (org: string) => string;
|
|
113
|
-
/** Deletes an org for good: `name`, its exact name, confirms it. */
|
|
114
|
-
export declare function deleteOrg(org: string, name: string): Promise<void>;
|
|
115
|
-
/** A gift code as staff's console lists it: never the code itself, which is only kept hashed. */
|
|
116
|
-
export type GiftCode = {
|
|
117
|
-
id: string;
|
|
118
|
-
/** Enough to tell them apart: it can't be claimed with this. */
|
|
119
|
-
short: string;
|
|
120
|
-
/** USD. */
|
|
121
|
-
amount: number;
|
|
122
|
-
/** The first day its credits no longer count (`YYYY-MM-DD`); none: they don't lapse. */
|
|
123
|
-
expires?: string;
|
|
124
|
-
/** The last moment it can be claimed (ISO); none: until it is. */
|
|
125
|
-
until?: string;
|
|
126
|
-
note?: string;
|
|
127
|
-
by: string;
|
|
128
|
-
at: string;
|
|
129
|
-
/** Who took it, for which org, and when. */
|
|
130
|
-
org?: string;
|
|
131
|
-
person?: string;
|
|
132
|
-
claimed?: string;
|
|
133
|
-
revoked?: string;
|
|
134
|
-
};
|
|
135
|
-
/** Gift codes, newest first, for staff's console. */
|
|
136
|
-
export declare function giftCodes(): Promise<GiftCode[]>;
|
|
137
|
-
/** Makes a gift code: the answer's `code` is the only time it's ever shown. */
|
|
138
|
-
export declare const createGiftCode: (code: {
|
|
139
|
-
amount: number;
|
|
140
|
-
expires?: string;
|
|
141
|
-
until?: string;
|
|
142
|
-
note?: string;
|
|
143
|
-
}) => Promise<{
|
|
144
|
-
code: string;
|
|
145
|
-
id: string;
|
|
146
|
-
}>;
|
|
147
|
-
/** Takes back a gift code nobody has claimed. */
|
|
148
|
-
export declare function revokeGiftCode(id: string): Promise<void>;
|