@firecms/user_management 3.0.0-canary.37 → 3.0.0-canary.39
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 +415 -409
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +5 -5
- package/src/hooks/useBuildFirestoreUserManagement.tsx +11 -15
package/dist/index.es.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
import
|
2
|
-
import { getFirestore as
|
3
|
-
import { jsx as e, jsxs as l, Fragment as
|
4
|
-
import { getColorSchemeForSeed as Fe, Chip as
|
5
|
-
import * as
|
6
|
-
import { toSnakeCase as
|
7
|
-
import { useCreateFormex as
|
8
|
-
import { format as
|
9
|
-
import * as
|
10
|
-
const
|
1
|
+
import F, { useEffect as se, useCallback as I, useContext as Ie, useState as P } from "react";
|
2
|
+
import { getFirestore as q, onSnapshot as ae, collection as ee, setDoc as ce, doc as H, addDoc as ke, deleteDoc as de } from "firebase/firestore";
|
3
|
+
import { jsx as e, jsxs as l, Fragment as K } from "react/jsx-runtime";
|
4
|
+
import { getColorSchemeForSeed as Fe, Chip as Pe, Dialog as ue, DialogContent as me, Typography as $, TextField as Q, Paper as Ae, Table as ie, TableHeader as re, TableCell as a, TableBody as oe, TableRow as Y, Tooltip as _, Checkbox as k, Select as ne, SelectItem as T, DialogActions as he, Button as W, LoadingButton as fe, DoneIcon as ge, IconButton as pe, DeleteIcon as Ce, CenteredView as ve, Container as we, AddIcon as ye, MultiSelect as Te, MultiSelectItem as Be } from "@firecms/ui";
|
5
|
+
import * as O from "yup";
|
6
|
+
import { toSnakeCase as Le, FieldCaption as B, DeleteConfirmationDialog as be, useNavigationController as Ve, useSnackbarController as Ne, useAuthController as xe, useCustomizationController as _e, defaultDateFormat as Oe } from "@firecms/core";
|
7
|
+
import { useCreateFormex as Re, getIn as z, Formex as De } from "@firecms/formex";
|
8
|
+
import { format as $e } from "date-fns";
|
9
|
+
import * as Me from "date-fns/locale";
|
10
|
+
const fn = ["Admin"], qe = {
|
11
11
|
read: !1,
|
12
12
|
edit: !1,
|
13
13
|
create: !1,
|
14
14
|
delete: !1
|
15
15
|
};
|
16
|
-
function
|
16
|
+
function Ye({
|
17
17
|
collection: t,
|
18
18
|
user: i
|
19
19
|
}) {
|
@@ -27,49 +27,49 @@ function je({
|
|
27
27
|
delete: !0
|
28
28
|
};
|
29
29
|
{
|
30
|
-
const
|
30
|
+
const d = {
|
31
31
|
read: !1,
|
32
32
|
create: !1,
|
33
33
|
edit: !1,
|
34
34
|
delete: !1
|
35
35
|
};
|
36
|
-
return n.map((r) =>
|
36
|
+
return n.map((r) => We(r, t.id)).reduce(te, d);
|
37
37
|
}
|
38
38
|
} else
|
39
|
-
return
|
39
|
+
return qe;
|
40
40
|
}
|
41
|
-
function
|
41
|
+
function We(t, i) {
|
42
42
|
const n = {
|
43
43
|
read: t.isAdmin || t.defaultPermissions?.read,
|
44
44
|
create: t.isAdmin || t.defaultPermissions?.create,
|
45
45
|
edit: t.isAdmin || t.defaultPermissions?.edit,
|
46
46
|
delete: t.isAdmin || t.defaultPermissions?.delete
|
47
47
|
};
|
48
|
-
return t.collectionPermissions && t.collectionPermissions[i] ?
|
48
|
+
return t.collectionPermissions && t.collectionPermissions[i] ? te(t.collectionPermissions[i], n) : t.defaultPermissions ? te(t.defaultPermissions, n) : n;
|
49
49
|
}
|
50
|
-
const
|
50
|
+
const te = (t, i) => ({
|
51
51
|
read: t.read || i.read,
|
52
52
|
create: t.create || i.create,
|
53
53
|
edit: t.edit || i.edit,
|
54
54
|
delete: t.delete || i.delete
|
55
55
|
});
|
56
|
-
function
|
57
|
-
return t ? i.roles ? i.roles.map((n) => t.find((
|
56
|
+
function gn(t, i) {
|
57
|
+
return t ? i.roles ? i.roles.map((n) => t.find((d) => d.id === n.id)).filter(Boolean) : [] : void 0;
|
58
58
|
}
|
59
|
-
const
|
60
|
-
const n = t.map((r) => r.id),
|
61
|
-
return n.length === i.length && n.every((r) =>
|
59
|
+
const je = (t, i) => {
|
60
|
+
const n = t.map((r) => r.id), d = i.map((r) => r.id);
|
61
|
+
return n.length === i.length && n.every((r) => d.includes(r));
|
62
62
|
};
|
63
|
-
function
|
63
|
+
function pn(t, i) {
|
64
64
|
if (!i)
|
65
65
|
return;
|
66
|
-
const n =
|
66
|
+
const n = ze(i), d = new Date(n.exp * 1e3);
|
67
67
|
localStorage.setItem(`auth_token::${t}`, JSON.stringify({
|
68
68
|
token: i,
|
69
|
-
expiry:
|
69
|
+
expiry: d
|
70
70
|
}));
|
71
71
|
}
|
72
|
-
function
|
72
|
+
function Cn(t) {
|
73
73
|
const i = localStorage.getItem(`auth_token::${t}`);
|
74
74
|
if (i) {
|
75
75
|
const n = JSON.parse(i);
|
@@ -77,168 +77,174 @@ function wn(t) {
|
|
77
77
|
return n.token;
|
78
78
|
}
|
79
79
|
}
|
80
|
-
function
|
80
|
+
function vn() {
|
81
81
|
for (let t = 0; t < localStorage.length; t++) {
|
82
82
|
const i = localStorage.key(t);
|
83
83
|
i?.startsWith("auth_token::") && localStorage.removeItem(i);
|
84
84
|
}
|
85
85
|
}
|
86
|
-
function
|
86
|
+
function ze(t) {
|
87
87
|
if (!t)
|
88
88
|
throw new Error("No JWT token");
|
89
|
-
const n = t.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"),
|
89
|
+
const n = t.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"), d = decodeURIComponent(window.atob(n).split("").map(function(r) {
|
90
90
|
return "%" + ("00" + r.charCodeAt(0).toString(16)).slice(-2);
|
91
91
|
}).join(""));
|
92
|
-
return JSON.parse(
|
92
|
+
return JSON.parse(d);
|
93
93
|
}
|
94
|
-
function
|
94
|
+
function wn(t, i = 10) {
|
95
95
|
if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(t))
|
96
96
|
throw new Error("Invalid color format");
|
97
97
|
let n = t.substring(1).split("");
|
98
98
|
n.length === 3 && (n = [n[0], n[0], n[1], n[1], n[2], n[2]]);
|
99
|
-
let
|
100
|
-
return
|
99
|
+
let d = parseInt(n[0] + n[1], 16), r = parseInt(n[2] + n[3], 16), f = parseInt(n[4] + n[5], 16);
|
100
|
+
return d = Math.floor(d * (1 - i / 100)), r = Math.floor(r * (1 - i / 100)), f = Math.floor(f * (1 - i / 100)), "#" + (d < 16 ? "0" : "") + d.toString(16) + (r < 16 ? "0" : "") + r.toString(16) + (f < 16 ? "0" : "") + f.toString(16);
|
101
101
|
}
|
102
|
-
function
|
102
|
+
function yn(t, i = 10) {
|
103
103
|
if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(t))
|
104
104
|
throw new Error("Invalid color format");
|
105
105
|
let n = t.substring(1).split("");
|
106
106
|
n.length === 3 && (n = [n[0], n[0], n[1], n[1], n[2], n[2]]);
|
107
|
-
const
|
108
|
-
return `rgba(${
|
107
|
+
const d = parseInt(n[0] + n[1], 16), r = parseInt(n[2] + n[3], 16), f = parseInt(n[4] + n[5], 16), C = i / 100;
|
108
|
+
return `rgba(${d}, ${r}, ${f}, ${C})`;
|
109
109
|
}
|
110
|
-
function
|
110
|
+
function bn({
|
111
111
|
firebaseApp: t,
|
112
112
|
usersPath: i = "__FIRECMS/config/users",
|
113
113
|
rolesPath: n = "__FIRECMS/config/roles",
|
114
|
-
usersLimit:
|
114
|
+
usersLimit: d,
|
115
115
|
canEditRoles: r = !0,
|
116
|
-
allowDefaultRolesCreation:
|
117
|
-
includeCollectionConfigPermissions:
|
116
|
+
allowDefaultRolesCreation: f,
|
117
|
+
includeCollectionConfigPermissions: C
|
118
118
|
}) {
|
119
|
-
const
|
120
|
-
...
|
121
|
-
roles:
|
122
|
-
})), [
|
123
|
-
|
124
|
-
t && (f.current = ee(t));
|
125
|
-
}, [t]), Z(() => {
|
119
|
+
const [v, D] = F.useState(!0), [w, c] = F.useState(!0), [E, y] = F.useState([]), [s, g] = F.useState([]), b = s.map((h) => ({
|
120
|
+
...h,
|
121
|
+
roles: E.filter((p) => h.roles?.includes(p.id))
|
122
|
+
})), [N, L] = F.useState(), [J, u] = F.useState(), m = v || w;
|
123
|
+
se(() => {
|
126
124
|
if (!t || !n)
|
127
125
|
return;
|
128
|
-
const
|
126
|
+
const h = q(t);
|
129
127
|
return ae(
|
130
|
-
|
128
|
+
ee(h, n),
|
131
129
|
{
|
132
|
-
next: (
|
130
|
+
next: (p) => {
|
133
131
|
L(void 0);
|
134
132
|
try {
|
135
|
-
const
|
136
|
-
|
137
|
-
} catch (
|
138
|
-
L(
|
133
|
+
const x = Ge(p.docs);
|
134
|
+
y(x);
|
135
|
+
} catch (x) {
|
136
|
+
L(x);
|
139
137
|
}
|
140
|
-
|
138
|
+
D(!1);
|
141
139
|
},
|
142
|
-
error: (
|
143
|
-
L(
|
140
|
+
error: (p) => {
|
141
|
+
L(p), D(!1);
|
144
142
|
}
|
145
143
|
}
|
146
144
|
);
|
147
|
-
}, [t, n]),
|
145
|
+
}, [t, n]), se(() => {
|
148
146
|
if (!t || !i)
|
149
147
|
return;
|
150
|
-
const
|
148
|
+
const h = q(t);
|
151
149
|
return ae(
|
152
|
-
|
150
|
+
ee(h, i),
|
153
151
|
{
|
154
|
-
next: (
|
152
|
+
next: (p) => {
|
155
153
|
u(void 0);
|
156
154
|
try {
|
157
|
-
const
|
158
|
-
|
159
|
-
} catch (
|
160
|
-
u(
|
155
|
+
const x = Je(p.docs);
|
156
|
+
g(x);
|
157
|
+
} catch (x) {
|
158
|
+
u(x);
|
161
159
|
}
|
162
|
-
|
160
|
+
c(!1);
|
163
161
|
},
|
164
|
-
error: (
|
165
|
-
u(
|
162
|
+
error: (p) => {
|
163
|
+
u(p), c(!1);
|
166
164
|
}
|
167
165
|
}
|
168
166
|
);
|
169
167
|
}, [t, i]);
|
170
|
-
const
|
171
|
-
|
172
|
-
|
168
|
+
const R = I(async (h) => {
|
169
|
+
if (!t)
|
170
|
+
throw Error("useFirestoreConfigurationPersistence Firebase not initialised");
|
171
|
+
const p = q(t);
|
172
|
+
if (!p || !i)
|
173
173
|
throw Error("useFirestoreConfigurationPersistence Firestore not initialised");
|
174
|
-
console.debug("Persisting user",
|
175
|
-
const
|
174
|
+
console.debug("Persisting user", h);
|
175
|
+
const x = h.roles?.map((Ee) => Ee.id), {
|
176
176
|
uid: M,
|
177
|
-
...
|
178
|
-
} =
|
179
|
-
...
|
180
|
-
roles:
|
177
|
+
...Z
|
178
|
+
} = h, le = {
|
179
|
+
...Z,
|
180
|
+
roles: x
|
181
181
|
};
|
182
|
-
return M ? ce(
|
183
|
-
}, [i]),
|
184
|
-
|
185
|
-
|
182
|
+
return M ? ce(H(p, i, M), le, { merge: !0 }).then(() => h) : ke(ee(p, i), le).then(() => h);
|
183
|
+
}, [i]), U = I((h) => {
|
184
|
+
if (!t)
|
185
|
+
throw Error("useFirestoreConfigurationPersistence Firebase not initialised");
|
186
|
+
const p = q(t);
|
187
|
+
if (!p || !n)
|
186
188
|
throw Error("useFirestoreConfigurationPersistence Firestore not initialised");
|
187
|
-
console.debug("Persisting role",
|
189
|
+
console.debug("Persisting role", h);
|
188
190
|
const {
|
189
|
-
id:
|
191
|
+
id: x,
|
190
192
|
...M
|
191
|
-
} =
|
192
|
-
return ce(
|
193
|
-
}, [n]),
|
194
|
-
|
195
|
-
|
193
|
+
} = h, Z = H(p, n, x);
|
194
|
+
return ce(Z, M, { merge: !0 });
|
195
|
+
}, [n]), A = I(async (h) => {
|
196
|
+
if (!t)
|
197
|
+
throw Error("useFirestoreConfigurationPersistence Firebase not initialised");
|
198
|
+
const p = q(t);
|
199
|
+
if (!p || !i)
|
196
200
|
throw Error("useFirestoreConfigurationPersistence Firestore not initialised");
|
197
|
-
console.debug("Deleting",
|
198
|
-
const { uid:
|
199
|
-
return de(
|
200
|
-
}, [i]),
|
201
|
-
|
202
|
-
|
201
|
+
console.debug("Deleting", h);
|
202
|
+
const { uid: x } = h;
|
203
|
+
return de(H(p, i, x));
|
204
|
+
}, [i]), o = I((h) => {
|
205
|
+
if (!t)
|
206
|
+
throw Error("useFirestoreConfigurationPersistence Firebase not initialised");
|
207
|
+
const p = q(t);
|
208
|
+
if (!p || !n)
|
203
209
|
throw Error("useFirestoreConfigurationPersistence Firestore not initialised");
|
204
|
-
console.debug("Deleting",
|
205
|
-
const { id:
|
210
|
+
console.debug("Deleting", h);
|
211
|
+
const { id: x } = h, M = H(p, n, x);
|
206
212
|
return de(M);
|
207
|
-
}, [n]),
|
208
|
-
collection:
|
209
|
-
user:
|
210
|
-
}) =>
|
211
|
-
collection:
|
212
|
-
user:
|
213
|
-
}), []),
|
214
|
-
if (!
|
213
|
+
}, [n]), S = I(({
|
214
|
+
collection: h,
|
215
|
+
user: p
|
216
|
+
}) => Ye({
|
217
|
+
collection: h,
|
218
|
+
user: p
|
219
|
+
}), []), V = b.map((h) => h.uid), G = I((h) => {
|
220
|
+
if (!b)
|
215
221
|
throw Error("Users not loaded");
|
216
|
-
return
|
217
|
-
}, [
|
218
|
-
if (console.log("Authenticating user",
|
222
|
+
return b.find((x) => x.email?.toLowerCase() === h?.email?.toLowerCase())?.roles;
|
223
|
+
}, [V]), Se = I(({ user: h }) => {
|
224
|
+
if (console.log("Authenticating user", h), m)
|
219
225
|
return console.log("User management is still loading"), !1;
|
220
|
-
if (
|
226
|
+
if (b.length === 0 || b.find((x) => x.email?.toLowerCase() === h?.email?.toLowerCase()))
|
221
227
|
return !0;
|
222
228
|
throw Error("Could not find a user with the provided email");
|
223
|
-
}, [
|
229
|
+
}, [m, V]);
|
224
230
|
return {
|
225
|
-
loading:
|
226
|
-
roles:
|
227
|
-
users:
|
228
|
-
saveUser:
|
229
|
-
saveRole:
|
230
|
-
deleteUser:
|
231
|
-
deleteRole:
|
232
|
-
usersLimit:
|
231
|
+
loading: m,
|
232
|
+
roles: E,
|
233
|
+
users: b,
|
234
|
+
saveUser: R,
|
235
|
+
saveRole: U,
|
236
|
+
deleteUser: A,
|
237
|
+
deleteRole: o,
|
238
|
+
usersLimit: d,
|
233
239
|
canEditRoles: r === void 0 ? !0 : r,
|
234
|
-
allowDefaultRolesCreation:
|
235
|
-
includeCollectionConfigPermissions: !!
|
236
|
-
collectionPermissions:
|
237
|
-
defineRolesFor:
|
238
|
-
authenticator:
|
240
|
+
allowDefaultRolesCreation: f === void 0 ? !0 : f,
|
241
|
+
includeCollectionConfigPermissions: !!C,
|
242
|
+
collectionPermissions: S,
|
243
|
+
defineRolesFor: G,
|
244
|
+
authenticator: Se
|
239
245
|
};
|
240
246
|
}
|
241
|
-
const
|
247
|
+
const Je = (t) => t.map((i) => {
|
242
248
|
const n = i.data();
|
243
249
|
return {
|
244
250
|
uid: i.id,
|
@@ -246,21 +252,21 @@ const He = (t) => t.map((i) => {
|
|
246
252
|
created_on: n?.created_on?.toDate(),
|
247
253
|
updated_on: n?.updated_on?.toDate()
|
248
254
|
};
|
249
|
-
}),
|
255
|
+
}), Ge = (t) => t.map((i) => ({
|
250
256
|
id: i.id,
|
251
257
|
...i.data()
|
252
|
-
})), Ue =
|
253
|
-
function
|
258
|
+
})), Ue = F.createContext({});
|
259
|
+
function He({
|
254
260
|
children: t,
|
255
261
|
userManagement: i
|
256
262
|
}) {
|
257
263
|
return /* @__PURE__ */ e(Ue.Provider, { value: i, children: t });
|
258
264
|
}
|
259
|
-
const
|
260
|
-
function
|
265
|
+
const j = () => Ie(Ue);
|
266
|
+
function X({ role: t }) {
|
261
267
|
let i;
|
262
268
|
return t.isAdmin ? i = "blueDarker" : t.id === "editor" ? i = "yellowLight" : t.id === "viewer" ? i = "grayLight" : i = Fe(t.id), /* @__PURE__ */ e(
|
263
|
-
|
269
|
+
Pe,
|
264
270
|
{
|
265
271
|
colorScheme: i,
|
266
272
|
children: t.name
|
@@ -268,55 +274,55 @@ function Q({ role: t }) {
|
|
268
274
|
t.id
|
269
275
|
);
|
270
276
|
}
|
271
|
-
const
|
272
|
-
id:
|
273
|
-
name:
|
277
|
+
const Ke = O.object().shape({
|
278
|
+
id: O.string().required("Required"),
|
279
|
+
name: O.string().required("Required")
|
274
280
|
});
|
275
|
-
function
|
281
|
+
function Qe({
|
276
282
|
open: t,
|
277
283
|
role: i,
|
278
284
|
editable: n,
|
279
|
-
handleClose:
|
285
|
+
handleClose: d,
|
280
286
|
collections: r
|
281
287
|
}) {
|
282
|
-
const { saveRole:
|
288
|
+
const { saveRole: f } = j(), C = !i, [v, D] = P(), w = I((o) => (D(void 0), f(o)), [f]), c = Re({
|
283
289
|
initialValues: i ?? {
|
284
290
|
name: ""
|
285
291
|
},
|
286
|
-
onSubmit: (o, S) =>
|
292
|
+
onSubmit: (o, S) => w(o).then(() => {
|
287
293
|
S.resetForm({
|
288
294
|
values: o
|
289
|
-
}),
|
290
|
-
}).catch((
|
291
|
-
validation: (o) =>
|
292
|
-
const
|
293
|
-
return S.inner.forEach((
|
294
|
-
|
295
|
-
}),
|
295
|
+
}), d();
|
296
|
+
}).catch((V) => D(V)),
|
297
|
+
validation: (o) => Ke.validate(o, { abortEarly: !1 }).then(() => ({})).catch((S) => {
|
298
|
+
const V = {};
|
299
|
+
return S.inner.forEach((G) => {
|
300
|
+
V[G.path] = G.message;
|
301
|
+
}), V;
|
296
302
|
})
|
297
303
|
}), {
|
298
|
-
isSubmitting:
|
299
|
-
touched:
|
304
|
+
isSubmitting: E,
|
305
|
+
touched: y,
|
300
306
|
values: s,
|
301
|
-
errors:
|
302
|
-
handleChange:
|
303
|
-
setFieldValue:
|
304
|
-
dirty:
|
305
|
-
setFieldTouched:
|
306
|
-
} =
|
307
|
-
return
|
308
|
-
!
|
309
|
-
}, [
|
307
|
+
errors: g,
|
308
|
+
handleChange: b,
|
309
|
+
setFieldValue: N,
|
310
|
+
dirty: L,
|
311
|
+
setFieldTouched: J
|
312
|
+
} = c, u = s.isAdmin ?? !1, m = s.defaultPermissions?.create ?? !1, R = s.defaultPermissions?.read ?? !1, U = s.defaultPermissions?.edit ?? !1, A = s.defaultPermissions?.delete ?? !1;
|
313
|
+
return F.useEffect(() => {
|
314
|
+
!z(y, "id") && s.name && N("id", Le(s.name));
|
315
|
+
}, [y, s.name]), /* @__PURE__ */ e(
|
310
316
|
ue,
|
311
317
|
{
|
312
318
|
open: t,
|
313
319
|
maxWidth: "4xl",
|
314
|
-
children: /* @__PURE__ */ e(De, { value:
|
320
|
+
children: /* @__PURE__ */ e(De, { value: c, children: /* @__PURE__ */ l(
|
315
321
|
"form",
|
316
322
|
{
|
317
323
|
noValidate: !0,
|
318
324
|
autoComplete: "off",
|
319
|
-
onSubmit:
|
325
|
+
onSubmit: c.handleSubmit,
|
320
326
|
style: {
|
321
327
|
display: "flex",
|
322
328
|
flexDirection: "column",
|
@@ -330,7 +336,7 @@ function Ze({
|
|
330
336
|
{
|
331
337
|
className: "flex flex-row pt-12 pb-8",
|
332
338
|
children: /* @__PURE__ */ e(
|
333
|
-
|
339
|
+
$,
|
334
340
|
{
|
335
341
|
variant: "h4",
|
336
342
|
className: "flex-grow",
|
@@ -342,45 +348,45 @@ function Ze({
|
|
342
348
|
/* @__PURE__ */ l("div", { className: "grid grid-cols-12 gap-8", children: [
|
343
349
|
/* @__PURE__ */ l("div", { className: "col-span-12 md:col-span-8", children: [
|
344
350
|
/* @__PURE__ */ e(
|
345
|
-
|
351
|
+
Q,
|
346
352
|
{
|
347
353
|
name: "name",
|
348
354
|
required: !0,
|
349
|
-
error:
|
355
|
+
error: y.name && !!g.name,
|
350
356
|
value: s.name,
|
351
|
-
disabled:
|
352
|
-
onChange:
|
357
|
+
disabled: u || !n,
|
358
|
+
onChange: b,
|
353
359
|
"aria-describedby": "name-helper-text",
|
354
360
|
label: "Name"
|
355
361
|
}
|
356
362
|
),
|
357
|
-
/* @__PURE__ */ e(B, { children:
|
363
|
+
/* @__PURE__ */ e(B, { children: y.name && g.name ? g.name : "Name of this role" })
|
358
364
|
] }),
|
359
365
|
/* @__PURE__ */ l("div", { className: "col-span-12 md:col-span-4", children: [
|
360
366
|
/* @__PURE__ */ e(
|
361
|
-
|
367
|
+
Q,
|
362
368
|
{
|
363
369
|
name: "id",
|
364
370
|
required: !0,
|
365
|
-
error:
|
371
|
+
error: y.id && !!g.id,
|
366
372
|
value: s.id,
|
367
|
-
disabled: !
|
373
|
+
disabled: !C || !n,
|
368
374
|
onChange: (o) => {
|
369
|
-
|
375
|
+
b(o), J("id", !0);
|
370
376
|
},
|
371
377
|
"aria-describedby": "id-helper-text",
|
372
378
|
label: "ID"
|
373
379
|
}
|
374
380
|
),
|
375
|
-
/* @__PURE__ */ e(B, { children:
|
381
|
+
/* @__PURE__ */ e(B, { children: y.id && g.id ? g.id : "ID of this role" })
|
376
382
|
] }),
|
377
383
|
/* @__PURE__ */ l("div", { className: "col-span-12", children: [
|
378
384
|
/* @__PURE__ */ e(
|
379
|
-
|
385
|
+
Ae,
|
380
386
|
{
|
381
387
|
className: "bg-inherit",
|
382
|
-
children: /* @__PURE__ */ l(
|
383
|
-
/* @__PURE__ */ l(
|
388
|
+
children: /* @__PURE__ */ l(ie, { children: [
|
389
|
+
/* @__PURE__ */ l(re, { children: [
|
384
390
|
/* @__PURE__ */ e(a, {}),
|
385
391
|
/* @__PURE__ */ e(
|
386
392
|
a,
|
@@ -411,8 +417,8 @@ function Ze({
|
|
411
417
|
}
|
412
418
|
)
|
413
419
|
] }),
|
414
|
-
/* @__PURE__ */ l(
|
415
|
-
/* @__PURE__ */ l(
|
420
|
+
/* @__PURE__ */ l(oe, { children: [
|
421
|
+
/* @__PURE__ */ l(Y, { children: [
|
416
422
|
/* @__PURE__ */ e(
|
417
423
|
a,
|
418
424
|
{
|
@@ -425,15 +431,15 @@ function Ze({
|
|
425
431
|
{
|
426
432
|
align: "center",
|
427
433
|
children: /* @__PURE__ */ e(
|
428
|
-
|
434
|
+
_,
|
429
435
|
{
|
430
436
|
title: "Create entities in collections",
|
431
437
|
children: /* @__PURE__ */ e(
|
432
|
-
|
438
|
+
k,
|
433
439
|
{
|
434
|
-
disabled:
|
435
|
-
checked: (
|
436
|
-
onCheckedChange: (o) =>
|
440
|
+
disabled: u || !n,
|
441
|
+
checked: (u || m) ?? !1,
|
442
|
+
onCheckedChange: (o) => N("defaultPermissions.create", o)
|
437
443
|
}
|
438
444
|
)
|
439
445
|
}
|
@@ -445,15 +451,15 @@ function Ze({
|
|
445
451
|
{
|
446
452
|
align: "center",
|
447
453
|
children: /* @__PURE__ */ e(
|
448
|
-
|
454
|
+
_,
|
449
455
|
{
|
450
456
|
title: "Access all data in every collection",
|
451
457
|
children: /* @__PURE__ */ e(
|
452
|
-
|
458
|
+
k,
|
453
459
|
{
|
454
|
-
disabled:
|
455
|
-
checked: (
|
456
|
-
onCheckedChange: (o) =>
|
460
|
+
disabled: u || !n,
|
461
|
+
checked: (u || R) ?? !1,
|
462
|
+
onCheckedChange: (o) => N("defaultPermissions.read", o)
|
457
463
|
}
|
458
464
|
)
|
459
465
|
}
|
@@ -465,15 +471,15 @@ function Ze({
|
|
465
471
|
{
|
466
472
|
align: "center",
|
467
473
|
children: /* @__PURE__ */ e(
|
468
|
-
|
474
|
+
_,
|
469
475
|
{
|
470
476
|
title: "Update data in any collection",
|
471
477
|
children: /* @__PURE__ */ e(
|
472
|
-
|
478
|
+
k,
|
473
479
|
{
|
474
|
-
disabled:
|
475
|
-
checked: (
|
476
|
-
onCheckedChange: (o) =>
|
480
|
+
disabled: u || !n,
|
481
|
+
checked: (u || U) ?? !1,
|
482
|
+
onCheckedChange: (o) => N("defaultPermissions.edit", o)
|
477
483
|
}
|
478
484
|
)
|
479
485
|
}
|
@@ -485,15 +491,15 @@ function Ze({
|
|
485
491
|
{
|
486
492
|
align: "center",
|
487
493
|
children: /* @__PURE__ */ e(
|
488
|
-
|
494
|
+
_,
|
489
495
|
{
|
490
496
|
title: "Delete data in any collection",
|
491
497
|
children: /* @__PURE__ */ e(
|
492
|
-
|
498
|
+
k,
|
493
499
|
{
|
494
|
-
disabled:
|
495
|
-
checked: (
|
496
|
-
onCheckedChange: (o) =>
|
500
|
+
disabled: u || !n,
|
501
|
+
checked: (u || A) ?? !1,
|
502
|
+
onCheckedChange: (o) => N("defaultPermissions.delete", o)
|
497
503
|
}
|
498
504
|
)
|
499
505
|
}
|
@@ -501,7 +507,7 @@ function Ze({
|
|
501
507
|
}
|
502
508
|
)
|
503
509
|
] }),
|
504
|
-
r && r.map((o) => /* @__PURE__ */ l(
|
510
|
+
r && r.map((o) => /* @__PURE__ */ l(Y, { children: [
|
505
511
|
/* @__PURE__ */ e(
|
506
512
|
a,
|
507
513
|
{
|
@@ -514,11 +520,11 @@ function Ze({
|
|
514
520
|
{
|
515
521
|
align: "center",
|
516
522
|
children: /* @__PURE__ */ e(
|
517
|
-
|
523
|
+
k,
|
518
524
|
{
|
519
|
-
disabled:
|
520
|
-
checked: (
|
521
|
-
onCheckedChange: (S) =>
|
525
|
+
disabled: u || m || !n,
|
526
|
+
checked: (u || m || z(s, `collectionPermissions.${o.path}.create`)) ?? !1,
|
527
|
+
onCheckedChange: (S) => N(`collectionPermissions.${o.path}.create`, S)
|
522
528
|
}
|
523
529
|
)
|
524
530
|
}
|
@@ -528,11 +534,11 @@ function Ze({
|
|
528
534
|
{
|
529
535
|
align: "center",
|
530
536
|
children: /* @__PURE__ */ e(
|
531
|
-
|
537
|
+
k,
|
532
538
|
{
|
533
|
-
disabled:
|
534
|
-
checked: (
|
535
|
-
onCheckedChange: (S) =>
|
539
|
+
disabled: u || R || !n,
|
540
|
+
checked: (u || R || z(s, `collectionPermissions.${o.path}.read`)) ?? !1,
|
541
|
+
onCheckedChange: (S) => N(`collectionPermissions.${o.path}.read`, S)
|
536
542
|
}
|
537
543
|
)
|
538
544
|
}
|
@@ -542,11 +548,11 @@ function Ze({
|
|
542
548
|
{
|
543
549
|
align: "center",
|
544
550
|
children: /* @__PURE__ */ e(
|
545
|
-
|
551
|
+
k,
|
546
552
|
{
|
547
|
-
disabled:
|
548
|
-
checked: (
|
549
|
-
onCheckedChange: (S) =>
|
553
|
+
disabled: u || U || !n,
|
554
|
+
checked: (u || U || z(s, `collectionPermissions.${o.path}.edit`)) ?? !1,
|
555
|
+
onCheckedChange: (S) => N(`collectionPermissions.${o.path}.edit`, S)
|
550
556
|
}
|
551
557
|
)
|
552
558
|
}
|
@@ -556,11 +562,11 @@ function Ze({
|
|
556
562
|
{
|
557
563
|
align: "center",
|
558
564
|
children: /* @__PURE__ */ e(
|
559
|
-
|
565
|
+
k,
|
560
566
|
{
|
561
|
-
disabled:
|
562
|
-
checked: (
|
563
|
-
onCheckedChange: (S) =>
|
567
|
+
disabled: u || A || !n,
|
568
|
+
checked: (u || A || z(s, `collectionPermissions.${o.path}.delete`)) ?? !1,
|
569
|
+
onCheckedChange: (S) => N(`collectionPermissions.${o.path}.delete`, S)
|
564
570
|
}
|
565
571
|
)
|
566
572
|
}
|
@@ -574,16 +580,16 @@ function Ze({
|
|
574
580
|
] }),
|
575
581
|
/* @__PURE__ */ l("div", { className: "col-span-12 md:col-span-4", children: [
|
576
582
|
/* @__PURE__ */ l(
|
577
|
-
|
583
|
+
ne,
|
578
584
|
{
|
579
|
-
error:
|
585
|
+
error: y.config && !!g.config,
|
580
586
|
id: "createCollections",
|
581
587
|
name: "createCollections",
|
582
588
|
label: "Create collections",
|
583
589
|
position: "item-aligned",
|
584
|
-
disabled:
|
585
|
-
onChange: (o) =>
|
586
|
-
value:
|
590
|
+
disabled: u || !n,
|
591
|
+
onChange: (o) => N("config.createCollections", o.target.value === "true"),
|
592
|
+
value: u || s.config?.createCollections ? "true" : "false",
|
587
593
|
renderValue: (o) => o === "true" ? "Yes" : "No",
|
588
594
|
children: [
|
589
595
|
/* @__PURE__ */ e(
|
@@ -603,20 +609,20 @@ function Ze({
|
|
603
609
|
]
|
604
610
|
}
|
605
611
|
),
|
606
|
-
/* @__PURE__ */ e(B, { children:
|
612
|
+
/* @__PURE__ */ e(B, { children: y.config && g.config ? g.config : "Can the user create collections" })
|
607
613
|
] }),
|
608
614
|
/* @__PURE__ */ l("div", { className: "col-span-12 md:col-span-4", children: [
|
609
615
|
/* @__PURE__ */ l(
|
610
|
-
|
616
|
+
ne,
|
611
617
|
{
|
612
|
-
error:
|
618
|
+
error: y.config && !!g.config,
|
613
619
|
id: "editCollections",
|
614
620
|
name: "editCollections",
|
615
621
|
label: "Edit collections",
|
616
|
-
disabled:
|
622
|
+
disabled: u || !n,
|
617
623
|
position: "item-aligned",
|
618
|
-
onChange: (o) =>
|
619
|
-
value:
|
624
|
+
onChange: (o) => N("config.editCollections", o.target.value === "own" ? "own" : o.target.value === "true"),
|
625
|
+
value: u ? "true" : s.config?.editCollections === "own" ? "own" : s.config?.editCollections ? "true" : "false",
|
620
626
|
renderValue: (o) => o === "own" ? "Own" : o === "true" ? "Yes" : "No",
|
621
627
|
children: [
|
622
628
|
/* @__PURE__ */ e(
|
@@ -643,20 +649,20 @@ function Ze({
|
|
643
649
|
]
|
644
650
|
}
|
645
651
|
),
|
646
|
-
/* @__PURE__ */ e(B, { children:
|
652
|
+
/* @__PURE__ */ e(B, { children: y.config && g.config ? g.config : "Can the user edit collections" })
|
647
653
|
] }),
|
648
654
|
/* @__PURE__ */ l("div", { className: "col-span-12 md:col-span-4", children: [
|
649
655
|
/* @__PURE__ */ l(
|
650
|
-
|
656
|
+
ne,
|
651
657
|
{
|
652
|
-
error:
|
658
|
+
error: y.config && !!g.config,
|
653
659
|
id: "deleteCollections",
|
654
660
|
name: "deleteCollections",
|
655
661
|
label: "Delete collections",
|
656
|
-
disabled:
|
662
|
+
disabled: u || !n,
|
657
663
|
position: "item-aligned",
|
658
|
-
onChange: (o) =>
|
659
|
-
value:
|
664
|
+
onChange: (o) => N("config.deleteCollections", o.target.value === "own" ? "own" : o.target.value === "true"),
|
665
|
+
value: u ? "true" : s.config?.deleteCollections === "own" ? "own" : s.config?.deleteCollections ? "true" : "false",
|
660
666
|
renderValue: (o) => o === "own" ? "Own" : o === "true" ? "Yes" : "No",
|
661
667
|
children: [
|
662
668
|
/* @__PURE__ */ e(
|
@@ -683,18 +689,18 @@ function Ze({
|
|
683
689
|
]
|
684
690
|
}
|
685
691
|
),
|
686
|
-
/* @__PURE__ */ e(B, { children:
|
692
|
+
/* @__PURE__ */ e(B, { children: y.config && g.config ? g.config : "Can the user delete collections" })
|
687
693
|
] })
|
688
694
|
] })
|
689
695
|
] }),
|
690
696
|
/* @__PURE__ */ l(he, { position: "sticky", children: [
|
691
|
-
|
697
|
+
v && /* @__PURE__ */ e($, { className: "text-red-500", children: "There was an error saving this role" }),
|
692
698
|
/* @__PURE__ */ e(
|
693
|
-
|
699
|
+
W,
|
694
700
|
{
|
695
701
|
variant: "text",
|
696
702
|
onClick: () => {
|
697
|
-
|
703
|
+
d();
|
698
704
|
},
|
699
705
|
children: "Cancel"
|
700
706
|
}
|
@@ -705,10 +711,10 @@ function Ze({
|
|
705
711
|
variant: "filled",
|
706
712
|
color: "primary",
|
707
713
|
type: "submit",
|
708
|
-
disabled: !
|
709
|
-
loading:
|
714
|
+
disabled: !L,
|
715
|
+
loading: E,
|
710
716
|
startIcon: /* @__PURE__ */ e(ge, {}),
|
711
|
-
children:
|
717
|
+
children: C ? "Create role" : "Update"
|
712
718
|
}
|
713
719
|
)
|
714
720
|
] })
|
@@ -718,7 +724,7 @@ function Ze({
|
|
718
724
|
}
|
719
725
|
);
|
720
726
|
}
|
721
|
-
const
|
727
|
+
const Xe = [
|
722
728
|
{
|
723
729
|
id: "admin",
|
724
730
|
name: "Admin",
|
@@ -752,69 +758,69 @@ const en = [
|
|
752
758
|
}
|
753
759
|
}
|
754
760
|
];
|
755
|
-
function
|
761
|
+
function Ze({
|
756
762
|
onRoleClicked: t,
|
757
763
|
editable: i
|
758
764
|
}) {
|
759
765
|
const {
|
760
766
|
roles: n,
|
761
|
-
saveRole:
|
767
|
+
saveRole: d,
|
762
768
|
deleteRole: r,
|
763
|
-
allowDefaultRolesCreation:
|
764
|
-
} =
|
769
|
+
allowDefaultRolesCreation: f
|
770
|
+
} = j(), [C, v] = P(void 0), [D, w] = P(!1);
|
765
771
|
return /* @__PURE__ */ l(
|
766
772
|
"div",
|
767
773
|
{
|
768
774
|
className: "w-full overflow-auto",
|
769
775
|
children: [
|
770
|
-
/* @__PURE__ */ l(
|
771
|
-
/* @__PURE__ */ l(
|
776
|
+
/* @__PURE__ */ l(ie, { children: [
|
777
|
+
/* @__PURE__ */ l(re, { children: [
|
772
778
|
/* @__PURE__ */ e(a, { header: !0, className: "w-16" }),
|
773
779
|
/* @__PURE__ */ e(a, { header: !0, children: "Role" }),
|
774
780
|
/* @__PURE__ */ e(a, { header: !0, className: "items-center", children: "Is Admin" }),
|
775
781
|
/* @__PURE__ */ e(a, { header: !0, children: "Default permissions" })
|
776
782
|
] }),
|
777
|
-
/* @__PURE__ */ l(
|
778
|
-
n && n.map((
|
779
|
-
const
|
783
|
+
/* @__PURE__ */ l(oe, { children: [
|
784
|
+
n && n.map((c) => {
|
785
|
+
const E = c.isAdmin || c.defaultPermissions?.create, y = c.isAdmin || c.defaultPermissions?.read, s = c.isAdmin || c.defaultPermissions?.edit, g = c.isAdmin || c.defaultPermissions?.delete;
|
780
786
|
return /* @__PURE__ */ l(
|
781
|
-
|
787
|
+
Y,
|
782
788
|
{
|
783
789
|
onClick: () => {
|
784
|
-
t(
|
790
|
+
t(c);
|
785
791
|
},
|
786
792
|
children: [
|
787
|
-
/* @__PURE__ */ e(a, { style: { width: "64px" }, children: !
|
793
|
+
/* @__PURE__ */ e(a, { style: { width: "64px" }, children: !c.isAdmin && /* @__PURE__ */ e(_, { title: "Delete this role", children: /* @__PURE__ */ e(
|
788
794
|
pe,
|
789
795
|
{
|
790
796
|
size: "small",
|
791
797
|
disabled: !i,
|
792
|
-
onClick: (
|
798
|
+
onClick: (b) => (b.stopPropagation(), v(c)),
|
793
799
|
children: /* @__PURE__ */ e(Ce, {})
|
794
800
|
}
|
795
801
|
) }) }),
|
796
|
-
/* @__PURE__ */ e(a, { children: /* @__PURE__ */ e(
|
797
|
-
/* @__PURE__ */ e(a, { className: "items-center", children: /* @__PURE__ */ e(
|
802
|
+
/* @__PURE__ */ e(a, { children: /* @__PURE__ */ e(X, { role: c }) }),
|
803
|
+
/* @__PURE__ */ e(a, { className: "items-center", children: /* @__PURE__ */ e(k, { checked: c.isAdmin ?? !1 }) }),
|
798
804
|
/* @__PURE__ */ e(a, { children: /* @__PURE__ */ l("ul", { children: [
|
799
|
-
|
800
|
-
|
805
|
+
E && /* @__PURE__ */ e("li", { children: "Create" }),
|
806
|
+
y && /* @__PURE__ */ e("li", { children: "Read" }),
|
801
807
|
s && /* @__PURE__ */ e("li", { children: "Update" }),
|
802
|
-
|
808
|
+
g && /* @__PURE__ */ e("li", { children: "Delete" })
|
803
809
|
] }) })
|
804
810
|
]
|
805
811
|
},
|
806
|
-
|
812
|
+
c.name
|
807
813
|
);
|
808
814
|
}),
|
809
|
-
(!n || n.length === 0) && /* @__PURE__ */ e(
|
810
|
-
/* @__PURE__ */ e(
|
811
|
-
|
812
|
-
|
815
|
+
(!n || n.length === 0) && /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(a, { colspan: 4, children: /* @__PURE__ */ l(ve, { className: "flex flex-col gap-4 my-8 items-center", children: [
|
816
|
+
/* @__PURE__ */ e($, { variant: "label", children: "You don't have any roles yet." }),
|
817
|
+
f && /* @__PURE__ */ e(
|
818
|
+
W,
|
813
819
|
{
|
814
820
|
variant: "outlined",
|
815
821
|
onClick: () => {
|
816
|
-
|
817
|
-
c
|
822
|
+
Xe.forEach((c) => {
|
823
|
+
d(c);
|
818
824
|
});
|
819
825
|
},
|
820
826
|
children: "Create default roles"
|
@@ -826,36 +832,36 @@ function nn({
|
|
826
832
|
/* @__PURE__ */ e(
|
827
833
|
be,
|
828
834
|
{
|
829
|
-
open: !!
|
830
|
-
loading:
|
835
|
+
open: !!C,
|
836
|
+
loading: D,
|
831
837
|
onAccept: () => {
|
832
|
-
|
833
|
-
|
838
|
+
C && (w(!0), r(C).then(() => {
|
839
|
+
v(void 0);
|
834
840
|
}).finally(() => {
|
835
|
-
|
841
|
+
w(!1);
|
836
842
|
}));
|
837
843
|
},
|
838
844
|
onCancel: () => {
|
839
|
-
|
845
|
+
v(void 0);
|
840
846
|
},
|
841
|
-
title: /* @__PURE__ */ e(
|
842
|
-
body: /* @__PURE__ */ e(
|
847
|
+
title: /* @__PURE__ */ e(K, { children: "Delete?" }),
|
848
|
+
body: /* @__PURE__ */ e(K, { children: "Are you sure you want to delete this role?" })
|
843
849
|
}
|
844
850
|
)
|
845
851
|
]
|
846
852
|
}
|
847
853
|
);
|
848
854
|
}
|
849
|
-
const
|
855
|
+
const en = F.memo(
|
850
856
|
function({ children: i }) {
|
851
|
-
const { collections: n } =
|
852
|
-
r(!0),
|
857
|
+
const { collections: n } = Ve(), [d, r] = P(!1), [f, C] = P(), { canEditRoles: v } = j(), D = I((c) => {
|
858
|
+
r(!0), C(c);
|
853
859
|
}, []);
|
854
860
|
return /* @__PURE__ */ l(we, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
|
855
861
|
i,
|
856
862
|
/* @__PURE__ */ l("div", { className: "flex items-center mt-12", children: [
|
857
863
|
/* @__PURE__ */ e(
|
858
|
-
|
864
|
+
$,
|
859
865
|
{
|
860
866
|
gutterBottom: !0,
|
861
867
|
variant: "h4",
|
@@ -864,103 +870,103 @@ const tn = A.memo(
|
|
864
870
|
children: "Roles"
|
865
871
|
}
|
866
872
|
),
|
867
|
-
/* @__PURE__ */ e(
|
868
|
-
|
873
|
+
/* @__PURE__ */ e(_, { title: v ? void 0 : "Update plans to customise roles", children: /* @__PURE__ */ e(
|
874
|
+
W,
|
869
875
|
{
|
870
876
|
size: "large",
|
871
|
-
disabled: !
|
877
|
+
disabled: !v,
|
872
878
|
startIcon: /* @__PURE__ */ e(ye, {}),
|
873
879
|
onClick: () => r(!0),
|
874
880
|
children: "Add role"
|
875
881
|
}
|
876
882
|
) })
|
877
883
|
] }),
|
878
|
-
/* @__PURE__ */ e(
|
884
|
+
/* @__PURE__ */ e(Ze, { onRoleClicked: D, editable: !!v }),
|
879
885
|
/* @__PURE__ */ e(
|
880
|
-
|
886
|
+
Qe,
|
881
887
|
{
|
882
|
-
open:
|
883
|
-
role:
|
884
|
-
editable:
|
888
|
+
open: d,
|
889
|
+
role: f,
|
890
|
+
editable: v,
|
885
891
|
collections: n,
|
886
892
|
handleClose: () => {
|
887
|
-
|
893
|
+
C(void 0), r(!1);
|
888
894
|
}
|
889
895
|
},
|
890
|
-
|
896
|
+
f?.id ?? "new"
|
891
897
|
)
|
892
898
|
] });
|
893
899
|
}
|
894
|
-
),
|
895
|
-
displayName:
|
896
|
-
email:
|
897
|
-
roles:
|
900
|
+
), nn = O.object().shape({
|
901
|
+
displayName: O.string().required("Required"),
|
902
|
+
email: O.string().email().required("Required"),
|
903
|
+
roles: O.array().min(1)
|
898
904
|
});
|
899
|
-
function
|
900
|
-
const
|
901
|
-
if ((!r || !
|
905
|
+
function tn(t, i, n, d, r) {
|
906
|
+
const f = n.filter((w) => w.roles?.map((c) => c.id).includes("admin")), C = t.roles?.map((w) => w.id).includes("admin");
|
907
|
+
if ((!r || !je(r.roles ?? [], i.roles ?? [])) && !C)
|
902
908
|
throw new Error("Only admins can change roles");
|
903
|
-
if (r && r.roles?.map((
|
909
|
+
if (r && r.roles?.map((w) => w.id).includes("admin") && !i.roles?.map((w) => w.id).includes("admin") && f.length === 1)
|
904
910
|
throw new Error("There must be at least one admin");
|
905
911
|
return !0;
|
906
912
|
}
|
907
|
-
function
|
913
|
+
function rn({
|
908
914
|
open: t,
|
909
915
|
user: i,
|
910
916
|
handleClose: n
|
911
917
|
}) {
|
912
|
-
const
|
918
|
+
const d = Ne(), {
|
913
919
|
user: r
|
914
|
-
} =
|
915
|
-
saveUser:
|
916
|
-
users:
|
917
|
-
roles:
|
918
|
-
} =
|
920
|
+
} = xe(), {
|
921
|
+
saveUser: f,
|
922
|
+
users: C,
|
923
|
+
roles: v
|
924
|
+
} = j(), D = !i, w = I((m) => {
|
919
925
|
if (!r)
|
920
926
|
throw new Error("Logged user not found");
|
921
927
|
try {
|
922
|
-
return
|
923
|
-
} catch (
|
924
|
-
return Promise.reject(
|
928
|
+
return tn(r, m, C, v, i), f(m);
|
929
|
+
} catch (R) {
|
930
|
+
return Promise.reject(R);
|
925
931
|
}
|
926
|
-
}, [
|
932
|
+
}, [v, f, i, C, r]), c = Re({
|
927
933
|
initialValues: i ?? {
|
928
934
|
displayName: "",
|
929
935
|
email: "",
|
930
|
-
roles:
|
936
|
+
roles: v.filter((m) => m.id === "editor")
|
931
937
|
},
|
932
|
-
validation: (
|
933
|
-
onSubmit: (
|
934
|
-
n(),
|
935
|
-
values:
|
938
|
+
validation: (m) => nn.validate(m, { abortEarly: !1 }).then(() => ({})).catch((R) => R.inner.reduce((U, A) => (U[A.path] = A.message, U), {})),
|
939
|
+
onSubmit: (m, R) => w(m).then(() => {
|
940
|
+
n(), R.resetForm({
|
941
|
+
values: m
|
936
942
|
});
|
937
943
|
}).catch((U) => {
|
938
|
-
|
944
|
+
d.open({
|
939
945
|
type: "error",
|
940
946
|
message: U.message
|
941
947
|
});
|
942
948
|
})
|
943
949
|
}), {
|
944
|
-
isSubmitting:
|
945
|
-
touched:
|
950
|
+
isSubmitting: E,
|
951
|
+
touched: y,
|
946
952
|
handleChange: s,
|
947
|
-
values:
|
948
|
-
errors:
|
949
|
-
setFieldValue:
|
950
|
-
dirty:
|
951
|
-
handleSubmit:
|
952
|
-
submitCount:
|
953
|
-
} =
|
953
|
+
values: g,
|
954
|
+
errors: b,
|
955
|
+
setFieldValue: N,
|
956
|
+
dirty: L,
|
957
|
+
handleSubmit: J,
|
958
|
+
submitCount: u
|
959
|
+
} = c;
|
954
960
|
return /* @__PURE__ */ e(
|
955
961
|
ue,
|
956
962
|
{
|
957
963
|
open: t,
|
958
|
-
onOpenChange: (
|
964
|
+
onOpenChange: (m) => m ? void 0 : n(),
|
959
965
|
maxWidth: "4xl",
|
960
|
-
children: /* @__PURE__ */ e(De, { value:
|
966
|
+
children: /* @__PURE__ */ e(De, { value: c, children: /* @__PURE__ */ l(
|
961
967
|
"form",
|
962
968
|
{
|
963
|
-
onSubmit:
|
969
|
+
onSubmit: J,
|
964
970
|
autoComplete: "off",
|
965
971
|
noValidate: !0,
|
966
972
|
style: {
|
@@ -976,7 +982,7 @@ function ln({
|
|
976
982
|
{
|
977
983
|
className: "flex flex-row pt-4 pb-4",
|
978
984
|
children: /* @__PURE__ */ e(
|
979
|
-
|
985
|
+
$,
|
980
986
|
{
|
981
987
|
variant: "h4",
|
982
988
|
className: "flex-grow",
|
@@ -988,51 +994,51 @@ function ln({
|
|
988
994
|
/* @__PURE__ */ l("div", { className: "grid grid-cols-12 gap-8", children: [
|
989
995
|
/* @__PURE__ */ l("div", { className: "col-span-12", children: [
|
990
996
|
/* @__PURE__ */ e(
|
991
|
-
|
997
|
+
Q,
|
992
998
|
{
|
993
999
|
name: "displayName",
|
994
1000
|
required: !0,
|
995
|
-
error:
|
996
|
-
value:
|
1001
|
+
error: u > 0 && !!b.displayName,
|
1002
|
+
value: g.displayName ?? "",
|
997
1003
|
onChange: s,
|
998
1004
|
"aria-describedby": "name-helper-text",
|
999
1005
|
label: "Name"
|
1000
1006
|
}
|
1001
1007
|
),
|
1002
|
-
/* @__PURE__ */ e(B, { children:
|
1008
|
+
/* @__PURE__ */ e(B, { children: u > 0 && b.displayName ? b.displayName : "Name of this user" })
|
1003
1009
|
] }),
|
1004
1010
|
/* @__PURE__ */ l("div", { className: "col-span-12", children: [
|
1005
1011
|
/* @__PURE__ */ e(
|
1006
|
-
|
1012
|
+
Q,
|
1007
1013
|
{
|
1008
1014
|
required: !0,
|
1009
|
-
error:
|
1015
|
+
error: u > 0 && !!b.email,
|
1010
1016
|
name: "email",
|
1011
|
-
value:
|
1017
|
+
value: g.email ?? "",
|
1012
1018
|
onChange: s,
|
1013
1019
|
"aria-describedby": "email-helper-text",
|
1014
1020
|
label: "Email"
|
1015
1021
|
}
|
1016
1022
|
),
|
1017
|
-
/* @__PURE__ */ e(B, { children:
|
1023
|
+
/* @__PURE__ */ e(B, { children: u > 0 && b.email ? b.email : "Email of this user" })
|
1018
1024
|
] }),
|
1019
1025
|
/* @__PURE__ */ e("div", { className: "col-span-12", children: /* @__PURE__ */ e(
|
1020
|
-
|
1026
|
+
Te,
|
1021
1027
|
{
|
1022
1028
|
label: "Roles",
|
1023
|
-
value:
|
1024
|
-
onMultiValueChange: (
|
1025
|
-
renderValue: (
|
1026
|
-
const
|
1027
|
-
return
|
1029
|
+
value: g.roles?.map((m) => m.id) ?? [],
|
1030
|
+
onMultiValueChange: (m) => N("roles", m.map((R) => v.find((U) => U.id === R))),
|
1031
|
+
renderValue: (m) => {
|
1032
|
+
const R = v.find((U) => U.id === m);
|
1033
|
+
return R ? /* @__PURE__ */ e("div", { className: "flex flex-wrap space-x-2 space-y-2", children: /* @__PURE__ */ e(X, { role: R }, R?.id) }) : null;
|
1028
1034
|
},
|
1029
|
-
children:
|
1030
|
-
|
1035
|
+
children: v.map((m) => /* @__PURE__ */ e(
|
1036
|
+
Be,
|
1031
1037
|
{
|
1032
|
-
value:
|
1033
|
-
children: /* @__PURE__ */ e(
|
1038
|
+
value: m.id,
|
1039
|
+
children: /* @__PURE__ */ e(X, { role: m }, m?.id)
|
1034
1040
|
},
|
1035
|
-
|
1041
|
+
m.id
|
1036
1042
|
))
|
1037
1043
|
}
|
1038
1044
|
) })
|
@@ -1040,7 +1046,7 @@ function ln({
|
|
1040
1046
|
] }),
|
1041
1047
|
/* @__PURE__ */ l(he, { children: [
|
1042
1048
|
/* @__PURE__ */ e(
|
1043
|
-
|
1049
|
+
W,
|
1044
1050
|
{
|
1045
1051
|
variant: "text",
|
1046
1052
|
onClick: () => {
|
@@ -1055,10 +1061,10 @@ function ln({
|
|
1055
1061
|
variant: "filled",
|
1056
1062
|
color: "primary",
|
1057
1063
|
type: "submit",
|
1058
|
-
disabled: !
|
1059
|
-
loading:
|
1064
|
+
disabled: !L,
|
1065
|
+
loading: E,
|
1060
1066
|
startIcon: /* @__PURE__ */ e(ge, {}),
|
1061
|
-
children:
|
1067
|
+
children: D ? "Create user" : "Update"
|
1062
1068
|
}
|
1063
1069
|
)
|
1064
1070
|
] })
|
@@ -1068,15 +1074,15 @@ function ln({
|
|
1068
1074
|
}
|
1069
1075
|
);
|
1070
1076
|
}
|
1071
|
-
function
|
1077
|
+
function on({ onUserClicked: t }) {
|
1072
1078
|
const {
|
1073
1079
|
users: i,
|
1074
1080
|
saveUser: n,
|
1075
|
-
deleteUser:
|
1076
|
-
} =
|
1081
|
+
deleteUser: d
|
1082
|
+
} = j(), r = xe(), f = Ne(), C = _e(), v = C?.locale ? Me[C?.locale] : void 0, D = C?.dateTimeFormat ?? Oe, [w, c] = P(void 0), [E, y] = P(!1);
|
1077
1083
|
return /* @__PURE__ */ l("div", { className: "overflow-auto", children: [
|
1078
|
-
/* @__PURE__ */ l(
|
1079
|
-
/* @__PURE__ */ l(
|
1084
|
+
/* @__PURE__ */ l(ie, { children: [
|
1085
|
+
/* @__PURE__ */ l(re, { children: [
|
1080
1086
|
/* @__PURE__ */ e(a, { className: "truncate w-16" }),
|
1081
1087
|
/* @__PURE__ */ e(a, { children: "ID" }),
|
1082
1088
|
/* @__PURE__ */ e(a, { children: "Email" }),
|
@@ -1084,40 +1090,40 @@ function sn({ onUserClicked: t }) {
|
|
1084
1090
|
/* @__PURE__ */ e(a, { children: "Roles" }),
|
1085
1091
|
/* @__PURE__ */ e(a, { children: "Created on" })
|
1086
1092
|
] }),
|
1087
|
-
/* @__PURE__ */ l(
|
1093
|
+
/* @__PURE__ */ l(oe, { children: [
|
1088
1094
|
i && i.map((s) => {
|
1089
|
-
const
|
1095
|
+
const g = s.roles, b = s.created_on ? $e(s.created_on, D, { locale: v }) : "";
|
1090
1096
|
return /* @__PURE__ */ l(
|
1091
|
-
|
1097
|
+
Y,
|
1092
1098
|
{
|
1093
1099
|
onClick: () => {
|
1094
1100
|
t(s);
|
1095
1101
|
},
|
1096
1102
|
children: [
|
1097
|
-
/* @__PURE__ */ e(a, { className: "w-10", children: /* @__PURE__ */ e(
|
1103
|
+
/* @__PURE__ */ e(a, { className: "w-10", children: /* @__PURE__ */ e(_, { title: "Delete this user", children: /* @__PURE__ */ e(
|
1098
1104
|
pe,
|
1099
1105
|
{
|
1100
1106
|
size: "small",
|
1101
|
-
onClick: (
|
1107
|
+
onClick: (N) => (N.stopPropagation(), c(s)),
|
1102
1108
|
children: /* @__PURE__ */ e(Ce, {})
|
1103
1109
|
}
|
1104
1110
|
) }) }),
|
1105
1111
|
/* @__PURE__ */ e(a, { children: s.uid }),
|
1106
1112
|
/* @__PURE__ */ e(a, { children: s.email }),
|
1107
1113
|
/* @__PURE__ */ e(a, { className: "font-medium align-left", children: s.displayName }),
|
1108
|
-
/* @__PURE__ */ e(a, { className: "align-left", children:
|
1109
|
-
(
|
1114
|
+
/* @__PURE__ */ e(a, { className: "align-left", children: g ? /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-2", children: g.map(
|
1115
|
+
(N) => /* @__PURE__ */ e(X, { role: N }, N?.id)
|
1110
1116
|
) }) : null }),
|
1111
|
-
/* @__PURE__ */ e(a, { children:
|
1117
|
+
/* @__PURE__ */ e(a, { children: b })
|
1112
1118
|
]
|
1113
1119
|
},
|
1114
1120
|
"row_" + s.uid
|
1115
1121
|
);
|
1116
1122
|
}),
|
1117
|
-
(!i || i.length === 0) && /* @__PURE__ */ e(
|
1118
|
-
/* @__PURE__ */ e(
|
1123
|
+
(!i || i.length === 0) && /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(a, { colspan: 6, children: /* @__PURE__ */ l(ve, { className: "flex flex-col gap-4 my-8 items-center", children: [
|
1124
|
+
/* @__PURE__ */ e($, { variant: "label", children: "There are no users yet" }),
|
1119
1125
|
/* @__PURE__ */ e(
|
1120
|
-
|
1126
|
+
W,
|
1121
1127
|
{
|
1122
1128
|
variant: "outlined",
|
1123
1129
|
onClick: () => {
|
@@ -1133,12 +1139,12 @@ function sn({ onUserClicked: t }) {
|
|
1133
1139
|
roles: [{ id: "admin", name: "Admin" }],
|
1134
1140
|
created_on: /* @__PURE__ */ new Date()
|
1135
1141
|
}).then(() => {
|
1136
|
-
|
1142
|
+
f.open({
|
1137
1143
|
type: "success",
|
1138
1144
|
message: "User added successfully"
|
1139
1145
|
});
|
1140
1146
|
}).catch((s) => {
|
1141
|
-
|
1147
|
+
f.open({
|
1142
1148
|
type: "error",
|
1143
1149
|
message: "Error adding user: " + s.message
|
1144
1150
|
});
|
@@ -1153,34 +1159,34 @@ function sn({ onUserClicked: t }) {
|
|
1153
1159
|
/* @__PURE__ */ e(
|
1154
1160
|
be,
|
1155
1161
|
{
|
1156
|
-
open: !!
|
1157
|
-
loading:
|
1162
|
+
open: !!w,
|
1163
|
+
loading: E,
|
1158
1164
|
onAccept: () => {
|
1159
|
-
|
1160
|
-
|
1165
|
+
w && (y(!0), d(w).then(() => {
|
1166
|
+
c(void 0);
|
1161
1167
|
}).catch((s) => {
|
1162
|
-
|
1168
|
+
f.open({
|
1163
1169
|
type: "error",
|
1164
1170
|
message: "Error deleting user: " + s.message
|
1165
1171
|
});
|
1166
1172
|
}).finally(() => {
|
1167
|
-
|
1173
|
+
y(!1);
|
1168
1174
|
}));
|
1169
1175
|
},
|
1170
1176
|
onCancel: () => {
|
1171
|
-
|
1177
|
+
c(void 0);
|
1172
1178
|
},
|
1173
|
-
title: /* @__PURE__ */ e(
|
1174
|
-
body: /* @__PURE__ */ e(
|
1179
|
+
title: /* @__PURE__ */ e(K, { children: "Delete?" }),
|
1180
|
+
body: /* @__PURE__ */ e(K, { children: "Are you sure you want to delete this user?" })
|
1175
1181
|
}
|
1176
1182
|
)
|
1177
1183
|
] });
|
1178
1184
|
}
|
1179
|
-
const
|
1180
|
-
const [n,
|
1181
|
-
|
1182
|
-
}, []),
|
1183
|
-
|
1185
|
+
const ln = function({ children: i }) {
|
1186
|
+
const [n, d] = P(), [r, f] = P(), { users: C, usersLimit: v } = j(), D = v !== void 0 && C && C.length >= v, w = I((E) => {
|
1187
|
+
f(E), d(!0);
|
1188
|
+
}, []), c = I(() => {
|
1189
|
+
d(!1), f(void 0);
|
1184
1190
|
}, []);
|
1185
1191
|
return /* @__PURE__ */ l(we, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
|
1186
1192
|
i,
|
@@ -1190,7 +1196,7 @@ const an = function({ children: i }) {
|
|
1190
1196
|
className: "flex items-center mt-12",
|
1191
1197
|
children: [
|
1192
1198
|
/* @__PURE__ */ e(
|
1193
|
-
|
1199
|
+
$,
|
1194
1200
|
{
|
1195
1201
|
gutterBottom: !0,
|
1196
1202
|
variant: "h4",
|
@@ -1200,82 +1206,82 @@ const an = function({ children: i }) {
|
|
1200
1206
|
}
|
1201
1207
|
),
|
1202
1208
|
/* @__PURE__ */ e(
|
1203
|
-
|
1209
|
+
W,
|
1204
1210
|
{
|
1205
1211
|
size: "large",
|
1206
|
-
disabled:
|
1212
|
+
disabled: D,
|
1207
1213
|
startIcon: /* @__PURE__ */ e(ye, {}),
|
1208
|
-
onClick: () =>
|
1214
|
+
onClick: () => d(!0),
|
1209
1215
|
children: "Add user"
|
1210
1216
|
}
|
1211
1217
|
)
|
1212
1218
|
]
|
1213
1219
|
}
|
1214
1220
|
),
|
1215
|
-
/* @__PURE__ */ e(
|
1221
|
+
/* @__PURE__ */ e(on, { onUserClicked: w }),
|
1216
1222
|
/* @__PURE__ */ e(
|
1217
|
-
|
1223
|
+
rn,
|
1218
1224
|
{
|
1219
1225
|
open: n ?? !1,
|
1220
1226
|
user: r,
|
1221
|
-
handleClose:
|
1227
|
+
handleClose: c
|
1222
1228
|
},
|
1223
1229
|
r?.uid ?? "new"
|
1224
1230
|
)
|
1225
1231
|
] });
|
1226
1232
|
};
|
1227
|
-
function
|
1233
|
+
function Nn({ userManagement: t }) {
|
1228
1234
|
return {
|
1229
1235
|
key: "user_management",
|
1230
1236
|
loading: t.loading,
|
1231
1237
|
provider: {
|
1232
|
-
Component:
|
1238
|
+
Component: He,
|
1233
1239
|
props: {
|
1234
1240
|
userManagement: t
|
1235
1241
|
}
|
1236
1242
|
}
|
1237
1243
|
};
|
1238
1244
|
}
|
1239
|
-
const
|
1245
|
+
const xn = [
|
1240
1246
|
{
|
1241
1247
|
path: "users",
|
1242
1248
|
name: "CMS Users",
|
1243
1249
|
group: "Admin",
|
1244
1250
|
icon: "face",
|
1245
|
-
view: /* @__PURE__ */ e(
|
1251
|
+
view: /* @__PURE__ */ e(ln, {})
|
1246
1252
|
},
|
1247
1253
|
{
|
1248
1254
|
path: "roles",
|
1249
1255
|
name: "Roles",
|
1250
1256
|
group: "Admin",
|
1251
1257
|
icon: "gpp_good",
|
1252
|
-
view: /* @__PURE__ */ e(
|
1258
|
+
view: /* @__PURE__ */ e(en, {})
|
1253
1259
|
}
|
1254
1260
|
];
|
1255
1261
|
export {
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1262
|
+
fn as RESERVED_GROUPS,
|
1263
|
+
X as RoleChip,
|
1264
|
+
Ke as RoleYupSchema,
|
1265
|
+
Qe as RolesDetailsForm,
|
1266
|
+
Ze as RolesTable,
|
1267
|
+
en as RolesView,
|
1268
|
+
rn as UserDetailsForm,
|
1263
1269
|
Ue as UserManagementContext,
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1270
|
+
He as UserManagementProvider,
|
1271
|
+
nn as UserYupSchema,
|
1272
|
+
on as UsersTable,
|
1273
|
+
ln as UsersView,
|
1274
|
+
je as areRolesEqual,
|
1275
|
+
pn as cacheDelegatedLoginToken,
|
1276
|
+
vn as clearDelegatedLoginTokensCache,
|
1277
|
+
wn as darkenColor,
|
1278
|
+
Cn as getDelegatedLoginTokenFromCache,
|
1279
|
+
gn as getUserRoles,
|
1280
|
+
yn as hexToRgbaWithOpacity,
|
1281
|
+
Ye as resolveUserRolePermissions,
|
1282
|
+
bn as useBuildFirestoreUserManagement,
|
1283
|
+
j as useUserManagement,
|
1284
|
+
Nn as useUserManagementPlugin,
|
1285
|
+
xn as userManagementAdminViews
|
1280
1286
|
};
|
1281
1287
|
//# sourceMappingURL=index.es.js.map
|