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