@firecms/user_management 3.0.0-beta.13 → 3.0.0-beta.15
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/index.es.js +119 -98
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +118 -97
- package/dist/index.umd.js.map +1 -1
- package/dist/types/user_management.d.ts +5 -0
- package/package.json +5 -5
- package/src/components/roles/RolesDetailsForm.tsx +1 -1
- package/src/components/users/UserDetailsForm.tsx +1 -1
- package/src/hooks/useBuildUserManagement.tsx +40 -0
- package/src/types/user_management.tsx +6 -0
package/dist/index.es.js
CHANGED
|
@@ -3,7 +3,7 @@ import equal from "react-fast-compare";
|
|
|
3
3
|
import { removeUndefined, useAuthController, toSnakeCase, FieldCaption, ConfirmationDialog, useNavigationController, useSnackbarController, useCustomizationController, defaultDateFormat } from "@firecms/core";
|
|
4
4
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { c } from "react-compiler-runtime";
|
|
6
|
-
import { getColorSchemeForSeed, Chip, TextField, TableRow, TableCell, Checkbox, Tooltip, Button, Typography, DialogTitle, TableHeader, Paper, Table, TableBody, SelectItem, Select, DialogContent,
|
|
6
|
+
import { getColorSchemeForSeed, Chip, TextField, TableRow, TableCell, Checkbox, Tooltip, Button, Typography, DialogTitle, TableHeader, Paper, Table, TableBody, SelectItem, Select, DialogContent, LoadingButton, DialogActions, Dialog, IconButton, DeleteIcon, CenteredView, AddIcon, Container, MultiSelectItem, MultiSelect } from "@firecms/ui";
|
|
7
7
|
import * as Yup from "yup";
|
|
8
8
|
import { useCreateFormex, getIn, Formex } from "@firecms/formex";
|
|
9
9
|
import { format } from "date-fns";
|
|
@@ -242,6 +242,20 @@ function useBuildUserManagement({
|
|
|
242
242
|
if (!userExists) {
|
|
243
243
|
data.created_on = /* @__PURE__ */ new Date();
|
|
244
244
|
}
|
|
245
|
+
if (userExists && userExists.uid !== user.uid) {
|
|
246
|
+
const entity = {
|
|
247
|
+
values: {},
|
|
248
|
+
path: usersPath,
|
|
249
|
+
id: userExists.uid
|
|
250
|
+
};
|
|
251
|
+
await dataSourceDelegate.deleteEntity({
|
|
252
|
+
entity
|
|
253
|
+
}).then(() => {
|
|
254
|
+
console.debug("Deleted previous user", userExists);
|
|
255
|
+
}).catch((e_3) => {
|
|
256
|
+
console.error("Error deleting user", e_3);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
245
259
|
return dataSourceDelegate.saveEntity({
|
|
246
260
|
status: "existing",
|
|
247
261
|
path: usersPath,
|
|
@@ -273,13 +287,13 @@ function useBuildUserManagement({
|
|
|
273
287
|
const {
|
|
274
288
|
uid
|
|
275
289
|
} = user_0;
|
|
276
|
-
const
|
|
290
|
+
const entity_0 = {
|
|
277
291
|
path: usersPath,
|
|
278
292
|
id: uid,
|
|
279
293
|
values: {}
|
|
280
294
|
};
|
|
281
295
|
await dataSourceDelegate.deleteEntity({
|
|
282
|
-
entity
|
|
296
|
+
entity: entity_0
|
|
283
297
|
});
|
|
284
298
|
}, [usersPath, dataSourceDelegate?.initialised]);
|
|
285
299
|
const deleteRole = useCallback(async (role_0) => {
|
|
@@ -289,13 +303,13 @@ function useBuildUserManagement({
|
|
|
289
303
|
const {
|
|
290
304
|
id: id_0
|
|
291
305
|
} = role_0;
|
|
292
|
-
const
|
|
306
|
+
const entity_1 = {
|
|
293
307
|
path: rolesPath,
|
|
294
308
|
id: id_0,
|
|
295
309
|
values: {}
|
|
296
310
|
};
|
|
297
311
|
await dataSourceDelegate.deleteEntity({
|
|
298
|
-
entity:
|
|
312
|
+
entity: entity_1
|
|
299
313
|
});
|
|
300
314
|
}, [rolesPath, dataSourceDelegate?.initialised]);
|
|
301
315
|
const collectionPermissions = useCallback(({
|
|
@@ -320,12 +334,27 @@ function useBuildUserManagement({
|
|
|
320
334
|
if (loading) {
|
|
321
335
|
return false;
|
|
322
336
|
}
|
|
337
|
+
if (user_3 === null) {
|
|
338
|
+
console.warn("User is null, returning");
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
323
341
|
if (users.length === 0) {
|
|
324
342
|
console.warn("No users created yet");
|
|
325
343
|
return true;
|
|
326
344
|
}
|
|
327
345
|
const mgmtUser_0 = users.find((u_3) => u_3.email?.toLowerCase() === user_3?.email?.toLowerCase());
|
|
328
346
|
if (mgmtUser_0) {
|
|
347
|
+
if (mgmtUser_0.uid !== user_3.uid) {
|
|
348
|
+
console.warn("User uid has changed, updating user in user management system");
|
|
349
|
+
saveUser({
|
|
350
|
+
...mgmtUser_0,
|
|
351
|
+
uid: user_3.uid
|
|
352
|
+
}).then(() => {
|
|
353
|
+
console.debug("User updated in user management system", mgmtUser_0);
|
|
354
|
+
}).catch((e_4) => {
|
|
355
|
+
console.error("Error updating user in user management system", e_4);
|
|
356
|
+
});
|
|
357
|
+
}
|
|
329
358
|
console.debug("User found in user management system", mgmtUser_0);
|
|
330
359
|
return true;
|
|
331
360
|
}
|
|
@@ -338,6 +367,11 @@ function useBuildUserManagement({
|
|
|
338
367
|
console.debug("Setting roles", userRoles);
|
|
339
368
|
authController.setUserRoles?.(userRoles ?? []);
|
|
340
369
|
}, [userRoleIds]);
|
|
370
|
+
const getUser = useCallback((uid_0) => {
|
|
371
|
+
if (!users) return null;
|
|
372
|
+
const user_4 = users.find((u_4) => u_4.uid === uid_0);
|
|
373
|
+
return user_4 ?? null;
|
|
374
|
+
}, [users]);
|
|
341
375
|
return {
|
|
342
376
|
loading,
|
|
343
377
|
roles,
|
|
@@ -357,6 +391,7 @@ function useBuildUserManagement({
|
|
|
357
391
|
...authController,
|
|
358
392
|
initialLoading: authController.initialLoading || loading,
|
|
359
393
|
userRoles,
|
|
394
|
+
getUser,
|
|
360
395
|
user: authController.user ? {
|
|
361
396
|
...authController.user,
|
|
362
397
|
roles: userRoles
|
|
@@ -453,7 +488,7 @@ function canRoleBeEdited(loggedUser) {
|
|
|
453
488
|
return true;
|
|
454
489
|
}
|
|
455
490
|
function RolesDetailsForm(t0) {
|
|
456
|
-
const $ = c(
|
|
491
|
+
const $ = c(164);
|
|
457
492
|
const {
|
|
458
493
|
open,
|
|
459
494
|
role,
|
|
@@ -1068,7 +1103,7 @@ function RolesDetailsForm(t0) {
|
|
|
1068
1103
|
}
|
|
1069
1104
|
let t80;
|
|
1070
1105
|
if ($[144] !== handleClose) {
|
|
1071
|
-
t80 = /* @__PURE__ */ jsx(Button, { variant: "text", onClick: () => {
|
|
1106
|
+
t80 = /* @__PURE__ */ jsx(Button, { variant: "text", color: "primary", onClick: () => {
|
|
1072
1107
|
handleClose();
|
|
1073
1108
|
}, children: "Cancel" });
|
|
1074
1109
|
$[144] = handleClose;
|
|
@@ -1077,71 +1112,64 @@ function RolesDetailsForm(t0) {
|
|
|
1077
1112
|
t80 = $[145];
|
|
1078
1113
|
}
|
|
1079
1114
|
const t81 = !dirty;
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
const t83 = isNewRole ? "Create role" : "Update";
|
|
1088
|
-
let t84;
|
|
1089
|
-
if ($[147] !== isSubmitting || $[148] !== t81 || $[149] !== t83) {
|
|
1090
|
-
t84 = /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t81, loading: isSubmitting, startIcon: t82, children: t83 });
|
|
1091
|
-
$[147] = isSubmitting;
|
|
1092
|
-
$[148] = t81;
|
|
1115
|
+
const t82 = isNewRole ? "Create role" : "Update";
|
|
1116
|
+
let t83;
|
|
1117
|
+
if ($[146] !== isSubmitting || $[147] !== t81 || $[148] !== t82) {
|
|
1118
|
+
t83 = /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t81, loading: isSubmitting, children: t82 });
|
|
1119
|
+
$[146] = isSubmitting;
|
|
1120
|
+
$[147] = t81;
|
|
1121
|
+
$[148] = t82;
|
|
1093
1122
|
$[149] = t83;
|
|
1094
|
-
$[150] = t84;
|
|
1095
1123
|
} else {
|
|
1096
|
-
|
|
1124
|
+
t83 = $[149];
|
|
1097
1125
|
}
|
|
1098
|
-
let
|
|
1099
|
-
if ($[
|
|
1100
|
-
|
|
1126
|
+
let t84;
|
|
1127
|
+
if ($[150] !== t79 || $[151] !== t80 || $[152] !== t83) {
|
|
1128
|
+
t84 = /* @__PURE__ */ jsxs(DialogActions, { position: "sticky", children: [
|
|
1101
1129
|
t79,
|
|
1102
1130
|
t80,
|
|
1103
|
-
|
|
1131
|
+
t83
|
|
1104
1132
|
] });
|
|
1105
|
-
$[
|
|
1106
|
-
$[
|
|
1133
|
+
$[150] = t79;
|
|
1134
|
+
$[151] = t80;
|
|
1135
|
+
$[152] = t83;
|
|
1107
1136
|
$[153] = t84;
|
|
1108
|
-
$[154] = t85;
|
|
1109
1137
|
} else {
|
|
1110
|
-
|
|
1138
|
+
t84 = $[153];
|
|
1111
1139
|
}
|
|
1112
|
-
let
|
|
1113
|
-
if ($[
|
|
1114
|
-
|
|
1140
|
+
let t85;
|
|
1141
|
+
if ($[154] !== formex.handleSubmit || $[155] !== t78 || $[156] !== t84) {
|
|
1142
|
+
t85 = /* @__PURE__ */ jsxs("form", { noValidate: true, autoComplete: "off", onSubmit: formex.handleSubmit, style: t7, children: [
|
|
1115
1143
|
t8,
|
|
1116
1144
|
t78,
|
|
1117
|
-
|
|
1145
|
+
t84
|
|
1118
1146
|
] });
|
|
1119
|
-
$[
|
|
1120
|
-
$[
|
|
1147
|
+
$[154] = formex.handleSubmit;
|
|
1148
|
+
$[155] = t78;
|
|
1149
|
+
$[156] = t84;
|
|
1121
1150
|
$[157] = t85;
|
|
1122
|
-
$[158] = t86;
|
|
1123
1151
|
} else {
|
|
1124
|
-
|
|
1152
|
+
t85 = $[157];
|
|
1125
1153
|
}
|
|
1126
|
-
let
|
|
1127
|
-
if ($[
|
|
1128
|
-
|
|
1129
|
-
$[
|
|
1154
|
+
let t86;
|
|
1155
|
+
if ($[158] !== formex || $[159] !== t85) {
|
|
1156
|
+
t86 = /* @__PURE__ */ jsx(Formex, { value: formex, children: t85 });
|
|
1157
|
+
$[158] = formex;
|
|
1158
|
+
$[159] = t85;
|
|
1130
1159
|
$[160] = t86;
|
|
1131
|
-
$[161] = t87;
|
|
1132
1160
|
} else {
|
|
1133
|
-
|
|
1161
|
+
t86 = $[160];
|
|
1134
1162
|
}
|
|
1135
|
-
let
|
|
1136
|
-
if ($[
|
|
1137
|
-
|
|
1138
|
-
$[
|
|
1163
|
+
let t87;
|
|
1164
|
+
if ($[161] !== open || $[162] !== t86) {
|
|
1165
|
+
t87 = /* @__PURE__ */ jsx(Dialog, { open, maxWidth: "4xl", children: t86 });
|
|
1166
|
+
$[161] = open;
|
|
1167
|
+
$[162] = t86;
|
|
1139
1168
|
$[163] = t87;
|
|
1140
|
-
$[164] = t88;
|
|
1141
1169
|
} else {
|
|
1142
|
-
|
|
1170
|
+
t87 = $[163];
|
|
1143
1171
|
}
|
|
1144
|
-
return
|
|
1172
|
+
return t87;
|
|
1145
1173
|
}
|
|
1146
1174
|
function _temp6$1(value_1) {
|
|
1147
1175
|
return value_1 === "own" ? "Own" : value_1 === "true" ? "Yes" : "No";
|
|
@@ -1448,7 +1476,7 @@ function canUserBeEdited(loggedUser, user, users, roles, prevUser) {
|
|
|
1448
1476
|
return true;
|
|
1449
1477
|
}
|
|
1450
1478
|
function UserDetailsForm(t0) {
|
|
1451
|
-
const $ = c(
|
|
1479
|
+
const $ = c(73);
|
|
1452
1480
|
const {
|
|
1453
1481
|
open,
|
|
1454
1482
|
user: userProp,
|
|
@@ -1686,7 +1714,7 @@ function UserDetailsForm(t0) {
|
|
|
1686
1714
|
}
|
|
1687
1715
|
let t25;
|
|
1688
1716
|
if ($[53] !== handleClose) {
|
|
1689
|
-
t25 = /* @__PURE__ */ jsx(Button, { variant: "text", onClick: () => {
|
|
1717
|
+
t25 = /* @__PURE__ */ jsx(Button, { variant: "text", color: "primary", onClick: () => {
|
|
1690
1718
|
handleClose();
|
|
1691
1719
|
}, children: "Cancel" });
|
|
1692
1720
|
$[53] = handleClose;
|
|
@@ -1695,70 +1723,63 @@ function UserDetailsForm(t0) {
|
|
|
1695
1723
|
t25 = $[54];
|
|
1696
1724
|
}
|
|
1697
1725
|
const t26 = !dirty;
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
const t28 = isNewUser ? "Create user" : "Update";
|
|
1706
|
-
let t29;
|
|
1707
|
-
if ($[56] !== isSubmitting || $[57] !== t26 || $[58] !== t28) {
|
|
1708
|
-
t29 = /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t26, loading: isSubmitting, startIcon: t27, children: t28 });
|
|
1709
|
-
$[56] = isSubmitting;
|
|
1710
|
-
$[57] = t26;
|
|
1726
|
+
const t27 = isNewUser ? "Create user" : "Update";
|
|
1727
|
+
let t28;
|
|
1728
|
+
if ($[55] !== isSubmitting || $[56] !== t26 || $[57] !== t27) {
|
|
1729
|
+
t28 = /* @__PURE__ */ jsx(LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t26, loading: isSubmitting, children: t27 });
|
|
1730
|
+
$[55] = isSubmitting;
|
|
1731
|
+
$[56] = t26;
|
|
1732
|
+
$[57] = t27;
|
|
1711
1733
|
$[58] = t28;
|
|
1712
|
-
$[59] = t29;
|
|
1713
1734
|
} else {
|
|
1714
|
-
|
|
1735
|
+
t28 = $[58];
|
|
1715
1736
|
}
|
|
1716
|
-
let
|
|
1717
|
-
if ($[
|
|
1718
|
-
|
|
1737
|
+
let t29;
|
|
1738
|
+
if ($[59] !== t25 || $[60] !== t28) {
|
|
1739
|
+
t29 = /* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
1719
1740
|
t25,
|
|
1720
|
-
|
|
1741
|
+
t28
|
|
1721
1742
|
] });
|
|
1722
|
-
$[
|
|
1743
|
+
$[59] = t25;
|
|
1744
|
+
$[60] = t28;
|
|
1723
1745
|
$[61] = t29;
|
|
1724
|
-
$[62] = t30;
|
|
1725
1746
|
} else {
|
|
1726
|
-
|
|
1747
|
+
t29 = $[61];
|
|
1727
1748
|
}
|
|
1728
|
-
let
|
|
1729
|
-
if ($[
|
|
1730
|
-
|
|
1749
|
+
let t30;
|
|
1750
|
+
if ($[62] !== handleSubmit || $[63] !== t24 || $[64] !== t29) {
|
|
1751
|
+
t30 = /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, autoComplete: "off", noValidate: true, style: t6, children: [
|
|
1731
1752
|
t7,
|
|
1732
1753
|
t24,
|
|
1733
|
-
|
|
1754
|
+
t29
|
|
1734
1755
|
] });
|
|
1735
|
-
$[
|
|
1736
|
-
$[
|
|
1756
|
+
$[62] = handleSubmit;
|
|
1757
|
+
$[63] = t24;
|
|
1758
|
+
$[64] = t29;
|
|
1737
1759
|
$[65] = t30;
|
|
1738
|
-
$[66] = t31;
|
|
1739
1760
|
} else {
|
|
1740
|
-
|
|
1761
|
+
t30 = $[65];
|
|
1741
1762
|
}
|
|
1742
|
-
let
|
|
1743
|
-
if ($[
|
|
1744
|
-
|
|
1745
|
-
$[
|
|
1763
|
+
let t31;
|
|
1764
|
+
if ($[66] !== formex || $[67] !== t30) {
|
|
1765
|
+
t31 = /* @__PURE__ */ jsx(Formex, { value: formex, children: t30 });
|
|
1766
|
+
$[66] = formex;
|
|
1767
|
+
$[67] = t30;
|
|
1746
1768
|
$[68] = t31;
|
|
1747
|
-
$[69] = t32;
|
|
1748
1769
|
} else {
|
|
1749
|
-
|
|
1770
|
+
t31 = $[68];
|
|
1750
1771
|
}
|
|
1751
|
-
let
|
|
1752
|
-
if ($[
|
|
1753
|
-
|
|
1754
|
-
$[
|
|
1755
|
-
$[
|
|
1756
|
-
$[
|
|
1757
|
-
$[
|
|
1772
|
+
let t32;
|
|
1773
|
+
if ($[69] !== open || $[70] !== t31 || $[71] !== t5) {
|
|
1774
|
+
t32 = /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: t5, maxWidth: "4xl", children: t31 });
|
|
1775
|
+
$[69] = open;
|
|
1776
|
+
$[70] = t31;
|
|
1777
|
+
$[71] = t5;
|
|
1778
|
+
$[72] = t32;
|
|
1758
1779
|
} else {
|
|
1759
|
-
|
|
1780
|
+
t32 = $[72];
|
|
1760
1781
|
}
|
|
1761
|
-
return
|
|
1782
|
+
return t32;
|
|
1762
1783
|
}
|
|
1763
1784
|
function _temp7(userRole) {
|
|
1764
1785
|
return /* @__PURE__ */ jsx(MultiSelectItem, { value: userRole.id, children: /* @__PURE__ */ jsx(RoleChip, { role: userRole }, userRole?.id) }, userRole.id);
|