@@ -13,20 +13,21 @@ import style from "./styles.module.scss";
1313const cx = classNames . bind ( style ) ;
1414
1515export 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} ;
0 commit comments