@firecms/user_management 3.0.0-canary.41 → 3.0.0-canary.43

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