@firecms/user_management 3.0.0-canary.85 → 3.0.0-canary.86
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/hooks/useBuildUserManagement.d.ts +2 -0
- package/dist/index.es.js +17 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +18 -14
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/useBuildUserManagement.tsx +28 -20
@@ -43,5 +43,7 @@ export interface UserManagementParams {
|
|
43
43
|
* @param rolesPath
|
44
44
|
* @param usersLimit
|
45
45
|
* @param canEditRoles
|
46
|
+
* @param allowDefaultRolesCreation
|
47
|
+
* @param includeCollectionConfigPermissions
|
46
48
|
*/
|
47
49
|
export declare function useBuildUserManagement({ dataSourceDelegate, usersPath, rolesPath, usersLimit, canEditRoles, allowDefaultRolesCreation, includeCollectionConfigPermissions }: UserManagementParams): UserManagement;
|
package/dist/index.es.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import React, { useEffect, useCallback, useContext, useState } from "react";
|
2
|
+
import equal from "react-fast-compare";
|
2
3
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
3
4
|
import { getColorSchemeForSeed, Chip, Dialog, DialogContent, Typography, TextField, Paper, Table, TableHeader, TableCell, TableBody, TableRow, Tooltip, Checkbox, Select, SelectItem, DialogActions, Button, LoadingButton, DoneIcon, IconButton, DeleteIcon, CenteredView, Container, AddIcon, MultiSelect, MultiSelectItem } from "@firecms/ui";
|
4
5
|
import * as Yup from "yup";
|
@@ -161,13 +162,15 @@ function useBuildUserManagement({
|
|
161
162
|
const loading = rolesLoading || usersLoading;
|
162
163
|
useEffect(() => {
|
163
164
|
if (!dataSourceDelegate || !rolesPath) return;
|
164
|
-
dataSourceDelegate.
|
165
|
+
if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
|
166
|
+
return dataSourceDelegate.listenCollection?.({
|
165
167
|
path: rolesPath,
|
166
168
|
onUpdate(entities) {
|
167
169
|
setRolesError(void 0);
|
168
170
|
try {
|
169
171
|
const newRoles = entityToRoles(entities);
|
170
|
-
|
172
|
+
if (!equal(newRoles, roles))
|
173
|
+
setRoles(newRoles);
|
171
174
|
} catch (e) {
|
172
175
|
console.error("Error loading roles", e);
|
173
176
|
setRolesError(e);
|
@@ -183,13 +186,15 @@ function useBuildUserManagement({
|
|
183
186
|
}, [dataSourceDelegate, rolesPath]);
|
184
187
|
useEffect(() => {
|
185
188
|
if (!dataSourceDelegate || !usersPath) return;
|
186
|
-
dataSourceDelegate.
|
189
|
+
if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
|
190
|
+
return dataSourceDelegate.listenCollection?.({
|
187
191
|
path: usersPath,
|
188
192
|
onUpdate(entities) {
|
189
193
|
setUsersError(void 0);
|
190
194
|
try {
|
191
195
|
const newUsers = entitiesToUsers(entities);
|
192
|
-
|
196
|
+
if (!equal(newUsers, usersWithRoleIds))
|
197
|
+
setUsersWithRoleIds(newUsers);
|
193
198
|
} catch (e) {
|
194
199
|
console.error("Error loading users", e);
|
195
200
|
setUsersError(e);
|
@@ -204,8 +209,8 @@ function useBuildUserManagement({
|
|
204
209
|
});
|
205
210
|
}, [dataSourceDelegate, usersPath]);
|
206
211
|
const saveUser = useCallback(async (user) => {
|
207
|
-
if (!dataSourceDelegate) throw Error("
|
208
|
-
if (!usersPath) throw Error("
|
212
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
213
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
209
214
|
console.debug("Persisting user", user);
|
210
215
|
const roleIds = user.roles?.map((r) => r.id);
|
211
216
|
const {
|
@@ -232,8 +237,8 @@ function useBuildUserManagement({
|
|
232
237
|
}
|
233
238
|
}, [usersPath, dataSourceDelegate]);
|
234
239
|
const saveRole = useCallback((role) => {
|
235
|
-
if (!dataSourceDelegate) throw Error("
|
236
|
-
if (!rolesPath) throw Error("
|
240
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
241
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
237
242
|
console.debug("Persisting role", role);
|
238
243
|
const {
|
239
244
|
id,
|
@@ -249,8 +254,8 @@ function useBuildUserManagement({
|
|
249
254
|
});
|
250
255
|
}, [rolesPath, dataSourceDelegate]);
|
251
256
|
const deleteUser = useCallback(async (user) => {
|
252
|
-
if (!dataSourceDelegate) throw Error("
|
253
|
-
if (!usersPath) throw Error("
|
257
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
258
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
254
259
|
console.debug("Deleting", user);
|
255
260
|
const { uid } = user;
|
256
261
|
const entity = {
|
@@ -261,8 +266,8 @@ function useBuildUserManagement({
|
|
261
266
|
await dataSourceDelegate.deleteEntity({ entity });
|
262
267
|
}, [usersPath, dataSourceDelegate]);
|
263
268
|
const deleteRole = useCallback(async (role) => {
|
264
|
-
if (!dataSourceDelegate) throw Error("
|
265
|
-
if (!rolesPath) throw Error("
|
269
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
270
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
266
271
|
console.debug("Deleting", role);
|
267
272
|
const { id } = role;
|
268
273
|
const entity = {
|