@zjazj/web 0.0.5 → 0.0.6
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/dist/index.d.ts +31 -4
- package/dist/index.js +263 -24
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -68,6 +68,14 @@ interface CurrentUser {
|
|
|
68
68
|
roles: string[];
|
|
69
69
|
permissions: string[];
|
|
70
70
|
timeZone?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Set while a platform operator works in this tenant as platform support. `until` is when
|
|
73
|
+
* the session ends, in seconds since 1970. Mirrors the server's `SupportSession`.
|
|
74
|
+
*/
|
|
75
|
+
support?: {
|
|
76
|
+
until: number;
|
|
77
|
+
mode: string;
|
|
78
|
+
};
|
|
71
79
|
isDev?: boolean;
|
|
72
80
|
}
|
|
73
81
|
/** Where the session stands. The shell picks its screen from `state`. */
|
|
@@ -87,6 +95,15 @@ interface SessionStatus {
|
|
|
87
95
|
interface Session {
|
|
88
96
|
/** `dev` for the local dev identity, `platform` for sign-in at the identity provider. */
|
|
89
97
|
readonly kind: string;
|
|
98
|
+
/**
|
|
99
|
+
* Platform support: make a customer's organization the current tenant of this browser,
|
|
100
|
+
* after the control plane let the operator in. The operator's own tenant is remembered
|
|
101
|
+
* as the way back. The page keeps its tenant for its whole life, so the caller opens the
|
|
102
|
+
* app again afterwards. A session without this method cannot enter a tenant.
|
|
103
|
+
*/
|
|
104
|
+
enterTenant?(organizationId: string): Promise<void>;
|
|
105
|
+
/** Platform support: make the operator's own tenant the current one again. */
|
|
106
|
+
leaveTenant?(): Promise<void>;
|
|
90
107
|
getUser(): CurrentUser | null;
|
|
91
108
|
/** The same object until the state changes, so it can back `useSyncExternalStore`. */
|
|
92
109
|
getStatus(): SessionStatus;
|
|
@@ -304,9 +321,9 @@ declare function ErrorScreen({ error }: {
|
|
|
304
321
|
error: unknown;
|
|
305
322
|
}): react.JSX.Element;
|
|
306
323
|
/**
|
|
307
|
-
* The frame every page renders in: sidebar built from the routes, header with the
|
|
308
|
-
*
|
|
309
|
-
*
|
|
324
|
+
* The frame every page renders in: sidebar built from the routes, header with the tenant
|
|
325
|
+
* switcher and the account menu, and the route content. Use it as the component of the
|
|
326
|
+
* root route. A route with `staticData.layout: 'none'` renders without the frame.
|
|
310
327
|
*/
|
|
311
328
|
declare function AppShell(): react.JSX.Element;
|
|
312
329
|
|
|
@@ -321,7 +338,9 @@ declare function hasPermissions(granted: Iterable<string>, required: readonly st
|
|
|
321
338
|
|
|
322
339
|
/**
|
|
323
340
|
* The current tenant of this browser. One browser profile has one current tenant, and every
|
|
324
|
-
* tab of every app reads the same value.
|
|
341
|
+
* tab of every app reads the same value. The header of every app
|
|
342
|
+
* changes it when a platform operator enters or leaves a tenant as platform support
|
|
343
|
+
* (`Session.enterTenant`, `Session.leaveTenant`).
|
|
325
344
|
*/
|
|
326
345
|
declare const TENANT_STORAGE_KEY = "platform.tenant";
|
|
327
346
|
/** What is stored: the tenant, and the organization its tokens are issued for. */
|
|
@@ -330,6 +349,14 @@ interface StoredTenant {
|
|
|
330
349
|
organizationId: string;
|
|
331
350
|
/** The tenant's UUID, as the organization token carries it. */
|
|
332
351
|
tenantId: string;
|
|
352
|
+
/**
|
|
353
|
+
* Set while a platform operator works in a customer's tenant as platform support: the
|
|
354
|
+
* operator's own tenant, which comes back when the session ends.
|
|
355
|
+
*/
|
|
356
|
+
home?: {
|
|
357
|
+
organizationId: string;
|
|
358
|
+
tenantId: string;
|
|
359
|
+
};
|
|
333
360
|
}
|
|
334
361
|
/** The stored current tenant, or undefined when none is stored or storage is closed. */
|
|
335
362
|
declare function readStoredTenant(): StoredTenant | undefined;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { registerMessages as registerMessages2 } from "@zjazj/i18n";
|
|
|
3
3
|
|
|
4
4
|
// src/locales/en-US.json
|
|
5
5
|
var en_US_default = {
|
|
6
|
-
apps: "Apps",
|
|
7
6
|
account: "Account",
|
|
8
7
|
signOut: "Sign out",
|
|
9
8
|
theme: "Theme",
|
|
@@ -35,12 +34,24 @@ var en_US_default = {
|
|
|
35
34
|
noTenantTitle: "No tenant",
|
|
36
35
|
noTenantBody: "Your account does not belong to a tenant yet. Ask an administrator to invite you.",
|
|
37
36
|
errorTitle: "Something went wrong",
|
|
38
|
-
traceId: "Trace id: {{id}}"
|
|
37
|
+
traceId: "Trace id: {{id}}",
|
|
38
|
+
cancel: "Cancel",
|
|
39
|
+
enterTenant: "Enter a tenant",
|
|
40
|
+
enterTenantBody: "Work in a customer's tenant as platform support, for one hour. Everything you do is recorded to your account. The tenant sees it as done by Platform Support.",
|
|
41
|
+
enterTenantSearch: "Search tenants",
|
|
42
|
+
enterTenantLoading: "Loading tenants\u2026",
|
|
43
|
+
enterTenantNone: "No tenant found.",
|
|
44
|
+
enterTenantConfirm: "Enter",
|
|
45
|
+
supportNotice: "Support in {{tenant}} \xB7 {{minutes}} min left",
|
|
46
|
+
supportExit: "Exit",
|
|
47
|
+
supportEndedTitle: "Support session ended",
|
|
48
|
+
supportEndedBody: "Your time in this tenant is over. Continue in your own tenant.",
|
|
49
|
+
continue: "Continue",
|
|
50
|
+
enterTenantNoSignIn: "No sign-in set up"
|
|
39
51
|
};
|
|
40
52
|
|
|
41
53
|
// src/locales/zh-CN.json
|
|
42
54
|
var zh_CN_default = {
|
|
43
|
-
apps: "\u5E94\u7528",
|
|
44
55
|
account: "\u8D26\u53F7",
|
|
45
56
|
signOut: "\u9000\u51FA\u767B\u5F55",
|
|
46
57
|
theme: "\u4E3B\u9898",
|
|
@@ -72,7 +83,20 @@ var zh_CN_default = {
|
|
|
72
83
|
noTenantTitle: "\u6CA1\u6709\u79DF\u6237",
|
|
73
84
|
noTenantBody: "\u4F60\u7684\u8D26\u53F7\u8FD8\u4E0D\u5C5E\u4E8E\u4EFB\u4F55\u79DF\u6237\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u9080\u8BF7\u4F60\u3002",
|
|
74
85
|
errorTitle: "\u51FA\u9519\u4E86",
|
|
75
|
-
traceId: "\u8FFD\u8E2A\u53F7\uFF1A{{id}}"
|
|
86
|
+
traceId: "\u8FFD\u8E2A\u53F7\uFF1A{{id}}",
|
|
87
|
+
cancel: "\u53D6\u6D88",
|
|
88
|
+
enterTenant: "\u8FDB\u5165\u79DF\u6237",
|
|
89
|
+
enterTenantBody: "\u4EE5\u5E73\u53F0\u652F\u6301\u8EAB\u4EFD\u8FDB\u5165\u5BA2\u6237\u7684\u79DF\u6237\uFF0C\u65F6\u957F\u4E00\u5C0F\u65F6\u3002\u4F60\u7684\u6240\u6709\u64CD\u4F5C\u90FD\u8BB0\u5728\u4F60\u81EA\u5DF1\u7684\u8D26\u53F7\u4E0B\uFF0C\u79DF\u6237\u770B\u5230\u7684\u64CD\u4F5C\u4EBA\u662F\u201C\u5E73\u53F0\u652F\u6301\u201D\u3002",
|
|
90
|
+
enterTenantSearch: "\u641C\u7D22\u79DF\u6237",
|
|
91
|
+
enterTenantLoading: "\u6B63\u5728\u52A0\u8F7D\u79DF\u6237\u2026",
|
|
92
|
+
enterTenantNone: "\u6CA1\u6709\u627E\u5230\u79DF\u6237\u3002",
|
|
93
|
+
enterTenantConfirm: "\u8FDB\u5165",
|
|
94
|
+
supportNotice: "\u652F\u6301\u4E2D\uFF1A{{tenant}} \xB7 \u5269\u4F59 {{minutes}} \u5206\u949F",
|
|
95
|
+
supportExit: "\u9000\u51FA",
|
|
96
|
+
supportEndedTitle: "\u652F\u6301\u4F1A\u8BDD\u5DF2\u7ED3\u675F",
|
|
97
|
+
supportEndedBody: "\u4F60\u5728\u8FD9\u4E2A\u79DF\u6237\u7684\u65F6\u95F4\u5DF2\u5230\u3002\u7EE7\u7EED\u4F1A\u56DE\u5230\u4F60\u81EA\u5DF1\u7684\u79DF\u6237\u3002",
|
|
98
|
+
continue: "\u7EE7\u7EED",
|
|
99
|
+
enterTenantNoSignIn: "\u672A\u5F00\u901A\u767B\u5F55"
|
|
76
100
|
};
|
|
77
101
|
|
|
78
102
|
// src/app.tsx
|
|
@@ -122,10 +146,12 @@ function parseStoredTenant(raw) {
|
|
|
122
146
|
try {
|
|
123
147
|
const parsed = JSON.parse(raw);
|
|
124
148
|
if (parsed && typeof parsed === "object") {
|
|
125
|
-
const { organizationId, tenantId } = parsed;
|
|
149
|
+
const { organizationId, tenantId, home } = parsed;
|
|
150
|
+
const back = home && typeof home === "object" ? home : {};
|
|
126
151
|
return {
|
|
127
152
|
...typeof organizationId === "string" && organizationId ? { organizationId } : {},
|
|
128
|
-
...typeof tenantId === "string" && tenantId ? { tenantId } : {}
|
|
153
|
+
...typeof tenantId === "string" && tenantId ? { tenantId } : {},
|
|
154
|
+
...typeof back.organizationId === "string" && back.organizationId && typeof back.tenantId === "string" && back.tenantId ? { home: { organizationId: back.organizationId, tenantId: back.tenantId } } : {}
|
|
129
155
|
};
|
|
130
156
|
}
|
|
131
157
|
} catch {
|
|
@@ -141,10 +167,8 @@ function readStoredTenant() {
|
|
|
141
167
|
}
|
|
142
168
|
}
|
|
143
169
|
function writeStoredTenant(value) {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
170
|
+
const stored = (tenant) => tenant ? JSON.stringify([tenant.organizationId, tenant.tenantId, tenant.home ?? null]) : void 0;
|
|
171
|
+
if (stored(readStoredTenant()) === stored(value)) return;
|
|
148
172
|
try {
|
|
149
173
|
globalThis.localStorage?.setItem(TENANT_STORAGE_KEY, JSON.stringify(value));
|
|
150
174
|
} catch {
|
|
@@ -251,6 +275,8 @@ function userFromTokenClaims(claims, profile = {}) {
|
|
|
251
275
|
}
|
|
252
276
|
const roles = strings(claims.organization_roles);
|
|
253
277
|
const timeZone = firstString(claims.tenant_time_zone);
|
|
278
|
+
const { support_until: until, support_mode: mode } = claims;
|
|
279
|
+
const support = typeof until === "number" && Number.isFinite(until) && typeof mode === "string" && mode ? { until, mode } : void 0;
|
|
254
280
|
return {
|
|
255
281
|
id: sub,
|
|
256
282
|
tenantId: tenantId.toLowerCase(),
|
|
@@ -265,7 +291,8 @@ function userFromTokenClaims(claims, profile = {}) {
|
|
|
265
291
|
) ?? sub,
|
|
266
292
|
roles: roles.length > 0 ? roles : strings(claims.roles),
|
|
267
293
|
permissions: strings(claims.permissions),
|
|
268
|
-
...timeZone ? { timeZone } : {}
|
|
294
|
+
...timeZone ? { timeZone } : {},
|
|
295
|
+
...support ? { support } : {}
|
|
269
296
|
};
|
|
270
297
|
}
|
|
271
298
|
function rememberLocation() {
|
|
@@ -324,11 +351,25 @@ function createPlatformSession(options = {}) {
|
|
|
324
351
|
token = { value, expiresAt: typeof claims.exp === "number" ? claims.exp : 0 };
|
|
325
352
|
return next;
|
|
326
353
|
};
|
|
354
|
+
const take = async (identity, organization, home) => {
|
|
355
|
+
try {
|
|
356
|
+
const next = readToken(await identity.getOrganizationToken(organization));
|
|
357
|
+
organizationId = organization;
|
|
358
|
+
writeStoredTenant({ organizationId: organization, tenantId: next.tenantId, home });
|
|
359
|
+
update(next, { state: "ready" });
|
|
360
|
+
return true;
|
|
361
|
+
} catch {
|
|
362
|
+
token = void 0;
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
327
366
|
const adopt = async (identity) => {
|
|
328
367
|
profile = await identity.getIdTokenClaims() ?? {};
|
|
329
368
|
const organizations = strings(profile.organizations);
|
|
330
369
|
const stored = readStoredTenant();
|
|
331
|
-
|
|
370
|
+
if (stored?.home && await take(identity, stored.organizationId, stored.home)) return;
|
|
371
|
+
const own = stored?.home?.organizationId ?? stored?.organizationId;
|
|
372
|
+
const organization = own && organizations.includes(own) ? own : organizations[0];
|
|
332
373
|
if (!organization) {
|
|
333
374
|
fail("no_organization", "The account is not a member of any tenant.");
|
|
334
375
|
return;
|
|
@@ -345,6 +386,13 @@ function createPlatformSession(options = {}) {
|
|
|
345
386
|
writeStoredTenant({ organizationId: organization, tenantId: next.tenantId });
|
|
346
387
|
update(next, { state: "ready" });
|
|
347
388
|
};
|
|
389
|
+
const supportEnded = () => {
|
|
390
|
+
const home = readStoredTenant()?.home;
|
|
391
|
+
if (home) writeStoredTenant(home);
|
|
392
|
+
else clearStoredTenant();
|
|
393
|
+
token = void 0;
|
|
394
|
+
update(null, { state: "error", code: "support_ended" });
|
|
395
|
+
};
|
|
348
396
|
const restore = async () => {
|
|
349
397
|
let identity;
|
|
350
398
|
try {
|
|
@@ -365,16 +413,34 @@ function createPlatformSession(options = {}) {
|
|
|
365
413
|
const started = restore();
|
|
366
414
|
const refresh = () => withTokenLock(async () => {
|
|
367
415
|
const current = token;
|
|
416
|
+
const stillValid = () => current && current.expiresAt > now() / 1e3 ? current : null;
|
|
417
|
+
let value;
|
|
368
418
|
try {
|
|
369
419
|
const identity = await connect();
|
|
370
420
|
await identity.clearAccessToken();
|
|
371
|
-
|
|
421
|
+
value = await identity.getOrganizationToken(organizationId);
|
|
422
|
+
} catch {
|
|
423
|
+
const valid = stillValid();
|
|
424
|
+
if (valid) {
|
|
425
|
+
token = valid;
|
|
426
|
+
return valid.value;
|
|
427
|
+
}
|
|
428
|
+
if (user?.support) supportEnded();
|
|
429
|
+
else end();
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
372
433
|
update(readToken(value), { state: "ready" });
|
|
373
434
|
return value;
|
|
374
435
|
} catch {
|
|
375
|
-
if (
|
|
376
|
-
|
|
377
|
-
return
|
|
436
|
+
if (user?.support) {
|
|
437
|
+
supportEnded();
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
const valid = stillValid();
|
|
441
|
+
if (valid) {
|
|
442
|
+
token = valid;
|
|
443
|
+
return valid.value;
|
|
378
444
|
}
|
|
379
445
|
end();
|
|
380
446
|
return null;
|
|
@@ -427,6 +493,23 @@ function createPlatformSession(options = {}) {
|
|
|
427
493
|
});
|
|
428
494
|
return signingIn;
|
|
429
495
|
},
|
|
496
|
+
async enterTenant(next) {
|
|
497
|
+
await started;
|
|
498
|
+
const self = user;
|
|
499
|
+
if (!isReady() || !self) throw new Error("Nobody is signed in.");
|
|
500
|
+
const value = await (await connect()).getOrganizationToken(next);
|
|
501
|
+
const { tenantId } = userFromTokenClaims(decodeTokenClaims(value), profile);
|
|
502
|
+
const home = readStoredTenant()?.home ?? {
|
|
503
|
+
organizationId,
|
|
504
|
+
tenantId: self.tenantId
|
|
505
|
+
};
|
|
506
|
+
writeStoredTenant({ organizationId: next, tenantId, home });
|
|
507
|
+
},
|
|
508
|
+
async leaveTenant() {
|
|
509
|
+
const home = readStoredTenant()?.home;
|
|
510
|
+
if (home) writeStoredTenant(home);
|
|
511
|
+
else clearStoredTenant();
|
|
512
|
+
},
|
|
430
513
|
async signOut() {
|
|
431
514
|
channel?.postMessage({ type: "signed-out" });
|
|
432
515
|
clearStoredTenant();
|
|
@@ -643,6 +726,18 @@ import {
|
|
|
643
726
|
AvatarFallback,
|
|
644
727
|
Badge,
|
|
645
728
|
Button,
|
|
729
|
+
Command,
|
|
730
|
+
CommandEmpty,
|
|
731
|
+
CommandInput,
|
|
732
|
+
CommandItem,
|
|
733
|
+
CommandList,
|
|
734
|
+
Dialog,
|
|
735
|
+
DialogContent,
|
|
736
|
+
DialogDescription,
|
|
737
|
+
DialogFooter,
|
|
738
|
+
DialogHeader,
|
|
739
|
+
DialogTitle,
|
|
740
|
+
DialogTrigger,
|
|
646
741
|
DropdownMenu,
|
|
647
742
|
DropdownMenuContent,
|
|
648
743
|
DropdownMenuItem,
|
|
@@ -670,8 +765,8 @@ import {
|
|
|
670
765
|
SidebarTrigger,
|
|
671
766
|
useTheme
|
|
672
767
|
} from "@zjazj/ui";
|
|
673
|
-
import { LayoutGrid, LogOut } from "lucide-react";
|
|
674
|
-
import { useEffect, useMemo, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
768
|
+
import { Building2, Check, LayoutGrid, LifeBuoy, LogOut } from "lucide-react";
|
|
769
|
+
import { useEffect, useMemo, useState, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
675
770
|
|
|
676
771
|
// src/menu.ts
|
|
677
772
|
function requiredPermissions(meta) {
|
|
@@ -744,12 +839,16 @@ function SessionScreen() {
|
|
|
744
839
|
const t = useT("web");
|
|
745
840
|
const session = useSession();
|
|
746
841
|
const status = useSessionStatus();
|
|
842
|
+
const { basePath } = useAppConfig();
|
|
747
843
|
if (status.state === "ended") {
|
|
748
844
|
return /* @__PURE__ */ jsx2(Message, { title: t("signedOutTitle"), body: t("signedOutBody"), children: /* @__PURE__ */ jsx2(Button, { onClick: () => void session.signIn(), children: t("signIn") }) });
|
|
749
845
|
}
|
|
750
846
|
if (status.state === "error" && status.code === "not_configured") {
|
|
751
847
|
return /* @__PURE__ */ jsx2(Message, { title: t("signInRequiredTitle"), body: t("signInRequiredBody") });
|
|
752
848
|
}
|
|
849
|
+
if (status.state === "error" && status.code === "support_ended") {
|
|
850
|
+
return /* @__PURE__ */ jsx2(Message, { title: t("supportEndedTitle"), body: t("supportEndedBody"), children: /* @__PURE__ */ jsx2(Button, { onClick: () => window.location.assign(basePath || "/"), children: t("continue") }) });
|
|
851
|
+
}
|
|
753
852
|
if (status.state === "error" && status.code === "no_organization") {
|
|
754
853
|
return /* @__PURE__ */ jsx2(Message, { title: t("noTenantTitle"), body: t("noTenantBody"), children: /* @__PURE__ */ jsx2(Button, { variant: "outline", onClick: () => void session.signOut(), children: t("signOut") }) });
|
|
755
854
|
}
|
|
@@ -771,6 +870,149 @@ var THEME_MODES = [
|
|
|
771
870
|
{ mode: "system", label: "themeSystem" }
|
|
772
871
|
];
|
|
773
872
|
var LOCALE_LABELS = { "en-US": "localeEnUS", "zh-CN": "localeZhCN" };
|
|
873
|
+
var ENTER_TENANT_PERMISSION = "admin:tenant:enter";
|
|
874
|
+
function messageOf2(error) {
|
|
875
|
+
return error instanceof Error ? error.message : String(error);
|
|
876
|
+
}
|
|
877
|
+
function TenantSwitcher() {
|
|
878
|
+
const user = useUser();
|
|
879
|
+
const session = useSession();
|
|
880
|
+
if (user.support) return /* @__PURE__ */ jsx2(SupportNotice, {});
|
|
881
|
+
const canEnter = Boolean(session.enterTenant) && hasPermissions(user.permissions, [ENTER_TENANT_PERMISSION]);
|
|
882
|
+
return canEnter ? /* @__PURE__ */ jsx2(EnterTenant, {}) : /* @__PURE__ */ jsx2(TenantName, {});
|
|
883
|
+
}
|
|
884
|
+
function TenantName() {
|
|
885
|
+
const t = useT("web");
|
|
886
|
+
const user = useUser();
|
|
887
|
+
return /* @__PURE__ */ jsxs(
|
|
888
|
+
"span",
|
|
889
|
+
{
|
|
890
|
+
className: "text-muted-foreground flex min-w-0 items-center gap-1.5 px-2 text-sm",
|
|
891
|
+
title: t("tenant"),
|
|
892
|
+
children: [
|
|
893
|
+
/* @__PURE__ */ jsx2(Building2, { className: "size-4 shrink-0" }),
|
|
894
|
+
/* @__PURE__ */ jsx2("span", { className: "max-w-40 truncate", children: user.tenantSlug || user.tenantId })
|
|
895
|
+
]
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
function EnterTenant() {
|
|
900
|
+
const t = useT("web");
|
|
901
|
+
const user = useUser();
|
|
902
|
+
const session = useSession();
|
|
903
|
+
const { basePath } = useAppConfig();
|
|
904
|
+
const [open, setOpen] = useState(false);
|
|
905
|
+
const [tenants, setTenants] = useState();
|
|
906
|
+
const [chosen, setChosen] = useState();
|
|
907
|
+
const [entering, setEntering] = useState(false);
|
|
908
|
+
const [failure, setFailure] = useState();
|
|
909
|
+
useEffect(() => {
|
|
910
|
+
if (!open) return;
|
|
911
|
+
let stale = false;
|
|
912
|
+
setTenants(void 0);
|
|
913
|
+
setChosen(void 0);
|
|
914
|
+
setFailure(void 0);
|
|
915
|
+
platformFetch(`${apiBaseUrl()}/_platform/tenants?page_size=100`).then((response) => response.json()).then((page) => {
|
|
916
|
+
if (!stale) setTenants(Array.isArray(page.items) ? page.items : []);
|
|
917
|
+
}).catch((error) => {
|
|
918
|
+
if (stale) return;
|
|
919
|
+
setTenants([]);
|
|
920
|
+
setFailure(messageOf2(error));
|
|
921
|
+
});
|
|
922
|
+
return () => {
|
|
923
|
+
stale = true;
|
|
924
|
+
};
|
|
925
|
+
}, [open]);
|
|
926
|
+
const target = tenants?.find((item) => item.tenant_id === chosen && item.organization_id);
|
|
927
|
+
const enter = async () => {
|
|
928
|
+
if (!target || !session.enterTenant) return;
|
|
929
|
+
setEntering(true);
|
|
930
|
+
setFailure(void 0);
|
|
931
|
+
try {
|
|
932
|
+
const response = await platformFetch(`${apiBaseUrl()}/_platform/support`, {
|
|
933
|
+
method: "POST",
|
|
934
|
+
headers: { "Content-Type": "application/json" },
|
|
935
|
+
body: JSON.stringify({ tenant_id: target.tenant_id })
|
|
936
|
+
});
|
|
937
|
+
const entered = await response.json();
|
|
938
|
+
if (typeof entered.organization_id !== "string") {
|
|
939
|
+
throw new Error("The control plane answered without the organization.");
|
|
940
|
+
}
|
|
941
|
+
await session.enterTenant(entered.organization_id);
|
|
942
|
+
window.location.assign(basePath || "/");
|
|
943
|
+
} catch (error) {
|
|
944
|
+
setFailure(messageOf2(error));
|
|
945
|
+
setEntering(false);
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange: setOpen, children: [
|
|
949
|
+
/* @__PURE__ */ jsx2(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", "aria-label": t("enterTenant"), children: [
|
|
950
|
+
/* @__PURE__ */ jsx2(Building2, {}),
|
|
951
|
+
/* @__PURE__ */ jsx2("span", { className: "max-w-40 truncate", children: user.tenantSlug || user.tenantId })
|
|
952
|
+
] }) }),
|
|
953
|
+
/* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-md", children: [
|
|
954
|
+
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
955
|
+
/* @__PURE__ */ jsx2(DialogTitle, { children: t("enterTenant") }),
|
|
956
|
+
/* @__PURE__ */ jsx2(DialogDescription, { children: t("enterTenantBody") })
|
|
957
|
+
] }),
|
|
958
|
+
/* @__PURE__ */ jsxs(Command, { className: "rounded-md border", children: [
|
|
959
|
+
/* @__PURE__ */ jsx2(CommandInput, { placeholder: t("enterTenantSearch") }),
|
|
960
|
+
/* @__PURE__ */ jsxs(CommandList, { children: [
|
|
961
|
+
/* @__PURE__ */ jsx2(CommandEmpty, { children: tenants === void 0 ? t("enterTenantLoading") : t("enterTenantNone") }),
|
|
962
|
+
(tenants ?? []).map((item) => /* @__PURE__ */ jsxs(
|
|
963
|
+
CommandItem,
|
|
964
|
+
{
|
|
965
|
+
value: `${item.name} ${item.slug} ${item.tenant_id}`,
|
|
966
|
+
disabled: !item.organization_id,
|
|
967
|
+
onSelect: () => setChosen(item.tenant_id),
|
|
968
|
+
children: [
|
|
969
|
+
/* @__PURE__ */ jsx2("span", { className: "min-w-0 flex-1 truncate", children: item.name || item.slug }),
|
|
970
|
+
/* @__PURE__ */ jsx2("span", { className: "text-muted-foreground truncate text-xs", children: item.organization_id ? item.slug : t("enterTenantNoSignIn") }),
|
|
971
|
+
item.tenant_id === chosen ? /* @__PURE__ */ jsx2(Check, {}) : null
|
|
972
|
+
]
|
|
973
|
+
},
|
|
974
|
+
item.tenant_id
|
|
975
|
+
))
|
|
976
|
+
] })
|
|
977
|
+
] }),
|
|
978
|
+
failure ? /* @__PURE__ */ jsx2("p", { className: "text-destructive text-sm", children: failure }) : null,
|
|
979
|
+
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
980
|
+
/* @__PURE__ */ jsx2(Button, { variant: "outline", onClick: () => setOpen(false), children: t("cancel") }),
|
|
981
|
+
/* @__PURE__ */ jsx2(Button, { disabled: !target || entering, onClick: () => void enter(), children: t("enterTenantConfirm") })
|
|
982
|
+
] })
|
|
983
|
+
] })
|
|
984
|
+
] });
|
|
985
|
+
}
|
|
986
|
+
function SupportNotice() {
|
|
987
|
+
const t = useT("web");
|
|
988
|
+
const user = useUser();
|
|
989
|
+
const session = useSession();
|
|
990
|
+
const { basePath } = useAppConfig();
|
|
991
|
+
const [now, setNow] = useState(() => Date.now());
|
|
992
|
+
const [leaving, setLeaving] = useState(false);
|
|
993
|
+
useEffect(() => {
|
|
994
|
+
const clock = window.setInterval(() => setNow(Date.now()), 3e4);
|
|
995
|
+
return () => window.clearInterval(clock);
|
|
996
|
+
}, []);
|
|
997
|
+
const until = (user.support?.until ?? 0) * 1e3;
|
|
998
|
+
const minutes = Math.max(0, Math.ceil((until - now) / 6e4));
|
|
999
|
+
const leave = async () => {
|
|
1000
|
+
setLeaving(true);
|
|
1001
|
+
try {
|
|
1002
|
+
await platformFetch(`${apiBaseUrl()}/_platform/support`, { method: "DELETE" });
|
|
1003
|
+
} catch {
|
|
1004
|
+
}
|
|
1005
|
+
await session.leaveTenant?.();
|
|
1006
|
+
window.location.assign(basePath || "/");
|
|
1007
|
+
};
|
|
1008
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
1009
|
+
/* @__PURE__ */ jsxs(Badge, { variant: "secondary", className: "gap-1.5", children: [
|
|
1010
|
+
/* @__PURE__ */ jsx2(LifeBuoy, {}),
|
|
1011
|
+
/* @__PURE__ */ jsx2("span", { className: "max-w-48 truncate", children: t("supportNotice", { tenant: user.tenantSlug || user.tenantId, minutes }) })
|
|
1012
|
+
] }),
|
|
1013
|
+
/* @__PURE__ */ jsx2(Button, { variant: "outline", size: "sm", disabled: leaving, onClick: () => void leave(), children: t("supportExit") })
|
|
1014
|
+
] });
|
|
1015
|
+
}
|
|
774
1016
|
function AccountMenu() {
|
|
775
1017
|
const t = useT("web");
|
|
776
1018
|
const user = useUser();
|
|
@@ -881,21 +1123,18 @@ function AppShell() {
|
|
|
881
1123
|
/* @__PURE__ */ jsx2(SidebarContent, { children: /* @__PURE__ */ jsx2(Navigation, { groups, pathname }) }),
|
|
882
1124
|
/* @__PURE__ */ jsx2(SidebarRail, {})
|
|
883
1125
|
] }),
|
|
884
|
-
/* @__PURE__ */ jsxs(SidebarInset, { children: [
|
|
1126
|
+
/* @__PURE__ */ jsxs(SidebarInset, { className: "min-w-0", children: [
|
|
885
1127
|
/* @__PURE__ */ jsxs("header", { className: "bg-background sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b px-4", children: [
|
|
886
1128
|
/* @__PURE__ */ jsx2(SidebarTrigger, {}),
|
|
887
1129
|
/* @__PURE__ */ jsx2(Separator, { orientation: "vertical", className: "mx-1 h-5" }),
|
|
888
1130
|
/* @__PURE__ */ jsx2("span", { className: "truncate font-medium", children: pageTitle ?? config.title }),
|
|
889
1131
|
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-2", children: [
|
|
890
1132
|
user.isDev ? /* @__PURE__ */ jsx2(Badge, { variant: "outline", children: t("devIdentity") }) : null,
|
|
891
|
-
/* @__PURE__ */ jsx2(
|
|
892
|
-
/* @__PURE__ */ jsx2(LayoutGrid, {}),
|
|
893
|
-
t("apps")
|
|
894
|
-
] }) }),
|
|
1133
|
+
/* @__PURE__ */ jsx2(TenantSwitcher, {}),
|
|
895
1134
|
/* @__PURE__ */ jsx2(AccountMenu, {})
|
|
896
1135
|
] })
|
|
897
1136
|
] }),
|
|
898
|
-
/* @__PURE__ */ jsx2("main", { className: "flex-1 p-4 md:p-6", children: allowed ? /* @__PURE__ */ jsx2(Outlet, {}) : /* @__PURE__ */ jsx2(Forbidden, {}) })
|
|
1137
|
+
/* @__PURE__ */ jsx2("main", { className: "min-w-0 flex-1 p-4 md:p-6", children: allowed ? /* @__PURE__ */ jsx2(Outlet, {}) : /* @__PURE__ */ jsx2(Forbidden, {}) })
|
|
899
1138
|
] }),
|
|
900
1139
|
tenantChanged ? /* @__PURE__ */ jsx2(TenantChanged, {}) : null
|
|
901
1140
|
] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zjazj/web",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Browser runtime for platform apps: session, typed API client, layout shell, guards and hooks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"@logto/browser": "^3.1.2",
|
|
28
28
|
"hono": "^4.13.17",
|
|
29
29
|
"lucide-react": "^0.545.0",
|
|
30
|
-
"@zjazj/
|
|
31
|
-
"@zjazj/
|
|
30
|
+
"@zjazj/ui": "^0.0.6",
|
|
31
|
+
"@zjazj/i18n": "^0.0.6"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@tanstack/react-query": "^5.90.0",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"jsdom": "^26.1.0",
|
|
46
46
|
"react": "^19.2.0",
|
|
47
47
|
"react-dom": "^19.2.0",
|
|
48
|
-
"@zjazj/server": "^0.0.
|
|
48
|
+
"@zjazj/server": "^0.0.6"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public",
|