@abpjs/tenant-management 0.7.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/LICENSE +165 -0
- package/README.md +549 -0
- package/dist/TenantManagementModal/TenantManagementModal.d.ts +60 -0
- package/dist/TenantManagementModal/index.d.ts +2 -0
- package/dist/components/TenantManagementModal/TenantManagementModal.d.ts +60 -0
- package/dist/components/TenantManagementModal/index.d.ts +2 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useTenantManagement.d.ts +80 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +553 -0
- package/dist/index.mjs +530 -0
- package/dist/models/index.d.ts +47 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/tenant-management.service.d.ts +57 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version of
|
|
113
|
+
the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
# @abpjs/tenant-management
|
|
2
|
+
|
|
3
|
+
> Multi-tenant management UI components for ABP Framework in React
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@abpjs/tenant-management)
|
|
6
|
+
[](https://www.gnu.org/licenses/lgpl-3.0)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`@abpjs/tenant-management` provides a complete tenant management interface for ABP-based multi-tenant SaaS applications in React. It enables administrators to create, update, delete, and manage tenants through an intuitive UI.
|
|
11
|
+
|
|
12
|
+
This package is a React translation of the original `@abp/ng.tenant-management` Angular package, bringing full multi-tenant management capabilities to React applications.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Tenant CRUD** - Create, read, update, and delete tenants
|
|
17
|
+
- **Tenant Modal** - Ready-to-use modal dialog for tenant management
|
|
18
|
+
- **Connection Strings** - Manage tenant-specific database connections
|
|
19
|
+
- **Feature Management** - Configure features per tenant
|
|
20
|
+
- **Permission Integration** - Seamlessly integrates with permission management
|
|
21
|
+
- **Chakra UI** - Beautiful, accessible components
|
|
22
|
+
- **TypeScript** - Full type safety with comprehensive definitions
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Using npm
|
|
28
|
+
npm install @abpjs/tenant-management
|
|
29
|
+
|
|
30
|
+
# Using yarn
|
|
31
|
+
yarn add @abpjs/tenant-management
|
|
32
|
+
|
|
33
|
+
# Using pnpm
|
|
34
|
+
pnpm add @abpjs/tenant-management
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Required Dependencies
|
|
38
|
+
|
|
39
|
+
This package requires the following peer dependencies:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install @abpjs/core @abpjs/theme-shared @chakra-ui/react @emotion/react @emotion/styled framer-motion
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Basic Tenant Management
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useState, useEffect } from 'react';
|
|
51
|
+
import {
|
|
52
|
+
TenantManagementModal,
|
|
53
|
+
useTenantManagement
|
|
54
|
+
} from '@abpjs/tenant-management';
|
|
55
|
+
import {
|
|
56
|
+
Table,
|
|
57
|
+
Button,
|
|
58
|
+
IconButton,
|
|
59
|
+
useDisclosure
|
|
60
|
+
} from '@chakra-ui/react';
|
|
61
|
+
import { EditIcon, DeleteIcon, AddIcon } from '@chakra-ui/icons';
|
|
62
|
+
|
|
63
|
+
function TenantManagementPage() {
|
|
64
|
+
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
65
|
+
const { tenants, getTenants, deleteTenant, isLoading } = useTenantManagement();
|
|
66
|
+
const [selectedTenant, setSelectedTenant] = useState(null);
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
getTenants();
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
const handleEdit = (tenant) => {
|
|
73
|
+
setSelectedTenant(tenant);
|
|
74
|
+
onOpen();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const handleCreate = () => {
|
|
78
|
+
setSelectedTenant(null);
|
|
79
|
+
onOpen();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const handleDelete = async (tenant) => {
|
|
83
|
+
if (confirm(`Delete tenant "${tenant.name}"?`)) {
|
|
84
|
+
await deleteTenant(tenant.id);
|
|
85
|
+
getTenants();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div>
|
|
91
|
+
<Button leftIcon={<AddIcon />} onClick={handleCreate}>
|
|
92
|
+
New Tenant
|
|
93
|
+
</Button>
|
|
94
|
+
|
|
95
|
+
<Table>
|
|
96
|
+
<thead>
|
|
97
|
+
<tr>
|
|
98
|
+
<th>Name</th>
|
|
99
|
+
<th>Actions</th>
|
|
100
|
+
</tr>
|
|
101
|
+
</thead>
|
|
102
|
+
<tbody>
|
|
103
|
+
{tenants.map(tenant => (
|
|
104
|
+
<tr key={tenant.id}>
|
|
105
|
+
<td>{tenant.name}</td>
|
|
106
|
+
<td>
|
|
107
|
+
<IconButton
|
|
108
|
+
icon={<EditIcon />}
|
|
109
|
+
onClick={() => handleEdit(tenant)}
|
|
110
|
+
/>
|
|
111
|
+
<IconButton
|
|
112
|
+
icon={<DeleteIcon />}
|
|
113
|
+
onClick={() => handleDelete(tenant)}
|
|
114
|
+
/>
|
|
115
|
+
</td>
|
|
116
|
+
</tr>
|
|
117
|
+
))}
|
|
118
|
+
</tbody>
|
|
119
|
+
</Table>
|
|
120
|
+
|
|
121
|
+
<TenantManagementModal
|
|
122
|
+
isOpen={isOpen}
|
|
123
|
+
onClose={onClose}
|
|
124
|
+
tenant={selectedTenant}
|
|
125
|
+
onSave={() => {
|
|
126
|
+
getTenants();
|
|
127
|
+
onClose();
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Creating a New Tenant
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
import { TenantManagementModal } from '@abpjs/tenant-management';
|
|
139
|
+
|
|
140
|
+
function CreateTenantButton() {
|
|
141
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<>
|
|
145
|
+
<Button onClick={() => setIsOpen(true)}>
|
|
146
|
+
Create Tenant
|
|
147
|
+
</Button>
|
|
148
|
+
|
|
149
|
+
<TenantManagementModal
|
|
150
|
+
isOpen={isOpen}
|
|
151
|
+
onClose={() => setIsOpen(false)}
|
|
152
|
+
onSave={() => {
|
|
153
|
+
console.log('Tenant created!');
|
|
154
|
+
setIsOpen(false);
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
</>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Editing an Existing Tenant
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { TenantManagementModal } from '@abpjs/tenant-management';
|
|
166
|
+
|
|
167
|
+
function EditTenantButton({ tenant }) {
|
|
168
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<Button onClick={() => setIsOpen(true)}>
|
|
173
|
+
Edit
|
|
174
|
+
</Button>
|
|
175
|
+
|
|
176
|
+
<TenantManagementModal
|
|
177
|
+
isOpen={isOpen}
|
|
178
|
+
onClose={() => setIsOpen(false)}
|
|
179
|
+
tenant={tenant} // Pass existing tenant for edit mode
|
|
180
|
+
onSave={() => {
|
|
181
|
+
console.log('Tenant updated!');
|
|
182
|
+
setIsOpen(false);
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
</>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Components
|
|
191
|
+
|
|
192
|
+
### TenantManagementModal
|
|
193
|
+
|
|
194
|
+
The main component for creating and editing tenants.
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
import { TenantManagementModal } from '@abpjs/tenant-management';
|
|
198
|
+
|
|
199
|
+
<TenantManagementModal
|
|
200
|
+
isOpen={isOpen}
|
|
201
|
+
onClose={handleClose}
|
|
202
|
+
tenant={selectedTenant} // null for create, tenant object for edit
|
|
203
|
+
onSave={handleSave}
|
|
204
|
+
/>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Props:**
|
|
208
|
+
|
|
209
|
+
| Prop | Type | Description |
|
|
210
|
+
|------|------|-------------|
|
|
211
|
+
| `isOpen` | `boolean` | Controls modal visibility |
|
|
212
|
+
| `onClose` | `() => void` | Callback when modal is closed |
|
|
213
|
+
| `tenant` | `Tenant \| null` | Tenant to edit, or null for create mode |
|
|
214
|
+
| `onSave` | `() => void` | Callback after tenant is saved |
|
|
215
|
+
|
|
216
|
+
## Hooks
|
|
217
|
+
|
|
218
|
+
### useTenantManagement
|
|
219
|
+
|
|
220
|
+
Hook for accessing tenant management functionality.
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
import { useTenantManagement } from '@abpjs/tenant-management';
|
|
224
|
+
|
|
225
|
+
function TenantsPage() {
|
|
226
|
+
const {
|
|
227
|
+
tenants, // Array of tenants
|
|
228
|
+
isLoading, // Loading state
|
|
229
|
+
error, // Error state
|
|
230
|
+
getTenants, // Fetch all tenants
|
|
231
|
+
getTenant, // Fetch single tenant by ID
|
|
232
|
+
createTenant, // Create new tenant
|
|
233
|
+
updateTenant, // Update existing tenant
|
|
234
|
+
deleteTenant, // Delete tenant
|
|
235
|
+
} = useTenantManagement();
|
|
236
|
+
|
|
237
|
+
useEffect(() => {
|
|
238
|
+
getTenants();
|
|
239
|
+
}, []);
|
|
240
|
+
|
|
241
|
+
const handleCreate = async () => {
|
|
242
|
+
await createTenant({
|
|
243
|
+
name: 'New Tenant',
|
|
244
|
+
adminEmailAddress: 'admin@newtenant.com',
|
|
245
|
+
adminPassword: 'SecurePassword123!',
|
|
246
|
+
});
|
|
247
|
+
getTenants();
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div>
|
|
252
|
+
{isLoading ? (
|
|
253
|
+
<Spinner />
|
|
254
|
+
) : (
|
|
255
|
+
<TenantList tenants={tenants} />
|
|
256
|
+
)}
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## Services
|
|
263
|
+
|
|
264
|
+
### TenantManagementService
|
|
265
|
+
|
|
266
|
+
Service class for direct API interaction.
|
|
267
|
+
|
|
268
|
+
```tsx
|
|
269
|
+
import { TenantManagementService } from '@abpjs/tenant-management';
|
|
270
|
+
|
|
271
|
+
// Get all tenants
|
|
272
|
+
const tenants = await TenantManagementService.getList({
|
|
273
|
+
filter: '',
|
|
274
|
+
sorting: 'name',
|
|
275
|
+
skipCount: 0,
|
|
276
|
+
maxResultCount: 10,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// Get single tenant
|
|
280
|
+
const tenant = await TenantManagementService.get(tenantId);
|
|
281
|
+
|
|
282
|
+
// Create tenant
|
|
283
|
+
const newTenant = await TenantManagementService.create({
|
|
284
|
+
name: 'Acme Corp',
|
|
285
|
+
adminEmailAddress: 'admin@acme.com',
|
|
286
|
+
adminPassword: 'SecurePassword123!',
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Update tenant
|
|
290
|
+
await TenantManagementService.update(tenantId, {
|
|
291
|
+
name: 'Acme Corporation',
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Delete tenant
|
|
295
|
+
await TenantManagementService.delete(tenantId);
|
|
296
|
+
|
|
297
|
+
// Get default connection string
|
|
298
|
+
const connectionString = await TenantManagementService.getDefaultConnectionString(tenantId);
|
|
299
|
+
|
|
300
|
+
// Update default connection string
|
|
301
|
+
await TenantManagementService.updateDefaultConnectionString(tenantId, connectionString);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## Data Models
|
|
305
|
+
|
|
306
|
+
### Tenant
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
interface Tenant {
|
|
310
|
+
id: string;
|
|
311
|
+
name: string;
|
|
312
|
+
concurrencyStamp?: string;
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### CreateTenantInput
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
interface CreateTenantInput {
|
|
320
|
+
name: string;
|
|
321
|
+
adminEmailAddress: string;
|
|
322
|
+
adminPassword: string;
|
|
323
|
+
connectionStrings?: ConnectionStrings;
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### UpdateTenantInput
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
interface UpdateTenantInput {
|
|
331
|
+
name: string;
|
|
332
|
+
concurrencyStamp?: string;
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Multi-Tenancy Concepts
|
|
337
|
+
|
|
338
|
+
ABP Framework supports multi-tenancy out of the box. Key concepts:
|
|
339
|
+
|
|
340
|
+
### Tenant Isolation
|
|
341
|
+
|
|
342
|
+
Each tenant operates in isolation with:
|
|
343
|
+
- **Separate Database** - Each tenant can have its own database
|
|
344
|
+
- **Shared Database** - Tenants can share a database with data isolation
|
|
345
|
+
- **Hybrid** - Mix of dedicated and shared databases
|
|
346
|
+
|
|
347
|
+
### Connection Strings
|
|
348
|
+
|
|
349
|
+
Manage per-tenant database connections:
|
|
350
|
+
|
|
351
|
+
```tsx
|
|
352
|
+
import { TenantManagementService } from '@abpjs/tenant-management';
|
|
353
|
+
|
|
354
|
+
// Set tenant-specific connection string
|
|
355
|
+
await TenantManagementService.updateDefaultConnectionString(
|
|
356
|
+
tenantId,
|
|
357
|
+
'Server=tenant-db;Database=TenantDB;...'
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
// Clear connection string (use host's database)
|
|
361
|
+
await TenantManagementService.deleteDefaultConnectionString(tenantId);
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Complete Example
|
|
365
|
+
|
|
366
|
+
Full tenant management page:
|
|
367
|
+
|
|
368
|
+
```tsx
|
|
369
|
+
import { useState, useEffect } from 'react';
|
|
370
|
+
import { usePermission } from '@abpjs/core';
|
|
371
|
+
import {
|
|
372
|
+
TenantManagementModal,
|
|
373
|
+
useTenantManagement
|
|
374
|
+
} from '@abpjs/tenant-management';
|
|
375
|
+
import { PermissionManagementModal } from '@abpjs/permission-management';
|
|
376
|
+
import {
|
|
377
|
+
Box,
|
|
378
|
+
Table,
|
|
379
|
+
Thead,
|
|
380
|
+
Tbody,
|
|
381
|
+
Tr,
|
|
382
|
+
Th,
|
|
383
|
+
Td,
|
|
384
|
+
Button,
|
|
385
|
+
IconButton,
|
|
386
|
+
HStack,
|
|
387
|
+
useDisclosure,
|
|
388
|
+
useToast,
|
|
389
|
+
} from '@chakra-ui/react';
|
|
390
|
+
import { AddIcon, EditIcon, DeleteIcon, SettingsIcon } from '@chakra-ui/icons';
|
|
391
|
+
|
|
392
|
+
function TenantManagementPage() {
|
|
393
|
+
const toast = useToast();
|
|
394
|
+
const { hasPermission } = usePermission();
|
|
395
|
+
|
|
396
|
+
// Tenant modal state
|
|
397
|
+
const tenantModal = useDisclosure();
|
|
398
|
+
const [selectedTenant, setSelectedTenant] = useState(null);
|
|
399
|
+
|
|
400
|
+
// Permission modal state
|
|
401
|
+
const permissionModal = useDisclosure();
|
|
402
|
+
const [permissionTenant, setPermissionTenant] = useState(null);
|
|
403
|
+
|
|
404
|
+
// Tenant management hook
|
|
405
|
+
const {
|
|
406
|
+
tenants,
|
|
407
|
+
getTenants,
|
|
408
|
+
deleteTenant,
|
|
409
|
+
isLoading,
|
|
410
|
+
} = useTenantManagement();
|
|
411
|
+
|
|
412
|
+
// Permission checks
|
|
413
|
+
const canCreate = hasPermission('AbpTenantManagement.Tenants.Create');
|
|
414
|
+
const canEdit = hasPermission('AbpTenantManagement.Tenants.Update');
|
|
415
|
+
const canDelete = hasPermission('AbpTenantManagement.Tenants.Delete');
|
|
416
|
+
const canManageFeatures = hasPermission('AbpTenantManagement.Tenants.ManageFeatures');
|
|
417
|
+
|
|
418
|
+
useEffect(() => {
|
|
419
|
+
getTenants();
|
|
420
|
+
}, []);
|
|
421
|
+
|
|
422
|
+
const handleCreate = () => {
|
|
423
|
+
setSelectedTenant(null);
|
|
424
|
+
tenantModal.onOpen();
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
const handleEdit = (tenant) => {
|
|
428
|
+
setSelectedTenant(tenant);
|
|
429
|
+
tenantModal.onOpen();
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const handleDelete = async (tenant) => {
|
|
433
|
+
if (window.confirm(`Are you sure you want to delete "${tenant.name}"?`)) {
|
|
434
|
+
try {
|
|
435
|
+
await deleteTenant(tenant.id);
|
|
436
|
+
toast({ title: 'Tenant deleted', status: 'success' });
|
|
437
|
+
getTenants();
|
|
438
|
+
} catch (error) {
|
|
439
|
+
toast({ title: 'Failed to delete tenant', status: 'error' });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const handleManageFeatures = (tenant) => {
|
|
445
|
+
setPermissionTenant(tenant);
|
|
446
|
+
permissionModal.onOpen();
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const handleSave = () => {
|
|
450
|
+
getTenants();
|
|
451
|
+
tenantModal.onClose();
|
|
452
|
+
toast({ title: 'Tenant saved', status: 'success' });
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<Box p={4}>
|
|
457
|
+
<HStack justify="space-between" mb={4}>
|
|
458
|
+
<h1>Tenant Management</h1>
|
|
459
|
+
{canCreate && (
|
|
460
|
+
<Button leftIcon={<AddIcon />} colorScheme="blue" onClick={handleCreate}>
|
|
461
|
+
New Tenant
|
|
462
|
+
</Button>
|
|
463
|
+
)}
|
|
464
|
+
</HStack>
|
|
465
|
+
|
|
466
|
+
<Table>
|
|
467
|
+
<Thead>
|
|
468
|
+
<Tr>
|
|
469
|
+
<Th>Name</Th>
|
|
470
|
+
<Th>Actions</Th>
|
|
471
|
+
</Tr>
|
|
472
|
+
</Thead>
|
|
473
|
+
<Tbody>
|
|
474
|
+
{tenants.map(tenant => (
|
|
475
|
+
<Tr key={tenant.id}>
|
|
476
|
+
<Td>{tenant.name}</Td>
|
|
477
|
+
<Td>
|
|
478
|
+
<HStack spacing={2}>
|
|
479
|
+
{canEdit && (
|
|
480
|
+
<IconButton
|
|
481
|
+
aria-label="Edit"
|
|
482
|
+
icon={<EditIcon />}
|
|
483
|
+
size="sm"
|
|
484
|
+
onClick={() => handleEdit(tenant)}
|
|
485
|
+
/>
|
|
486
|
+
)}
|
|
487
|
+
{canManageFeatures && (
|
|
488
|
+
<IconButton
|
|
489
|
+
aria-label="Manage Features"
|
|
490
|
+
icon={<SettingsIcon />}
|
|
491
|
+
size="sm"
|
|
492
|
+
onClick={() => handleManageFeatures(tenant)}
|
|
493
|
+
/>
|
|
494
|
+
)}
|
|
495
|
+
{canDelete && (
|
|
496
|
+
<IconButton
|
|
497
|
+
aria-label="Delete"
|
|
498
|
+
icon={<DeleteIcon />}
|
|
499
|
+
size="sm"
|
|
500
|
+
colorScheme="red"
|
|
501
|
+
onClick={() => handleDelete(tenant)}
|
|
502
|
+
/>
|
|
503
|
+
)}
|
|
504
|
+
</HStack>
|
|
505
|
+
</Td>
|
|
506
|
+
</Tr>
|
|
507
|
+
))}
|
|
508
|
+
</Tbody>
|
|
509
|
+
</Table>
|
|
510
|
+
|
|
511
|
+
<TenantManagementModal
|
|
512
|
+
isOpen={tenantModal.isOpen}
|
|
513
|
+
onClose={tenantModal.onClose}
|
|
514
|
+
tenant={selectedTenant}
|
|
515
|
+
onSave={handleSave}
|
|
516
|
+
/>
|
|
517
|
+
|
|
518
|
+
<PermissionManagementModal
|
|
519
|
+
isOpen={permissionModal.isOpen}
|
|
520
|
+
onClose={permissionModal.onClose}
|
|
521
|
+
providerName="T"
|
|
522
|
+
providerKey={permissionTenant?.id}
|
|
523
|
+
/>
|
|
524
|
+
</Box>
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export default TenantManagementPage;
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Related Packages
|
|
532
|
+
|
|
533
|
+
- [@abpjs/core](https://www.npmjs.com/package/@abpjs/core) - Core infrastructure (required)
|
|
534
|
+
- [@abpjs/theme-shared](https://www.npmjs.com/package/@abpjs/theme-shared) - Shared UI components (required)
|
|
535
|
+
- [@abpjs/permission-management](https://www.npmjs.com/package/@abpjs/permission-management) - Permission management
|
|
536
|
+
- [@abpjs/account](https://www.npmjs.com/package/@abpjs/account) - Account management
|
|
537
|
+
- [@abpjs/theme-basic](https://www.npmjs.com/package/@abpjs/theme-basic) - Layout components
|
|
538
|
+
|
|
539
|
+
## Contributing
|
|
540
|
+
|
|
541
|
+
This package is part of the [ABP React](https://github.com/abpjs/abp-react) monorepo. Contributions are welcome!
|
|
542
|
+
|
|
543
|
+
## License
|
|
544
|
+
|
|
545
|
+
LGPL-3.0 - See [LICENSE](https://github.com/abpjs/abp-react/blob/main/LICENSE) for details.
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
**[View Full Documentation](https://docs.abpjs.io/docs/packages/tenant-management/overview)** | **[Report Issues](https://github.com/abpjs/abp-react/issues)** | **[View Source](https://github.com/abpjs/abp-react/tree/main/packages/tenant-management)**
|