@firecms/user_management 3.0.0-canary.49 → 3.0.0-canary.51

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,19 +1,19 @@
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";
1
+ import F, { useEffect as ce, useCallback as k, useContext as Fe, useState as A } from "react";
2
+ import { getFirestore as Y, onSnapshot as ue, collection as ee, setDoc as me, doc as H, addDoc as Ae, 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 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";
4
+ import { getColorSchemeForSeed as Pe, Chip as Te, Dialog as fe, DialogContent as ge, Typography as P, 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 Le, MultiSelectItem as Be } from "@firecms/ui";
5
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";
6
+ import { toSnakeCase as _e, FieldCaption as B, DeleteConfirmationDialog as xe, useNavigationController as Ve, useSnackbarController as se, useAuthController as ae, useCustomizationController as Me, defaultDateFormat as Oe } from "@firecms/core";
7
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 = {
8
+ import { format as $e } from "date-fns";
9
+ import * as qe from "date-fns/locale";
10
+ const gn = ["Admin"], Ye = {
11
11
  read: !1,
12
12
  edit: !1,
13
13
  create: !1,
14
14
  delete: !1
15
15
  };
16
- function Ye({
16
+ function We({
17
17
  collection: t,
18
18
  user: r
19
19
  }) {
@@ -33,12 +33,12 @@ function Ye({
33
33
  edit: !1,
34
34
  delete: !1
35
35
  };
36
- return n.map((i) => We(i, t.id)).reduce(te, l);
36
+ return n.map((i) => je(i, t.id)).reduce(te, l);
37
37
  }
38
38
  } else
39
- return qe;
39
+ return Ye;
40
40
  }
41
- function We(t, r) {
41
+ function je(t, r) {
42
42
  const n = {
43
43
  read: t.isAdmin || t.defaultPermissions?.read,
44
44
  create: t.isAdmin || t.defaultPermissions?.create,
@@ -53,23 +53,23 @@ const te = (t, r) => ({
53
53
  edit: t.edit || r.edit,
54
54
  delete: t.delete || r.delete
55
55
  });
56
- function gn(t, r) {
56
+ function pn(t, r) {
57
57
  return t ? r.roles ? r.roles.map((n) => t.find((l) => l.id === n.id)).filter(Boolean) : [] : void 0;
58
58
  }
59
- const je = (t, r) => {
59
+ const ze = (t, r) => {
60
60
  const n = t.map((i) => i.id), l = r.map((i) => i.id);
61
61
  return n.length === r.length && n.every((i) => l.includes(i));
62
62
  };
63
- function pn(t, r) {
63
+ function Cn(t, r) {
64
64
  if (!r)
65
65
  return;
66
- const n = ze(r), l = new Date(n.exp * 1e3);
66
+ const n = Je(r), l = new Date(n.exp * 1e3);
67
67
  localStorage.setItem(`auth_token::${t}`, JSON.stringify({
68
68
  token: r,
69
69
  expiry: l
70
70
  }));
71
71
  }
72
- function Cn(t) {
72
+ function vn(t) {
73
73
  const r = localStorage.getItem(`auth_token::${t}`);
74
74
  if (r) {
75
75
  const n = JSON.parse(r);
@@ -77,13 +77,13 @@ function Cn(t) {
77
77
  return n.token;
78
78
  }
79
79
  }
80
- function vn() {
80
+ function wn() {
81
81
  for (let t = 0; t < localStorage.length; t++) {
82
82
  const r = localStorage.key(t);
83
83
  r?.startsWith("auth_token::") && localStorage.removeItem(r);
84
84
  }
85
85
  }
86
- function ze(t) {
86
+ function Je(t) {
87
87
  if (!t)
88
88
  throw new Error("No JWT token");
89
89
  const n = t.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"), l = decodeURIComponent(window.atob(n).split("").map(function(i) {
@@ -91,7 +91,7 @@ function ze(t) {
91
91
  }).join(""));
92
92
  return JSON.parse(l);
93
93
  }
94
- function wn(t, r = 10) {
94
+ function yn(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("");
@@ -99,38 +99,38 @@ function wn(t, r = 10) {
99
99
  let l = parseInt(n[0] + n[1], 16), i = parseInt(n[2] + n[3], 16), m = parseInt(n[4] + n[5], 16);
100
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 yn(t, r = 10) {
102
+ function bn(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 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})`;
107
+ const l = parseInt(n[0] + n[1], 16), i = parseInt(n[2] + n[3], 16), m = parseInt(n[4] + n[5], 16), g = r / 100;
108
+ return `rgba(${l}, ${i}, ${m}, ${g})`;
109
109
  }
110
- function bn({
110
+ function Nn({
111
111
  firebaseApp: t,
112
112
  usersPath: r = "__FIRECMS/config/users",
113
113
  rolesPath: n = "__FIRECMS/config/roles",
114
114
  usersLimit: l,
115
115
  canEditRoles: i = !0,
116
116
  allowDefaultRolesCreation: m,
117
- includeCollectionConfigPermissions: f
117
+ includeCollectionConfigPermissions: g
118
118
  }) {
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))
119
+ const [v, R] = F.useState(!0), [w, c] = F.useState(!0), [E, U] = F.useState([]), [a, C] = F.useState([]), y = a.map((f) => ({
120
+ ...f,
121
+ roles: E.filter((p) => f.roles?.includes(p.id))
122
122
  })), [b, _] = F.useState(), [z, u] = F.useState(), h = v || w;
123
123
  ce(() => {
124
124
  if (!t || !n)
125
125
  return;
126
- const g = Y(t);
126
+ const f = Y(t);
127
127
  return ue(
128
- ee(g, n),
128
+ ee(f, n),
129
129
  {
130
130
  next: (p) => {
131
131
  _(void 0);
132
132
  try {
133
- const N = Ge(p.docs);
133
+ const N = He(p.docs);
134
134
  U(N);
135
135
  } catch (N) {
136
136
  console.error("Error loading roles", N), _(N);
@@ -145,14 +145,14 @@ function bn({
145
145
  }, [t, n]), ce(() => {
146
146
  if (!t || !r)
147
147
  return;
148
- const g = Y(t);
148
+ const f = Y(t);
149
149
  return ue(
150
- ee(g, r),
150
+ ee(f, r),
151
151
  {
152
152
  next: (p) => {
153
153
  u(void 0);
154
154
  try {
155
- const N = Je(p.docs);
155
+ const N = Ge(p.docs);
156
156
  C(N);
157
157
  } catch (N) {
158
158
  console.error("Error loading users", N), u(N);
@@ -165,71 +165,71 @@ function bn({
165
165
  }
166
166
  );
167
167
  }, [t, r]);
168
- const x = k(async (g) => {
168
+ const x = k(async (f) => {
169
169
  if (!t)
170
170
  throw Error("useFirestoreUserManagement Firebase not initialised");
171
171
  const p = Y(t);
172
172
  if (!p || !r)
173
173
  throw Error("useFirestoreUserManagement Firestore not initialised");
174
- console.debug("Persisting user", g);
175
- const N = g.roles?.map((ke) => ke.id), {
174
+ console.debug("Persisting user", f);
175
+ const N = f.roles?.map((Ie) => Ie.id), {
176
176
  uid: q,
177
177
  ...Z
178
- } = g, de = {
178
+ } = f, de = {
179
179
  ...Z,
180
180
  roles: N
181
181
  };
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) => {
182
+ return q ? me(H(p, r, q), de, { merge: !0 }).then(() => f) : Ae(ee(p, r), de).then(() => f);
183
+ }, [r, t]), D = k((f) => {
184
184
  if (!t)
185
185
  throw Error("useFirestoreUserManagement Firebase not initialised");
186
186
  const p = Y(t);
187
187
  if (!p || !n)
188
188
  throw Error("useFirestoreUserManagement Firestore not initialised");
189
- console.debug("Persisting role", g);
189
+ console.debug("Persisting role", f);
190
190
  const {
191
191
  id: N,
192
192
  ...q
193
- } = g, Z = H(p, n, N);
193
+ } = f, Z = H(p, n, N);
194
194
  return me(Z, q, { merge: !0 });
195
- }, [n, t]), T = k(async (g) => {
195
+ }, [n, t]), T = k(async (f) => {
196
196
  if (!t)
197
197
  throw Error("useFirestoreUserManagement Firebase not initialised");
198
198
  const p = Y(t);
199
199
  if (!p || !r)
200
200
  throw Error("useFirestoreUserManagement Firestore not initialised");
201
- console.debug("Deleting", g);
202
- const { uid: N } = g;
201
+ console.debug("Deleting", f);
202
+ const { uid: N } = f;
203
203
  return he(H(p, r, N));
204
- }, [r, t]), o = k((g) => {
204
+ }, [r, t]), o = k((f) => {
205
205
  if (!t)
206
206
  throw Error("useFirestoreUserManagement Firebase not initialised");
207
207
  const p = Y(t);
208
208
  if (!p || !n)
209
209
  throw Error("useFirestoreUserManagement Firestore not initialised");
210
- console.debug("Deleting", g);
211
- const { id: N } = g, q = H(p, n, N);
210
+ console.debug("Deleting", f);
211
+ const { id: N } = f, q = H(p, n, N);
212
212
  return he(q);
213
- }, [n, t]), E = k(({
214
- collection: g,
213
+ }, [n, t]), S = k(({
214
+ collection: f,
215
215
  user: p
216
- }) => Ye({
217
- collection: g,
216
+ }) => We({
217
+ collection: f,
218
218
  user: p
219
- }), []), $ = k((g) => {
219
+ }), []), $ = k((f) => {
220
220
  if (!y)
221
221
  throw Error("Users not loaded");
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)
222
+ return y.find((N) => N.email?.toLowerCase() === f?.email?.toLowerCase())?.roles;
223
+ }, [y]), G = k(({ user: f }) => {
224
+ if (console.debug("Authenticating user", f), h)
225
225
  return console.warn("User management is still loading"), !1;
226
- if (y.length === 0 || y.find((N) => N.email?.toLowerCase() === g?.email?.toLowerCase()))
226
+ if (y.length === 0 || y.find((N) => N.email?.toLowerCase() === f?.email?.toLowerCase()))
227
227
  return !0;
228
228
  throw Error("Could not find a user with the provided email in the user management system.");
229
- }, [h, y]);
229
+ }, [h, y]), ke = E.some((f) => f.id === "admin");
230
230
  return {
231
231
  loading: h,
232
- roles: S,
232
+ roles: E,
233
233
  users: y,
234
234
  saveUser: x,
235
235
  saveRole: D,
@@ -238,15 +238,16 @@ function bn({
238
238
  deleteRole: o,
239
239
  usersLimit: l,
240
240
  usersError: z,
241
+ isAdmin: ke,
241
242
  canEditRoles: i === void 0 ? !0 : i,
242
243
  allowDefaultRolesCreation: m === void 0 ? !0 : m,
243
- includeCollectionConfigPermissions: !!f,
244
- collectionPermissions: E,
244
+ includeCollectionConfigPermissions: !!g,
245
+ collectionPermissions: S,
245
246
  defineRolesFor: $,
246
247
  authenticator: G
247
248
  };
248
249
  }
249
- const Je = (t) => t.map((r) => {
250
+ const Ge = (t) => t.map((r) => {
250
251
  const n = r.data();
251
252
  return {
252
253
  uid: r.id,
@@ -254,21 +255,21 @@ const Je = (t) => t.map((r) => {
254
255
  created_on: n?.created_on?.toDate(),
255
256
  updated_on: n?.updated_on?.toDate()
256
257
  };
257
- }), Ge = (t) => t.map((r) => ({
258
+ }), He = (t) => t.map((r) => ({
258
259
  id: r.id,
259
260
  ...r.data()
260
261
  })), Ee = F.createContext({});
261
- function He({
262
+ function Ke({
262
263
  children: t,
263
264
  userManagement: r
264
265
  }) {
265
266
  return /* @__PURE__ */ e(Ee.Provider, { value: r, children: t });
266
267
  }
267
- const j = () => Ie(Ee);
268
+ const j = () => Fe(Ee);
268
269
  function X({ role: t }) {
269
270
  let r;
270
271
  return t.isAdmin ? r = "blueDarker" : t.id === "editor" ? r = "yellowLight" : t.id === "viewer" ? r = "grayLight" : r = Pe(t.id), /* @__PURE__ */ e(
271
- Ae,
272
+ Te,
272
273
  {
273
274
  colorScheme: r,
274
275
  children: t.name
@@ -276,34 +277,34 @@ function X({ role: t }) {
276
277
  t.id
277
278
  );
278
279
  }
279
- const Ke = M.object().shape({
280
+ const Qe = M.object().shape({
280
281
  id: M.string().required("Required"),
281
282
  name: M.string().required("Required")
282
283
  });
283
- function Qe({
284
+ function Xe({
284
285
  open: t,
285
286
  role: r,
286
287
  editable: n,
287
288
  handleClose: l,
288
289
  collections: i
289
290
  }) {
290
- const { saveRole: m } = j(), f = !r, [v, R] = P(), w = k((o) => (R(void 0), m(o)), [m]), c = Re({
291
+ const { saveRole: m } = j(), g = !r, [v, R] = A(), w = k((o) => (R(void 0), m(o)), [m]), c = Re({
291
292
  initialValues: r ?? {
292
293
  name: ""
293
294
  },
294
- onSubmit: (o, E) => w(o).then(() => {
295
- E.resetForm({
295
+ onSubmit: (o, S) => w(o).then(() => {
296
+ S.resetForm({
296
297
  values: o
297
298
  }), l();
298
299
  }).catch(($) => R($)),
299
- validation: (o) => Ke.validate(o, { abortEarly: !1 }).then(() => ({})).catch((E) => {
300
+ validation: (o) => Qe.validate(o, { abortEarly: !1 }).then(() => ({})).catch((S) => {
300
301
  const $ = {};
301
- return E.inner.forEach((G) => {
302
+ return S.inner.forEach((G) => {
302
303
  $[G.path] = G.message;
303
304
  }), $;
304
305
  })
305
306
  }), {
306
- isSubmitting: S,
307
+ isSubmitting: E,
307
308
  touched: U,
308
309
  values: a,
309
310
  errors: C,
@@ -313,7 +314,7 @@ function Qe({
313
314
  setFieldTouched: z
314
315
  } = 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;
315
316
  return F.useEffect(() => {
316
- !J(U, "id") && a.name && b("id", Be(a.name));
317
+ !J(U, "id") && a.name && b("id", _e(a.name));
317
318
  }, [U, a.name]), /* @__PURE__ */ e(
318
319
  fe,
319
320
  {
@@ -338,7 +339,7 @@ function Qe({
338
339
  {
339
340
  className: "flex flex-row pt-12 pb-8",
340
341
  children: /* @__PURE__ */ e(
341
- A,
342
+ P,
342
343
  {
343
344
  variant: "h4",
344
345
  className: "flex-grow",
@@ -372,7 +373,7 @@ function Qe({
372
373
  required: !0,
373
374
  error: U.id && !!C.id,
374
375
  value: a.id,
375
- disabled: !f || !n,
376
+ disabled: !g || !n,
376
377
  onChange: (o) => {
377
378
  y(o), z("id", !0);
378
379
  },
@@ -526,7 +527,7 @@ function Qe({
526
527
  {
527
528
  disabled: u || h || !n,
528
529
  checked: (u || h || J(a, `collectionPermissions.${o.path}.create`)) ?? !1,
529
- onCheckedChange: (E) => b(`collectionPermissions.${o.path}.create`, E)
530
+ onCheckedChange: (S) => b(`collectionPermissions.${o.path}.create`, S)
530
531
  }
531
532
  )
532
533
  }
@@ -540,7 +541,7 @@ function Qe({
540
541
  {
541
542
  disabled: u || x || !n,
542
543
  checked: (u || x || J(a, `collectionPermissions.${o.path}.read`)) ?? !1,
543
- onCheckedChange: (E) => b(`collectionPermissions.${o.path}.read`, E)
544
+ onCheckedChange: (S) => b(`collectionPermissions.${o.path}.read`, S)
544
545
  }
545
546
  )
546
547
  }
@@ -554,7 +555,7 @@ function Qe({
554
555
  {
555
556
  disabled: u || D || !n,
556
557
  checked: (u || D || J(a, `collectionPermissions.${o.path}.edit`)) ?? !1,
557
- onCheckedChange: (E) => b(`collectionPermissions.${o.path}.edit`, E)
558
+ onCheckedChange: (S) => b(`collectionPermissions.${o.path}.edit`, S)
558
559
  }
559
560
  )
560
561
  }
@@ -568,7 +569,7 @@ function Qe({
568
569
  {
569
570
  disabled: u || T || !n,
570
571
  checked: (u || T || J(a, `collectionPermissions.${o.path}.delete`)) ?? !1,
571
- onCheckedChange: (E) => b(`collectionPermissions.${o.path}.delete`, E)
572
+ onCheckedChange: (S) => b(`collectionPermissions.${o.path}.delete`, S)
572
573
  }
573
574
  )
574
575
  }
@@ -696,7 +697,7 @@ function Qe({
696
697
  ] })
697
698
  ] }),
698
699
  /* @__PURE__ */ s(Ce, { position: "sticky", children: [
699
- v && /* @__PURE__ */ e(A, { className: "text-red-500", children: "There was an error saving this role" }),
700
+ v && /* @__PURE__ */ e(P, { className: "text-red-500", children: "There was an error saving this role" }),
700
701
  /* @__PURE__ */ e(
701
702
  O,
702
703
  {
@@ -714,9 +715,9 @@ function Qe({
714
715
  color: "primary",
715
716
  type: "submit",
716
717
  disabled: !_,
717
- loading: S,
718
+ loading: E,
718
719
  startIcon: /* @__PURE__ */ e(we, {}),
719
- children: f ? "Create role" : "Update"
720
+ children: g ? "Create role" : "Update"
720
721
  }
721
722
  )
722
723
  ] })
@@ -760,7 +761,7 @@ const Se = [
760
761
  }
761
762
  }
762
763
  ];
763
- function Xe({
764
+ function Ze({
764
765
  onRoleClicked: t,
765
766
  editable: r
766
767
  }) {
@@ -769,7 +770,7 @@ function Xe({
769
770
  saveRole: l,
770
771
  deleteRole: i,
771
772
  allowDefaultRolesCreation: m
772
- } = j(), [f, v] = P(void 0), [R, w] = P(!1);
773
+ } = j(), [g, v] = A(void 0), [R, w] = A(!1);
773
774
  return /* @__PURE__ */ s(
774
775
  "div",
775
776
  {
@@ -784,7 +785,7 @@ function Xe({
784
785
  ] }),
785
786
  /* @__PURE__ */ s(oe, { children: [
786
787
  n && n.map((c) => {
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;
788
+ const E = c.isAdmin || c.defaultPermissions?.create, U = c.isAdmin || c.defaultPermissions?.read, a = c.isAdmin || c.defaultPermissions?.edit, C = c.isAdmin || c.defaultPermissions?.delete;
788
789
  return /* @__PURE__ */ s(
789
790
  W,
790
791
  {
@@ -804,7 +805,7 @@ function Xe({
804
805
  /* @__PURE__ */ e(d, { children: /* @__PURE__ */ e(X, { role: c }) }),
805
806
  /* @__PURE__ */ e(d, { className: "items-center", children: /* @__PURE__ */ e(I, { checked: c.isAdmin ?? !1 }) }),
806
807
  /* @__PURE__ */ e(d, { children: /* @__PURE__ */ s("ul", { children: [
807
- S && /* @__PURE__ */ e("li", { children: "Create" }),
808
+ E && /* @__PURE__ */ e("li", { children: "Create" }),
808
809
  U && /* @__PURE__ */ e("li", { children: "Read" }),
809
810
  a && /* @__PURE__ */ e("li", { children: "Update" }),
810
811
  C && /* @__PURE__ */ e("li", { children: "Delete" })
@@ -815,7 +816,7 @@ function Xe({
815
816
  );
816
817
  }),
817
818
  (!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
+ /* @__PURE__ */ e(P, { variant: "label", children: "You don't have any roles yet." }),
819
820
  m && /* @__PURE__ */ e(
820
821
  O,
821
822
  {
@@ -834,10 +835,10 @@ function Xe({
834
835
  /* @__PURE__ */ e(
835
836
  xe,
836
837
  {
837
- open: !!f,
838
+ open: !!g,
838
839
  loading: R,
839
840
  onAccept: () => {
840
- f && (w(!0), i(f).then(() => {
841
+ g && (w(!0), i(g).then(() => {
841
842
  v(void 0);
842
843
  }).finally(() => {
843
844
  w(!1);
@@ -854,16 +855,16 @@ function Xe({
854
855
  }
855
856
  );
856
857
  }
857
- const Ze = F.memo(
858
+ const en = F.memo(
858
859
  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);
860
+ const { collections: n } = Ve(), [l, i] = A(!1), [m, g] = A(), { canEditRoles: v } = j(), R = k((c) => {
861
+ i(!0), g(c);
861
862
  }, []);
862
863
  return /* @__PURE__ */ s(Ue, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
863
864
  r,
864
865
  /* @__PURE__ */ s("div", { className: "flex items-center mt-12", children: [
865
866
  /* @__PURE__ */ e(
866
- A,
867
+ P,
867
868
  {
868
869
  gutterBottom: !0,
869
870
  variant: "h4",
@@ -883,36 +884,36 @@ const Ze = F.memo(
883
884
  }
884
885
  ) })
885
886
  ] }),
886
- /* @__PURE__ */ e(Xe, { onRoleClicked: R, editable: !!v }),
887
+ /* @__PURE__ */ e(Ze, { onRoleClicked: R, editable: !!v }),
887
888
  /* @__PURE__ */ e(
888
- Qe,
889
+ Xe,
889
890
  {
890
891
  open: l,
891
892
  role: m,
892
893
  editable: v,
893
894
  collections: n,
894
895
  handleClose: () => {
895
- f(void 0), i(!1);
896
+ g(void 0), i(!1);
896
897
  }
897
898
  },
898
899
  m?.id ?? "new"
899
900
  )
900
901
  ] });
901
902
  }
902
- ), en = M.object().shape({
903
+ ), nn = M.object().shape({
903
904
  displayName: M.string().required("Required"),
904
905
  email: M.string().email().required("Required"),
905
906
  roles: M.array().min(1)
906
907
  });
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)
908
+ function tn(t, r, n, l, i) {
909
+ const m = n.filter((w) => w.roles?.map((c) => c.id).includes("admin")), g = t.roles?.map((w) => w.id).includes("admin");
910
+ if ((!i || !ze(i.roles ?? [], r.roles ?? [])) && !g)
910
911
  throw new Error("Only admins can change roles");
911
912
  if (i && i.roles?.map((w) => w.id).includes("admin") && !r.roles?.map((w) => w.id).includes("admin") && m.length === 1)
912
913
  throw new Error("There must be at least one admin");
913
914
  return !0;
914
915
  }
915
- function tn({
916
+ function rn({
916
917
  open: t,
917
918
  user: r,
918
919
  handleClose: n
@@ -921,23 +922,23 @@ function tn({
921
922
  user: i
922
923
  } = ae(), {
923
924
  saveUser: m,
924
- users: f,
925
+ users: g,
925
926
  roles: v
926
927
  } = j(), R = !r, w = k((h) => {
927
928
  if (!i)
928
929
  throw new Error("Logged user not found");
929
930
  try {
930
- return nn(i, h, f, v, r), m(h);
931
+ return tn(i, h, g, v, r), m(h);
931
932
  } catch (x) {
932
933
  return Promise.reject(x);
933
934
  }
934
- }, [v, m, r, f, i]), c = Re({
935
+ }, [v, m, r, g, i]), c = Re({
935
936
  initialValues: r ?? {
936
937
  displayName: "",
937
938
  email: "",
938
939
  roles: v.filter((h) => h.id === "editor")
939
940
  },
940
- validation: (h) => en.validate(h, { abortEarly: !1 }).then(() => ({})).catch((x) => x.inner.reduce((D, T) => (D[T.path] = T.message, D), {})),
941
+ validation: (h) => nn.validate(h, { abortEarly: !1 }).then(() => ({})).catch((x) => x.inner.reduce((D, T) => (D[T.path] = T.message, D), {})),
941
942
  onSubmit: (h, x) => w(h).then(() => {
942
943
  n(), x.resetForm({
943
944
  values: h
@@ -949,7 +950,7 @@ function tn({
949
950
  });
950
951
  })
951
952
  }), {
952
- isSubmitting: S,
953
+ isSubmitting: E,
953
954
  touched: U,
954
955
  handleChange: a,
955
956
  values: C,
@@ -984,7 +985,7 @@ function tn({
984
985
  {
985
986
  className: "flex flex-row pt-4 pb-4",
986
987
  children: /* @__PURE__ */ e(
987
- A,
988
+ P,
988
989
  {
989
990
  variant: "h4",
990
991
  className: "flex-grow",
@@ -1025,7 +1026,7 @@ function tn({
1025
1026
  /* @__PURE__ */ e(B, { children: u > 0 && y.email ? y.email : "Email of this user" })
1026
1027
  ] }),
1027
1028
  /* @__PURE__ */ e("div", { className: "col-span-12", children: /* @__PURE__ */ e(
1028
- Te,
1029
+ Le,
1029
1030
  {
1030
1031
  label: "Roles",
1031
1032
  value: C.roles?.map((h) => h.id) ?? [],
@@ -1035,7 +1036,7 @@ function tn({
1035
1036
  return x ? /* @__PURE__ */ e("div", { className: "flex flex-wrap space-x-2 space-y-2", children: /* @__PURE__ */ e(X, { role: x }, x?.id) }) : null;
1036
1037
  },
1037
1038
  children: v.map((h) => /* @__PURE__ */ e(
1038
- Le,
1039
+ Be,
1039
1040
  {
1040
1041
  value: h.id,
1041
1042
  children: /* @__PURE__ */ e(X, { role: h }, h?.id)
@@ -1064,7 +1065,7 @@ function tn({
1064
1065
  color: "primary",
1065
1066
  type: "submit",
1066
1067
  disabled: !_,
1067
- loading: S,
1068
+ loading: E,
1068
1069
  startIcon: /* @__PURE__ */ e(we, {}),
1069
1070
  children: R ? "Create user" : "Update"
1070
1071
  }
@@ -1076,12 +1077,12 @@ function tn({
1076
1077
  }
1077
1078
  );
1078
1079
  }
1079
- function rn({ onUserClicked: t }) {
1080
+ function on({ onUserClicked: t }) {
1080
1081
  const {
1081
1082
  users: r,
1082
1083
  saveUser: n,
1083
1084
  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);
1085
+ } = j(), i = ae(), m = se(), g = Me(), v = g?.locale ? qe[g?.locale] : void 0, R = g?.dateTimeFormat ?? Oe, [w, c] = A(void 0), [E, U] = A(!1);
1085
1086
  return /* @__PURE__ */ s("div", { className: "overflow-auto", children: [
1086
1087
  /* @__PURE__ */ s(re, { children: [
1087
1088
  /* @__PURE__ */ s(ie, { children: [
@@ -1094,7 +1095,7 @@ function rn({ onUserClicked: t }) {
1094
1095
  ] }),
1095
1096
  /* @__PURE__ */ s(oe, { children: [
1096
1097
  r && r.map((a) => {
1097
- const C = a.roles, y = a.created_on ? Oe(a.created_on, R, { locale: v }) : "";
1098
+ const C = a.roles, y = a.created_on ? $e(a.created_on, R, { locale: v }) : "";
1098
1099
  return /* @__PURE__ */ s(
1099
1100
  W,
1100
1101
  {
@@ -1123,7 +1124,7 @@ function rn({ onUserClicked: t }) {
1123
1124
  );
1124
1125
  }),
1125
1126
  (!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" }),
1127
+ /* @__PURE__ */ e(P, { variant: "label", children: "There are no users yet" }),
1127
1128
  /* @__PURE__ */ e(
1128
1129
  O,
1129
1130
  {
@@ -1162,7 +1163,7 @@ function rn({ onUserClicked: t }) {
1162
1163
  xe,
1163
1164
  {
1164
1165
  open: !!w,
1165
- loading: S,
1166
+ loading: E,
1166
1167
  onAccept: () => {
1167
1168
  w && (U(!0), l(w).then(() => {
1168
1169
  c(void 0);
@@ -1184,9 +1185,9 @@ function rn({ onUserClicked: t }) {
1184
1185
  )
1185
1186
  ] });
1186
1187
  }
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);
1188
+ const ln = function({ children: r }) {
1189
+ const [n, l] = A(), [i, m] = A(), { users: g, usersLimit: v } = j(), R = v !== void 0 && g && g.length >= v, w = k((E) => {
1190
+ m(E), l(!0);
1190
1191
  }, []), c = k(() => {
1191
1192
  l(!1), m(void 0);
1192
1193
  }, []);
@@ -1198,7 +1199,7 @@ const on = function({ children: r }) {
1198
1199
  className: "flex items-center mt-12",
1199
1200
  children: [
1200
1201
  /* @__PURE__ */ e(
1201
- A,
1202
+ P,
1202
1203
  {
1203
1204
  gutterBottom: !0,
1204
1205
  variant: "h4",
@@ -1220,9 +1221,9 @@ const on = function({ children: r }) {
1220
1221
  ]
1221
1222
  }
1222
1223
  ),
1223
- /* @__PURE__ */ e(rn, { onUserClicked: w }),
1224
+ /* @__PURE__ */ e(on, { onUserClicked: w }),
1224
1225
  /* @__PURE__ */ e(
1225
- tn,
1226
+ rn,
1226
1227
  {
1227
1228
  open: n ?? !1,
1228
1229
  user: i,
@@ -1232,14 +1233,14 @@ const on = function({ children: r }) {
1232
1233
  )
1233
1234
  ] });
1234
1235
  };
1235
- function Nn({ userManagement: t }) {
1236
+ function Un({ userManagement: t }) {
1236
1237
  const r = t.users.length === 0, n = t.roles.length === 0;
1237
1238
  return {
1238
1239
  key: "user_management",
1239
1240
  loading: t.loading,
1240
1241
  homePage: {
1241
1242
  additionalChildrenStart: r || n ? /* @__PURE__ */ e(
1242
- ln,
1243
+ sn,
1243
1244
  {
1244
1245
  noUsers: r,
1245
1246
  noRoles: n,
@@ -1248,14 +1249,14 @@ function Nn({ userManagement: t }) {
1248
1249
  ) : void 0
1249
1250
  },
1250
1251
  provider: {
1251
- Component: He,
1252
+ Component: Ke,
1252
1253
  props: {
1253
1254
  userManagement: t
1254
1255
  }
1255
1256
  }
1256
1257
  };
1257
1258
  }
1258
- function ln({
1259
+ function sn({
1259
1260
  noUsers: t,
1260
1261
  noRoles: r,
1261
1262
  userManagement: n
@@ -1266,8 +1267,8 @@ function ln({
1266
1267
  {
1267
1268
  className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-slate-800 gap-2",
1268
1269
  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." }),
1270
+ /* @__PURE__ */ e(P, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" }),
1271
+ /* @__PURE__ */ e(P, { children: "You have no users or roles defined. You can create default roles and add the current user as admin." }),
1271
1272
  /* @__PURE__ */ s(O, { onClick: () => {
1272
1273
  if (!l.user?.uid)
1273
1274
  throw Error("UsersTable, authController misconfiguration");
@@ -1288,13 +1289,13 @@ function ln({
1288
1289
  type: "success",
1289
1290
  message: "User added successfully"
1290
1291
  });
1291
- }).catch((f) => {
1292
+ }).catch((g) => {
1292
1293
  i.open({
1293
1294
  type: "error",
1294
- message: "Error adding user: " + f.message
1295
+ message: "Error adding user: " + g.message
1295
1296
  });
1296
- }), r && Se.forEach((f) => {
1297
- n.saveRole(f);
1297
+ }), r && Se.forEach((g) => {
1298
+ n.saveRole(g);
1298
1299
  });
1299
1300
  }, children: [
1300
1301
  /* @__PURE__ */ e(le, {}),
@@ -1304,47 +1305,47 @@ function ln({
1304
1305
  }
1305
1306
  );
1306
1307
  }
1307
- const Un = [
1308
+ const xn = [
1308
1309
  {
1309
1310
  path: "users",
1310
1311
  name: "CMS Users",
1311
1312
  group: "Admin",
1312
1313
  icon: "face",
1313
- view: /* @__PURE__ */ e(on, {})
1314
+ view: /* @__PURE__ */ e(ln, {})
1314
1315
  },
1315
1316
  {
1316
1317
  path: "roles",
1317
1318
  name: "Roles",
1318
1319
  group: "Admin",
1319
1320
  icon: "gpp_good",
1320
- view: /* @__PURE__ */ e(Ze, {})
1321
+ view: /* @__PURE__ */ e(en, {})
1321
1322
  }
1322
1323
  ];
1323
1324
  export {
1324
- ln as IntroWidget,
1325
- fn as RESERVED_GROUPS,
1325
+ sn as IntroWidget,
1326
+ gn as RESERVED_GROUPS,
1326
1327
  X as RoleChip,
1327
- Ke as RoleYupSchema,
1328
- Qe as RolesDetailsForm,
1329
- Xe as RolesTable,
1330
- Ze as RolesView,
1331
- tn as UserDetailsForm,
1328
+ Qe as RoleYupSchema,
1329
+ Xe as RolesDetailsForm,
1330
+ Ze as RolesTable,
1331
+ en as RolesView,
1332
+ rn as UserDetailsForm,
1332
1333
  Ee as UserManagementContext,
1333
- He as UserManagementProvider,
1334
- en as UserYupSchema,
1335
- rn as UsersTable,
1336
- on as UsersView,
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,
1334
+ Ke as UserManagementProvider,
1335
+ nn as UserYupSchema,
1336
+ on as UsersTable,
1337
+ ln as UsersView,
1338
+ ze as areRolesEqual,
1339
+ Cn as cacheDelegatedLoginToken,
1340
+ wn as clearDelegatedLoginTokensCache,
1341
+ yn as darkenColor,
1342
+ vn as getDelegatedLoginTokenFromCache,
1343
+ pn as getUserRoles,
1344
+ bn as hexToRgbaWithOpacity,
1345
+ We as resolveUserRolePermissions,
1346
+ Nn as useFirestoreUserManagement,
1346
1347
  j as useUserManagement,
1347
- Nn as useUserManagementPlugin,
1348
- Un as userManagementAdminViews
1348
+ Un as useUserManagementPlugin,
1349
+ xn as userManagementAdminViews
1349
1350
  };
1350
1351
  //# sourceMappingURL=index.es.js.map