@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
@@ -1,4 +1,6 @@
|
|
1
1
|
import React, { useCallback, useEffect } from "react";
|
2
|
+
import equal from "react-fast-compare"
|
3
|
+
|
2
4
|
import { UserManagement } from "../types";
|
3
5
|
import { Authenticator, DataSourceDelegate, Entity, PermissionsBuilder, Role, User } from "@firecms/core";
|
4
6
|
import { resolveUserRolePermissions } from "../utils";
|
@@ -57,16 +59,18 @@ export interface UserManagementParams {
|
|
57
59
|
* @param rolesPath
|
58
60
|
* @param usersLimit
|
59
61
|
* @param canEditRoles
|
62
|
+
* @param allowDefaultRolesCreation
|
63
|
+
* @param includeCollectionConfigPermissions
|
60
64
|
*/
|
61
65
|
export function useBuildUserManagement({
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
dataSourceDelegate,
|
67
|
+
usersPath = "__FIRECMS/config/users",
|
68
|
+
rolesPath = "__FIRECMS/config/roles",
|
69
|
+
usersLimit,
|
70
|
+
canEditRoles = true,
|
71
|
+
allowDefaultRolesCreation,
|
72
|
+
includeCollectionConfigPermissions
|
73
|
+
}: UserManagementParams): UserManagement {
|
70
74
|
|
71
75
|
const [rolesLoading, setRolesLoading] = React.useState<boolean>(true);
|
72
76
|
const [usersLoading, setUsersLoading] = React.useState<boolean>(true);
|
@@ -85,14 +89,16 @@ export function useBuildUserManagement({
|
|
85
89
|
|
86
90
|
useEffect(() => {
|
87
91
|
if (!dataSourceDelegate || !rolesPath) return;
|
92
|
+
if (dataSourceDelegate.initialised !== undefined && !dataSourceDelegate.initialised) return;
|
88
93
|
|
89
|
-
dataSourceDelegate.listenCollection?.({
|
94
|
+
return dataSourceDelegate.listenCollection?.({
|
90
95
|
path: rolesPath,
|
91
96
|
onUpdate(entities: Entity<any>[]): void {
|
92
97
|
setRolesError(undefined);
|
93
98
|
try {
|
94
99
|
const newRoles = entityToRoles(entities);
|
95
|
-
|
100
|
+
if (!equal(newRoles, roles))
|
101
|
+
setRoles(newRoles);
|
96
102
|
} catch (e) {
|
97
103
|
console.error("Error loading roles", e);
|
98
104
|
setRolesError(e as Error);
|
@@ -110,14 +116,16 @@ export function useBuildUserManagement({
|
|
110
116
|
|
111
117
|
useEffect(() => {
|
112
118
|
if (!dataSourceDelegate || !usersPath) return;
|
119
|
+
if (dataSourceDelegate.initialised !== undefined && !dataSourceDelegate.initialised) return;
|
113
120
|
|
114
|
-
dataSourceDelegate.listenCollection?.({
|
121
|
+
return dataSourceDelegate.listenCollection?.({
|
115
122
|
path: usersPath,
|
116
123
|
onUpdate(entities: Entity<any>[]): void {
|
117
124
|
setUsersError(undefined);
|
118
125
|
try {
|
119
126
|
const newUsers = entitiesToUsers(entities);
|
120
|
-
|
127
|
+
if (!equal(newUsers, usersWithRoleIds))
|
128
|
+
setUsersWithRoleIds(newUsers);
|
121
129
|
} catch (e) {
|
122
130
|
console.error("Error loading users", e);
|
123
131
|
setUsersError(e as Error);
|
@@ -134,8 +142,8 @@ export function useBuildUserManagement({
|
|
134
142
|
}, [dataSourceDelegate, usersPath]);
|
135
143
|
|
136
144
|
const saveUser = useCallback(async (user: User): Promise<User> => {
|
137
|
-
if (!dataSourceDelegate) throw Error("
|
138
|
-
if (!usersPath) throw Error("
|
145
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
146
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
139
147
|
|
140
148
|
console.debug("Persisting user", user);
|
141
149
|
|
@@ -165,8 +173,8 @@ export function useBuildUserManagement({
|
|
165
173
|
}, [usersPath, dataSourceDelegate]);
|
166
174
|
|
167
175
|
const saveRole = useCallback((role: Role): Promise<void> => {
|
168
|
-
if (!dataSourceDelegate) throw Error("
|
169
|
-
if (!rolesPath) throw Error("
|
176
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
177
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
170
178
|
console.debug("Persisting role", role);
|
171
179
|
const {
|
172
180
|
id,
|
@@ -183,8 +191,8 @@ export function useBuildUserManagement({
|
|
183
191
|
}, [rolesPath, dataSourceDelegate]);
|
184
192
|
|
185
193
|
const deleteUser = useCallback(async (user: User): Promise<void> => {
|
186
|
-
if (!dataSourceDelegate) throw Error("
|
187
|
-
if (!usersPath) throw Error("
|
194
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
195
|
+
if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
|
188
196
|
console.debug("Deleting", user);
|
189
197
|
const { uid } = user;
|
190
198
|
const entity: Entity<any> = {
|
@@ -196,8 +204,8 @@ export function useBuildUserManagement({
|
|
196
204
|
}, [usersPath, dataSourceDelegate]);
|
197
205
|
|
198
206
|
const deleteRole = useCallback(async (role: Role): Promise<void> => {
|
199
|
-
if (!dataSourceDelegate) throw Error("
|
200
|
-
if (!rolesPath) throw Error("
|
207
|
+
if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
|
208
|
+
if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
|
201
209
|
console.debug("Deleting", role);
|
202
210
|
const { id } = role;
|
203
211
|
const entity: Entity<any> = {
|