Skip to content

Commit ba43413

Browse files
feat: add support for tenants tab/table structure and use in users tab
1 parent 94b6369 commit ba43413

File tree

10 files changed

+77
-39
lines changed

10 files changed

+77
-39
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './tenant-card';
22
export * from './page-wrapper';
3-
export * from './tenant-management';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react";
2+
3+
type TenantTabProps = {
4+
description: string;
5+
children: React.ReactNode;
6+
}
7+
8+
export const TenantTab: React.FC<TenantTabProps> = ({ description, children }) => {
9+
return (
10+
<div>
11+
<div>{description}</div>
12+
<div>{children}</div>
13+
</div>
14+
);
15+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
type TableProps = {
2+
columns: {
3+
emailComponent: React.ReactNode;
4+
extraComponent?: React.ReactNode;
5+
}[];
6+
};
7+
8+
export const TenantTable: React.FC<TableProps> = ({ columns }) => {
9+
return (
10+
<div>
11+
<div data-supertokens="table-head">
12+
<div>Email</div>
13+
<div>Role</div>
14+
</div>
15+
<div data-supertokens="table-columns">
16+
{columns.map((column) => {
17+
<div>
18+
<div data-supertokens="email-component">{column.emailComponent}</div>
19+
{column.extraComponent && <div data-supertokens="extra-component">{column.extraComponent}</div>}
20+
</div>;
21+
})}
22+
</div>
23+
</div>
24+
);
25+
};

packages/tenants-react/src/components/details/details-wrapper.tsx renamed to packages/tenants-react/src/components/users/TenantUsers.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import classNames from "classnames/bind";
22
import { useCallback, useEffect, useState } from "react";
33
import { User } from "supertokens-web-js/types";
44

5+
import { TenantTable } from "../table/TenantTable";
6+
57
import style from "./details.module.scss";
68

79
// import { BaseFormSection } from '@supertokens-plugin-profile/common-details-shared';
810

911
const cx = classNames.bind(style);
1012

11-
export const DetailsWrapper = ({ section, onFetch }: { section: any; onFetch: () => Promise<{ users: User[] }> }) => {
13+
type TenantUsersProps = {
14+
onFetch: () => Promise<{ users: User[] }>
15+
};
16+
17+
export const TenantUsers: React.FC<TenantUsersProps> = ({ onFetch }) => {
1218
const [users, setUsers] = useState<User[]>([]);
1319

1420
const loadDetails = useCallback(async () => {
@@ -22,20 +28,19 @@ export const DetailsWrapper = ({ section, onFetch }: { section: any; onFetch: ()
2228

2329
return (
2430
<div className={cx("tenantDetailsSection")}>
25-
<div className={cx("tenantDetailsHeader")}>
26-
<h3>{section.label}</h3>
27-
<p>{section.description}</p>
28-
</div>
29-
3031
<div className={cx("tenantDetailsContent")}>
3132
{users.length > 0 ? (
3233
<div className={cx("tenantDetailsUsers")}>
33-
{users.map((user) => (
34-
<div key={user.id} className={cx("userRow")}>
35-
<div className={cx("userAvatar")}>{user.emails[0]?.charAt(0).toUpperCase() || "U"}</div>
36-
<div className={cx("userEmail")}>{user.emails[0]}</div>
37-
</div>
38-
))}
34+
<TenantTable
35+
columns={users.map((user) => ({
36+
emailComponent: (
37+
<div className={cx("userRow")}>
38+
<div className={cx("userAvatar")}>{user.emails[0]?.charAt(0).toUpperCase() || "U"}</div>
39+
<div className={cx("userEmail")}>{user.emails[0]}</div>
40+
</div>
41+
)
42+
}))}
43+
/>
3944
</div>
4045
) : (
4146
<div className={cx("tenantDetailsNoUsers")}>

packages/tenants-react/src/components/tenant-management/tenant-management.tsx renamed to packages/tenants-react/src/pages/tenant-management/tenant-management.tsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { SelectInput, TabGroup, Tab } from "@shared/ui";
44
import classNames from "classnames/bind";
55
import { useState, useEffect, useCallback } from "react";
66

7+
import { InvitationsWrapper } from "../../components/invitations/invitations";
8+
import { TenantTab } from "../../components/tab/TenantTab";
9+
import { TenantUsers } from "../../components/users/TenantUsers";
710
import { usePluginContext } from "../../plugin";
8-
import { DetailsWrapper } from "../details/details-wrapper";
9-
import { InvitationsWrapper } from "../invitations/invitations";
1011

1112
import style from "./styles.module.scss";
1213

@@ -44,16 +45,13 @@ export const TenantManagement = ({ section }: { section: any }) => {
4445
}, [getUsers]);
4546

4647
// Invitations tab functions
47-
const onFetchInvitations = useCallback(
48-
async () => {
49-
const response = await getInvitations();
50-
if (response.status === "ERROR") {
51-
throw new Error(response.message);
52-
}
53-
return { invitations: response.invitees };
54-
},
55-
[getInvitations],
56-
);
48+
const onFetchInvitations = useCallback(async () => {
49+
const response = await getInvitations();
50+
if (response.status === "ERROR") {
51+
throw new Error(response.message);
52+
}
53+
return { invitations: response.invitees };
54+
}, [getInvitations]);
5755

5856
const onRemoveInvite = useCallback(
5957
async (email: string) => {
@@ -117,15 +115,11 @@ export const TenantManagement = ({ section }: { section: any }) => {
117115
<div>
118116
<TabGroup>
119117
<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-
/>
118+
<TenantTab description="List of users that are part of your tenant">
119+
<TenantUsers
120+
onFetch={onFetchUsers}
121+
/>
122+
</TenantTab>
129123
</Tab>
130124
<Tab panel={t("PL_TB_INVITATIONS_TAB_LABEL")}>
131125
<InvitationsWrapper

packages/tenants-react/src/plugin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { getTranslationFunction, SuperTokensPlugin, SuperTokensPublicConfig, Sup
44
import { BooleanClaim } from "supertokens-auth-react/recipe/session";
55

66
import { getApi } from "./api";
7-
import { TenantManagement } from "./components";
87
import { API_PATH, PLUGIN_ID } from "./constants";
98
// import { InvitationAcceptWrapper } from "./invitation-accept-wrapper";
109
import { enableDebugLogs } from "./logger";
10+
import { TenantManagement } from "./pages/tenant-management/tenant-management";
1111
// import { SelectTenantPage } from "./select-tenant-page";
1212
import { defaultTranslationsTenants } from "./translations";
1313
import { SuperTokensPluginTenantsPluginConfig, SuperTokensPluginTenantsPluginNormalisedConfig, TranslationKeys } from "./types";

packages/tenants-react/src/tenant-details-wrapper.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// import { BaseFormSection } from "@supertokens-plugin-profile/common-details-shared";
2-
import { useCallback } from "react";
2+
import { useCallback } from 'react';
33

4-
import { DetailsWrapper } from "./components/details/details-wrapper";
5-
import { usePluginContext } from "./plugin";
4+
import { DetailsWrapper } from './components/users/TenantUsers';
5+
import { usePluginContext } from './plugin';
66

77
export const TenantDetailsWrapper = ({ section }: { section: any }) => {
88
const { api } = usePluginContext();
@@ -11,7 +11,7 @@ export const TenantDetailsWrapper = ({ section }: { section: any }) => {
1111
// Use the `tid` from the users access token payload.
1212

1313
const response = await api.getUsers();
14-
if (response.status === "ERROR") {
14+
if (response.status === 'ERROR') {
1515
throw new Error(response.message);
1616
}
1717
return { users: response.users };

0 commit comments

Comments
 (0)