@firecms/user_management 3.0.0-canary.117 → 3.0.0-canary.118
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.
@@ -2,10 +2,18 @@ import React, { useCallback, useEffect } from "react";
|
|
2
2
|
import equal from "react-fast-compare"
|
3
3
|
|
4
4
|
import { UserManagement } from "../types";
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
Authenticator,
|
7
|
+
DataSourceDelegate,
|
8
|
+
Entity,
|
9
|
+
PermissionsBuilder,
|
10
|
+
removeUndefined,
|
11
|
+
Role,
|
12
|
+
User
|
13
|
+
} from "@firecms/core";
|
6
14
|
import { resolveUserRolePermissions } from "../utils";
|
7
15
|
|
8
|
-
type UserWithRoleIds = User & { roles: string[] };
|
16
|
+
type UserWithRoleIds = Omit<User, "roles"> & { roles: string[] };
|
9
17
|
|
10
18
|
export interface UserManagementParams {
|
11
19
|
|
@@ -154,15 +162,22 @@ export function useBuildUserManagement({
|
|
154
162
|
const roleIds = user.roles?.map(r => r.id);
|
155
163
|
const email = user.email?.toLowerCase().trim();
|
156
164
|
if (!email) throw Error("Email is required");
|
165
|
+
|
166
|
+
const userExists = users.find(u => u.email?.toLowerCase() === email);
|
157
167
|
const data = {
|
158
168
|
...user,
|
159
|
-
roles: roleIds
|
169
|
+
roles: roleIds ?? []
|
160
170
|
};
|
171
|
+
if (!userExists) {
|
172
|
+
// @ts-ignore
|
173
|
+
data.created_on = new Date();
|
174
|
+
}
|
175
|
+
|
161
176
|
return dataSourceDelegate.saveEntity({
|
162
177
|
status: "existing",
|
163
178
|
path: usersPath,
|
164
179
|
entityId: email,
|
165
|
-
values: data
|
180
|
+
values: removeUndefined(data)
|
166
181
|
}).then(() => user);
|
167
182
|
}, [usersPath, dataSourceDelegate?.initialised]);
|
168
183
|
|
@@ -178,7 +193,7 @@ export function useBuildUserManagement({
|
|
178
193
|
status: "existing",
|
179
194
|
path: rolesPath,
|
180
195
|
entityId: id,
|
181
|
-
values: roleData
|
196
|
+
values: removeUndefined(roleData)
|
182
197
|
}).then(() => {
|
183
198
|
return;
|
184
199
|
});
|