Skip to content

Commit 94b6369

Browse files
feat: update tenant management with UI components
1 parent 5226d7f commit 94b6369

File tree

4 files changed

+59
-61
lines changed

4 files changed

+59
-61
lines changed

packages/tenants-react/src/components/tenant-management/tenant-management.tsx

Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ import style from "./styles.module.scss";
1313
const cx = classNames.bind(style);
1414

1515
export const TenantManagement = ({ section }: { section: any }) => {
16-
const { api } = usePluginContext();
16+
const { api, t } = usePluginContext();
1717
const { getUsers, getInvitations, removeInvitation, addInvitation, fetchTenants, switchTenant } = api;
1818
const [tenants, setTenants] = useState<TenantDetails[]>([]);
1919
const [selectedTenantId, setSelectedTenantId] = useState<string>("public");
20-
const [activeTab, setActiveTab] = useState<"users" | "invitations">("users");
2120

2221
// Load tenants on component mount
2322
useEffect(() => {
2423
const loadTenants = async () => {
2524
const response = await fetchTenants();
2625
if (response.status === "OK") {
2726
setTenants(response.tenants);
27+
28+
// TODO: Set the selected tenant from the user details
2829
if (response.tenants.length > 0) {
29-
setSelectedTenantId(response.tenants[0].tenantId);
30+
setSelectedTenantId(response.tenants[0]!.tenantId);
3031
}
3132
}
3233
};
@@ -35,38 +36,38 @@ export const TenantManagement = ({ section }: { section: any }) => {
3536

3637
// Users tab functions
3738
const onFetchUsers = useCallback(async () => {
38-
const response = await getUsers(selectedTenantId);
39+
const response = await getUsers();
3940
if (response.status === "ERROR") {
4041
throw new Error(response.message);
4142
}
4243
return { users: response.users };
43-
}, [getUsers, selectedTenantId]);
44+
}, [getUsers]);
4445

4546
// Invitations tab functions
4647
const onFetchInvitations = useCallback(
47-
async (tenantId?: string) => {
48+
async () => {
4849
const response = await getInvitations();
4950
if (response.status === "ERROR") {
5051
throw new Error(response.message);
5152
}
5253
return { invitations: response.invitees };
5354
},
54-
[getInvitations, selectedTenantId],
55+
[getInvitations],
5556
);
5657

5758
const onRemoveInvite = useCallback(
58-
async (email: string, tenantId?: string) => {
59-
const response = await removeInvitation(email, tenantId || selectedTenantId);
59+
async (email: string) => {
60+
const response = await removeInvitation(email);
6061
if (response.status === "ERROR") {
6162
throw new Error(response.message);
6263
}
6364
},
64-
[removeInvitation, selectedTenantId],
65+
[removeInvitation],
6566
);
6667

6768
const onCreateInvite = useCallback(
68-
async (email: string, tenantId: string) => {
69-
const response = await addInvitation(email, tenantId);
69+
async (email: string) => {
70+
const response = await addInvitation(email);
7071
if (response.status === "ERROR") {
7172
throw new Error(response.message);
7273
}
@@ -113,55 +114,36 @@ export const TenantManagement = ({ section }: { section: any }) => {
113114
</div>
114115

115116
{/* Tab Navigation */}
116-
117117
<div>
118118
<TabGroup>
119-
<Tab panel="Users"></Tab>
120-
<Tab panel="Invitations"></Tab>
121-
<Tab panel="Requests"></Tab>
119+
<Tab panel={t("PL_TB_USERS_TAB_LABEL")}>
120+
<DetailsWrapper
121+
section={{
122+
id: "tenant-users",
123+
label: "Tenant Users",
124+
description: "Users in this tenant",
125+
fields: [],
126+
}}
127+
onFetch={onFetchUsers}
128+
/>
129+
</Tab>
130+
<Tab panel={t("PL_TB_INVITATIONS_TAB_LABEL")}>
131+
<InvitationsWrapper
132+
section={{
133+
id: "tenant-invitations",
134+
label: "Tenant Invitations",
135+
description: "Invitations for this tenant",
136+
fields: [],
137+
}}
138+
onFetch={onFetchInvitations}
139+
onRemove={onRemoveInvite}
140+
onCreate={onCreateInvite}
141+
selectedTenantId={selectedTenantId}
142+
/>
143+
</Tab>
144+
<Tab panel={t("PL_TB_REQUESTS_TAB_LABEL")}></Tab>
122145
</TabGroup>
123146
</div>
124-
125-
<div className={cx("tabNavigation")}>
126-
<button className={cx("tabButton", { active: activeTab === "users" })} onClick={() => setActiveTab("users")}>
127-
Users
128-
</button>
129-
<button
130-
className={cx("tabButton", { active: activeTab === "invitations" })}
131-
onClick={() => setActiveTab("invitations")}>
132-
Invitations
133-
</button>
134-
</div>
135-
136-
{/* Tab Content */}
137-
<div className={cx("tabContent")}>
138-
{activeTab === "users" && selectedTenantId && (
139-
<DetailsWrapper
140-
section={{
141-
id: "tenant-users",
142-
label: "Tenant Users",
143-
description: "Users in this tenant",
144-
fields: [],
145-
}}
146-
onFetch={onFetchUsers}
147-
/>
148-
)}
149-
150-
{activeTab === "invitations" && selectedTenantId && (
151-
<InvitationsWrapper
152-
section={{
153-
id: "tenant-invitations",
154-
label: "Tenant Invitations",
155-
description: "Invitations for this tenant",
156-
fields: [],
157-
}}
158-
onFetch={onFetchInvitations}
159-
onRemove={onRemoveInvite}
160-
onCreate={onCreateInvite}
161-
selectedTenantId={selectedTenantId}
162-
/>
163-
)}
164-
</div>
165147
</div>
166148
);
167149
};

packages/tenants-react/src/plugin.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createPluginInitFunction } from "@shared/js";
22
import { buildContext, getQuerier } from "@shared/react";
3-
import { SuperTokensPlugin, SuperTokensPublicConfig, SuperTokensPublicPlugin } from "supertokens-auth-react";
3+
import { getTranslationFunction, SuperTokensPlugin, SuperTokensPublicConfig, SuperTokensPublicPlugin } from "supertokens-auth-react";
44
import { BooleanClaim } from "supertokens-auth-react/recipe/session";
55

66
import { getApi } from "./api";
@@ -9,7 +9,8 @@ import { API_PATH, PLUGIN_ID } from "./constants";
99
// import { InvitationAcceptWrapper } from "./invitation-accept-wrapper";
1010
import { enableDebugLogs } from "./logger";
1111
// import { SelectTenantPage } from "./select-tenant-page";
12-
import { SuperTokensPluginTenantsPluginConfig, SuperTokensPluginTenantsPluginNormalisedConfig } from "./types";
12+
import { defaultTranslationsTenants } from "./translations";
13+
import { SuperTokensPluginTenantsPluginConfig, SuperTokensPluginTenantsPluginNormalisedConfig, TranslationKeys } from "./types";
1314

1415
const { usePluginContext, setContext } = buildContext<{
1516
plugins: SuperTokensPublicPlugin[];
@@ -18,7 +19,7 @@ const { usePluginContext, setContext } = buildContext<{
1819
pluginConfig: SuperTokensPluginTenantsPluginNormalisedConfig;
1920
querier: ReturnType<typeof getQuerier>;
2021
api: ReturnType<typeof getApi>;
21-
t: (key: any) => string; // TODO: Update with correct translations type
22+
t: (key: TranslationKeys) => string;
2223
}>();
2324
export { usePluginContext };
2425

@@ -75,6 +76,8 @@ export const init = createPluginInitFunction<
7576
};
7677
};
7778

79+
let translations: ReturnType<typeof getTranslationFunction<TranslationKeys>>;
80+
7881
return {
7982
id: PLUGIN_ID,
8083
init: (config, plugins, sdkVersion) => {
@@ -118,6 +121,7 @@ export const init = createPluginInitFunction<
118121

119122
const querier = getQuerier(new URL(API_PATH, config.appInfo.apiDomain.getAsStringDangerous()).toString());
120123
const api = getApi(querier);
124+
translations = getTranslationFunction<TranslationKeys>(defaultTranslationsTenants);
121125

122126
setContext({
123127
plugins,
@@ -126,7 +130,7 @@ export const init = createPluginInitFunction<
126130
pluginConfig,
127131
querier,
128132
api,
129-
t: (t: undefined) => "", // TODO: Update this
133+
t: translations,
130134
});
131135
},
132136
routeHandlers: (appConfig: any, plugins: any, sdkVersion: any) => {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const defaultTranslationsTenants = {
2+
en: {
3+
PL_TB_USERS_TAB_LABEL: "Users",
4+
PL_TB_INVITATIONS_TAB_LABEL: "Invitations",
5+
PL_TB_REQUESTS_TAB_LABEL: "Requests",
6+
},
7+
} as const;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import { defaultTranslationsTenants } from "./translations";
2+
3+
14
export type SuperTokensPluginTenantsPluginConfig = {
25
requireTenantCreation?: boolean;
36
};
47

58
export type SuperTokensPluginTenantsPluginNormalisedConfig = {
69
requireTenantCreation?: boolean;
710
};
11+
12+
export type TranslationKeys = keyof (typeof defaultTranslationsTenants)["en"];

0 commit comments

Comments
 (0)