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