@firecms/user_management 3.0.0-canary.153 → 3.0.0-canary.155

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.umd.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react-fast-compare"), require("@firecms/core"), require("react/jsx-runtime"), require("@firecms/ui"), require("yup"), require("@firecms/formex"), require("date-fns"), require("date-fns/locale")) : typeof define === "function" && define.amd ? define(["exports", "react", "react-fast-compare", "@firecms/core", "react/jsx-runtime", "@firecms/ui", "yup", "@firecms/formex", "date-fns", "date-fns/locale"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.FireCMS = {}, global.React, global.equal, global.core, global.jsxRuntime, global.ui, global.Yup, global.formex, global.dateFns, global.locales));
3
- })(this, function(exports2, React, equal, core, jsxRuntime, ui, Yup, formex, dateFns, locales) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react"), require("react-fast-compare"), require("@firecms/core"), require("react/jsx-runtime"), require("react-compiler-runtime"), require("@firecms/ui"), require("yup"), require("@firecms/formex"), require("date-fns"), require("date-fns/locale")) : typeof define === "function" && define.amd ? define(["exports", "react", "react-fast-compare", "@firecms/core", "react/jsx-runtime", "react-compiler-runtime", "@firecms/ui", "yup", "@firecms/formex", "date-fns", "date-fns/locale"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.FireCMS = {}, global.React, global.equal, global.core, global.jsxRuntime, global.reactCompilerRuntime, global.ui, global.Yup, global.formex, global.dateFns, global.locales));
3
+ })(this, function(exports2, React, equal, core, jsxRuntime, reactCompilerRuntime, ui, Yup, formex, dateFns, locales) {
4
4
  "use strict";
5
5
  function _interopNamespaceDefault(e) {
6
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -201,10 +201,10 @@
201
201
  }
202
202
  setRolesLoading(false);
203
203
  },
204
- onError(e) {
204
+ onError(e_0) {
205
205
  setRoles([]);
206
- console.error("Error loading roles", e);
207
- setRolesError(e);
206
+ console.error("Error loading roles", e_0);
207
+ setRolesError(e_0);
208
208
  setRolesLoading(false);
209
209
  }
210
210
  });
@@ -220,23 +220,23 @@
220
220
  setUsersLoading(true);
221
221
  return dataSourceDelegate.listenCollection?.({
222
222
  path: usersPath,
223
- onUpdate(entities) {
224
- console.debug("Updating users", entities);
223
+ onUpdate(entities_0) {
224
+ console.debug("Updating users", entities_0);
225
225
  setUsersError(void 0);
226
226
  try {
227
- const newUsers = entitiesToUsers(entities);
227
+ const newUsers = entitiesToUsers(entities_0);
228
228
  setUsersWithRoleIds(newUsers);
229
- } catch (e) {
229
+ } catch (e_1) {
230
230
  setUsersWithRoleIds([]);
231
- console.error("Error loading users", e);
232
- setUsersError(e);
231
+ console.error("Error loading users", e_1);
232
+ setUsersError(e_1);
233
233
  }
234
234
  setUsersLoading(false);
235
235
  },
236
- onError(e) {
237
- console.error("Error loading users", e);
236
+ onError(e_2) {
237
+ console.error("Error loading users", e_2);
238
238
  setUsersWithRoleIds([]);
239
- setUsersError(e);
239
+ setUsersError(e_2);
240
240
  setUsersLoading(false);
241
241
  }
242
242
  });
@@ -245,10 +245,10 @@
245
245
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
246
246
  if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
247
247
  console.debug("Persisting user", user);
248
- const roleIds = user.roles?.map((r) => r.id);
248
+ const roleIds = user.roles?.map((r_0) => r_0.id);
249
249
  const email = user.email?.toLowerCase().trim();
250
250
  if (!email) throw Error("Email is required");
251
- const userExists = users.find((u) => u.email?.toLowerCase() === email);
251
+ const userExists = users.find((u_0) => u_0.email?.toLowerCase() === email);
252
252
  const data = {
253
253
  ...user,
254
254
  roles: roleIds ?? []
@@ -280,47 +280,57 @@
280
280
  return;
281
281
  });
282
282
  }, [rolesPath, dataSourceDelegate?.initialised]);
283
- const deleteUser = React.useCallback(async (user) => {
283
+ const deleteUser = React.useCallback(async (user_0) => {
284
284
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
285
285
  if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
286
- console.debug("Deleting", user);
287
- const { uid } = user;
286
+ console.debug("Deleting", user_0);
287
+ const {
288
+ uid
289
+ } = user_0;
288
290
  const entity = {
289
291
  path: usersPath,
290
292
  id: uid,
291
293
  values: {}
292
294
  };
293
- await dataSourceDelegate.deleteEntity({ entity });
295
+ await dataSourceDelegate.deleteEntity({
296
+ entity
297
+ });
294
298
  }, [usersPath, dataSourceDelegate?.initialised]);
295
- const deleteRole = React.useCallback(async (role) => {
299
+ const deleteRole = React.useCallback(async (role_0) => {
296
300
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
297
301
  if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
298
- console.debug("Deleting", role);
299
- const { id } = role;
300
- const entity = {
302
+ console.debug("Deleting", role_0);
303
+ const {
304
+ id: id_0
305
+ } = role_0;
306
+ const entity_0 = {
301
307
  path: rolesPath,
302
- id,
308
+ id: id_0,
303
309
  values: {}
304
310
  };
305
- await dataSourceDelegate.deleteEntity({ entity });
311
+ await dataSourceDelegate.deleteEntity({
312
+ entity: entity_0
313
+ });
306
314
  }, [rolesPath, dataSourceDelegate?.initialised]);
307
315
  const collectionPermissions = React.useCallback(({
308
316
  collection,
309
- user
317
+ user: user_1
310
318
  }) => resolveUserRolePermissions({
311
319
  collection,
312
- user
320
+ user: user_1
313
321
  }), []);
314
- const defineRolesFor = React.useCallback((user) => {
322
+ const defineRolesFor = React.useCallback((user_2) => {
315
323
  if (!usersWithRoleIds) throw Error("Users not loaded");
316
- const users2 = usersWithRoleIds.map((u) => ({
317
- ...u,
318
- roles: roles.filter((r) => u.roles?.includes(r.id))
324
+ const users_0 = usersWithRoleIds.map((u_1) => ({
325
+ ...u_1,
326
+ roles: roles.filter((r_1) => u_1.roles?.includes(r_1.id))
319
327
  }));
320
- const mgmtUser = users2.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
328
+ const mgmtUser = users_0.find((u_2) => u_2.email?.toLowerCase() === user_2?.email?.toLowerCase());
321
329
  return mgmtUser?.roles;
322
330
  }, [roles, usersWithRoleIds]);
323
- const authenticator = React.useCallback(({ user }) => {
331
+ const authenticator = React.useCallback(({
332
+ user: user_3
333
+ }) => {
324
334
  if (loading) {
325
335
  return false;
326
336
  }
@@ -328,15 +338,20 @@
328
338
  console.warn("No users created yet");
329
339
  return true;
330
340
  }
331
- const mgmtUser = users.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
332
- if (mgmtUser) {
333
- console.debug("User found in user management system", mgmtUser);
341
+ const mgmtUser_0 = users.find((u_3) => u_3.email?.toLowerCase() === user_3?.email?.toLowerCase());
342
+ if (mgmtUser_0) {
343
+ console.debug("User found in user management system", mgmtUser_0);
334
344
  return true;
335
345
  }
336
346
  throw Error("Could not find a user with the provided email in the user management system.");
337
347
  }, [loading, users]);
338
348
  const userRoles = authController.user ? defineRolesFor(authController.user) : void 0;
339
- const isAdmin = (userRoles ?? []).some((r) => r.id === "admin");
349
+ const isAdmin = (userRoles ?? []).some((r_2) => r_2.id === "admin");
350
+ const userRoleIds = userRoles?.map((r_3) => r_3.id);
351
+ React.useEffect(() => {
352
+ console.debug("Setting roles", userRoles);
353
+ authController.setUserRoles?.(userRoles ?? []);
354
+ }, [userRoleIds]);
340
355
  return {
341
356
  loading,
342
357
  roles,
@@ -383,32 +398,64 @@
383
398
  }));
384
399
  };
385
400
  const UserManagementContext = React.createContext({});
386
- function UserManagementProvider({
387
- children,
388
- userManagement
389
- }) {
390
- return /* @__PURE__ */ jsxRuntime.jsx(UserManagementContext.Provider, { value: userManagement, children });
401
+ function UserManagementProvider(t0) {
402
+ const $ = reactCompilerRuntime.c(3);
403
+ const {
404
+ children,
405
+ userManagement
406
+ } = t0;
407
+ let t1;
408
+ if ($[0] !== children || $[1] !== userManagement) {
409
+ t1 = /* @__PURE__ */ jsxRuntime.jsx(UserManagementContext.Provider, { value: userManagement, children });
410
+ $[0] = children;
411
+ $[1] = userManagement;
412
+ $[2] = t1;
413
+ } else {
414
+ t1 = $[2];
415
+ }
416
+ return t1;
391
417
  }
392
- const useUserManagement = () => React.useContext(UserManagementContext);
393
- function RoleChip({ role }) {
418
+ const useUserManagement = () => {
419
+ return React.useContext(UserManagementContext);
420
+ };
421
+ function RoleChip(t0) {
422
+ const $ = reactCompilerRuntime.c(6);
423
+ const {
424
+ role
425
+ } = t0;
394
426
  let colorScheme;
395
427
  if (role.isAdmin) {
396
428
  colorScheme = "blueDarker";
397
- } else if (role.id === "editor") {
398
- colorScheme = "yellowLight";
399
- } else if (role.id === "viewer") {
400
- colorScheme = "grayLight";
401
- } else {
402
- colorScheme = ui.getColorSchemeForSeed(role.id);
403
- }
404
- return /* @__PURE__ */ jsxRuntime.jsx(
405
- ui.Chip,
406
- {
407
- colorScheme,
408
- children: role.name
409
- },
410
- role.id
411
- );
429
+ } else {
430
+ if (role.id === "editor") {
431
+ colorScheme = "yellowLight";
432
+ } else {
433
+ if (role.id === "viewer") {
434
+ colorScheme = "grayLight";
435
+ } else {
436
+ let t12;
437
+ if ($[0] !== role.id) {
438
+ t12 = ui.getColorSchemeForSeed(role.id);
439
+ $[0] = role.id;
440
+ $[1] = t12;
441
+ } else {
442
+ t12 = $[1];
443
+ }
444
+ colorScheme = t12;
445
+ }
446
+ }
447
+ }
448
+ let t1;
449
+ if ($[2] !== colorScheme || $[3] !== role.id || $[4] !== role.name) {
450
+ t1 = /* @__PURE__ */ jsxRuntime.jsx(ui.Chip, { colorScheme, children: role.name }, role.id);
451
+ $[2] = colorScheme;
452
+ $[3] = role.id;
453
+ $[4] = role.name;
454
+ $[5] = t1;
455
+ } else {
456
+ t1 = $[5];
457
+ }
458
+ return t1;
412
459
  }
413
460
  const RoleYupSchema = Yup__namespace.object().shape({
414
461
  id: Yup__namespace.string().required("Required"),
@@ -422,562 +469,757 @@
422
469
  }
423
470
  return true;
424
471
  }
425
- function RolesDetailsForm({
426
- open,
427
- role,
428
- editable,
429
- handleClose,
430
- collections
431
- }) {
432
- const { saveRole } = useUserManagement();
472
+ function RolesDetailsForm(t0) {
473
+ const $ = reactCompilerRuntime.c(165);
474
+ const {
475
+ open,
476
+ role,
477
+ editable,
478
+ handleClose,
479
+ collections
480
+ } = t0;
481
+ const {
482
+ saveRole
483
+ } = useUserManagement();
433
484
  const isNewRole = !role;
434
485
  const {
435
486
  user: loggedInUser
436
487
  } = core.useAuthController();
437
488
  const [savingError, setSavingError] = React.useState();
438
- const onRoleUpdated = React.useCallback((role2) => {
439
- setSavingError(void 0);
440
- if (!loggedInUser) throw new Error("User not found");
441
- canRoleBeEdited(loggedInUser);
442
- return saveRole(role2);
443
- }, [saveRole, loggedInUser]);
444
- const formex$1 = formex.useCreateFormex({
445
- initialValues: role ?? {
489
+ let t1;
490
+ if ($[0] !== loggedInUser || $[1] !== saveRole) {
491
+ t1 = (role_0) => {
492
+ setSavingError(void 0);
493
+ if (!loggedInUser) {
494
+ throw new Error("User not found");
495
+ }
496
+ canRoleBeEdited(loggedInUser);
497
+ return saveRole(role_0);
498
+ };
499
+ $[0] = loggedInUser;
500
+ $[1] = saveRole;
501
+ $[2] = t1;
502
+ } else {
503
+ t1 = $[2];
504
+ }
505
+ const onRoleUpdated = t1;
506
+ let t2;
507
+ if ($[3] !== role) {
508
+ t2 = role ?? {
446
509
  name: ""
447
- },
448
- onSubmit: (role2, formexController) => {
510
+ };
511
+ $[3] = role;
512
+ $[4] = t2;
513
+ } else {
514
+ t2 = $[4];
515
+ }
516
+ let t3;
517
+ if ($[5] !== handleClose || $[6] !== onRoleUpdated) {
518
+ t3 = (role_1, formexController) => {
449
519
  try {
450
- return onRoleUpdated(role2).then(() => {
520
+ return onRoleUpdated(role_1).then(() => {
451
521
  formexController.resetForm({
452
- values: role2
522
+ values: role_1
453
523
  });
454
524
  handleClose();
455
- }).catch((e) => {
456
- setSavingError(e);
525
+ }).catch((e_0) => {
526
+ setSavingError(e_0);
457
527
  });
458
- } catch (e) {
528
+ } catch (t410) {
529
+ const e = t410;
459
530
  setSavingError(e);
460
531
  return Promise.resolve();
461
532
  }
462
- },
463
- validation: (values2) => {
464
- return RoleYupSchema.validate(values2, { abortEarly: false }).then(() => ({})).catch((e) => {
465
- const errors2 = {};
466
- e.inner.forEach((error) => {
467
- errors2[error.path] = error.message;
468
- });
469
- return errors2;
470
- });
471
- }
472
- });
533
+ };
534
+ $[5] = handleClose;
535
+ $[6] = onRoleUpdated;
536
+ $[7] = t3;
537
+ } else {
538
+ t3 = $[7];
539
+ }
540
+ let t4;
541
+ if ($[8] !== t2 || $[9] !== t3) {
542
+ t4 = {
543
+ initialValues: t2,
544
+ onSubmit: t3,
545
+ validation: _temp3$1
546
+ };
547
+ $[8] = t2;
548
+ $[9] = t3;
549
+ $[10] = t4;
550
+ } else {
551
+ t4 = $[10];
552
+ }
553
+ const formex$1 = formex.useCreateFormex(t4);
473
554
  const {
474
555
  isSubmitting,
475
556
  touched,
476
- values,
477
- errors,
557
+ values: values_0,
558
+ errors: errors_0,
478
559
  handleChange,
479
560
  setFieldValue,
480
561
  dirty,
481
562
  setFieldTouched
482
563
  } = formex$1;
483
- const isAdmin = values.isAdmin ?? false;
484
- const defaultCreate = values.defaultPermissions?.create ?? false;
485
- const defaultRead = values.defaultPermissions?.read ?? false;
486
- const defaultEdit = values.defaultPermissions?.edit ?? false;
487
- const defaultDelete = values.defaultPermissions?.delete ?? false;
488
- React.useEffect(() => {
489
- const idTouched = formex.getIn(touched, "id");
490
- if (!idTouched && values.name) {
491
- setFieldValue("id", core.toSnakeCase(values.name));
492
- }
493
- }, [touched, values.name]);
494
- return /* @__PURE__ */ jsxRuntime.jsx(
495
- ui.Dialog,
496
- {
497
- open,
498
- maxWidth: "4xl",
499
- children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
500
- "form",
501
- {
502
- noValidate: true,
503
- autoComplete: "off",
504
- onSubmit: formex$1.handleSubmit,
505
- style: {
506
- display: "flex",
507
- flexDirection: "column",
508
- position: "relative",
509
- height: "100%"
510
- },
511
- children: [
512
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "flex-grow", children: [
513
- /* @__PURE__ */ jsxRuntime.jsx(
514
- "div",
515
- {
516
- className: "flex flex-row pt-12 pb-8",
517
- children: /* @__PURE__ */ jsxRuntime.jsx(
518
- ui.Typography,
519
- {
520
- variant: "h4",
521
- className: "flex-grow",
522
- children: "Role"
523
- }
524
- )
525
- }
526
- ),
527
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
528
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-8", children: [
529
- /* @__PURE__ */ jsxRuntime.jsx(
530
- ui.TextField,
531
- {
532
- name: "name",
533
- required: true,
534
- error: touched.name && Boolean(errors.name),
535
- value: values.name,
536
- disabled: isAdmin || !editable,
537
- onChange: handleChange,
538
- "aria-describedby": "name-helper-text",
539
- label: "Name"
540
- }
541
- ),
542
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.name && Boolean(errors.name) ? errors.name : "Name of this role" })
543
- ] }),
544
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
545
- /* @__PURE__ */ jsxRuntime.jsx(
546
- ui.TextField,
547
- {
548
- name: "id",
549
- required: true,
550
- error: touched.id && Boolean(errors.id),
551
- value: values.id,
552
- disabled: !isNewRole || !editable,
553
- onChange: (e) => {
554
- handleChange(e);
555
- setFieldTouched("id", true);
556
- },
557
- "aria-describedby": "id-helper-text",
558
- label: "ID"
559
- }
560
- ),
561
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.id && Boolean(errors.id) ? errors.id : "ID of this role" })
562
- ] }),
563
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Paper, { className: "bg-inherit overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full rounded-md", children: [
565
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { className: "rounded-md", children: [
566
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, {}),
567
- /* @__PURE__ */ jsxRuntime.jsx(
568
- ui.TableCell,
569
- {
570
- align: "center",
571
- children: "Create entities"
572
- }
573
- ),
574
- /* @__PURE__ */ jsxRuntime.jsx(
575
- ui.TableCell,
576
- {
577
- align: "center",
578
- children: "Read entities"
579
- }
580
- ),
581
- /* @__PURE__ */ jsxRuntime.jsx(
582
- ui.TableCell,
583
- {
584
- align: "center",
585
- children: "Update entities"
586
- }
587
- ),
588
- /* @__PURE__ */ jsxRuntime.jsx(
589
- ui.TableCell,
590
- {
591
- align: "center",
592
- children: "Delete entities"
593
- }
594
- ),
595
- /* @__PURE__ */ jsxRuntime.jsx(
596
- ui.TableCell,
597
- {
598
- align: "center"
599
- }
600
- )
601
- ] }),
602
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
603
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
604
- /* @__PURE__ */ jsxRuntime.jsx(
605
- ui.TableCell,
606
- {
607
- scope: "row",
608
- children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "All collections" })
609
- }
610
- ),
611
- /* @__PURE__ */ jsxRuntime.jsx(
612
- ui.TableCell,
613
- {
614
- align: "center",
615
- children: /* @__PURE__ */ jsxRuntime.jsx(
616
- ui.Tooltip,
617
- {
618
- title: "Create entities in collections",
619
- children: /* @__PURE__ */ jsxRuntime.jsx(
620
- ui.Checkbox,
621
- {
622
- disabled: isAdmin || !editable,
623
- checked: (isAdmin || defaultCreate) ?? false,
624
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.create", checked)
625
- }
626
- )
627
- }
628
- )
629
- }
630
- ),
631
- /* @__PURE__ */ jsxRuntime.jsx(
632
- ui.TableCell,
633
- {
634
- align: "center",
635
- children: /* @__PURE__ */ jsxRuntime.jsx(
636
- ui.Tooltip,
637
- {
638
- title: "Access all data in every collection",
639
- children: /* @__PURE__ */ jsxRuntime.jsx(
640
- ui.Checkbox,
641
- {
642
- disabled: isAdmin || !editable,
643
- checked: (isAdmin || defaultRead) ?? false,
644
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.read", checked)
645
- }
646
- )
647
- }
648
- )
649
- }
650
- ),
651
- /* @__PURE__ */ jsxRuntime.jsx(
652
- ui.TableCell,
653
- {
654
- align: "center",
655
- children: /* @__PURE__ */ jsxRuntime.jsx(
656
- ui.Tooltip,
657
- {
658
- title: "Update data in any collection",
659
- children: /* @__PURE__ */ jsxRuntime.jsx(
660
- ui.Checkbox,
661
- {
662
- disabled: isAdmin || !editable,
663
- checked: (isAdmin || defaultEdit) ?? false,
664
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.edit", checked)
665
- }
666
- )
667
- }
668
- )
669
- }
670
- ),
671
- /* @__PURE__ */ jsxRuntime.jsx(
672
- ui.TableCell,
673
- {
674
- align: "center",
675
- children: /* @__PURE__ */ jsxRuntime.jsx(
676
- ui.Tooltip,
677
- {
678
- title: "Delete data in any collection",
679
- children: /* @__PURE__ */ jsxRuntime.jsx(
680
- ui.Checkbox,
681
- {
682
- disabled: isAdmin || !editable,
683
- checked: (isAdmin || defaultDelete) ?? false,
684
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.delete", checked)
685
- }
686
- )
687
- }
688
- )
689
- }
690
- ),
691
- /* @__PURE__ */ jsxRuntime.jsx(
692
- ui.TableCell,
693
- {
694
- align: "center"
695
- }
696
- )
697
- ] }),
698
- collections && collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
699
- /* @__PURE__ */ jsxRuntime.jsx(
700
- ui.TableCell,
701
- {
702
- scope: "row",
703
- children: col.name
704
- }
705
- ),
706
- /* @__PURE__ */ jsxRuntime.jsx(
707
- ui.TableCell,
708
- {
709
- align: "center",
710
- children: /* @__PURE__ */ jsxRuntime.jsx(
711
- ui.Checkbox,
712
- {
713
- disabled: isAdmin || defaultCreate || !editable,
714
- checked: (isAdmin || defaultCreate || formex.getIn(values, `collectionPermissions.${col.id}.create`)) ?? false,
715
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.create`, checked)
716
- }
717
- )
718
- }
719
- ),
720
- /* @__PURE__ */ jsxRuntime.jsx(
721
- ui.TableCell,
722
- {
723
- align: "center",
724
- children: /* @__PURE__ */ jsxRuntime.jsx(
725
- ui.Checkbox,
726
- {
727
- disabled: isAdmin || defaultRead || !editable,
728
- checked: (isAdmin || defaultRead || formex.getIn(values, `collectionPermissions.${col.id}.read`)) ?? false,
729
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.read`, checked)
730
- }
731
- )
732
- }
733
- ),
734
- /* @__PURE__ */ jsxRuntime.jsx(
735
- ui.TableCell,
736
- {
737
- align: "center",
738
- children: /* @__PURE__ */ jsxRuntime.jsx(
739
- ui.Checkbox,
740
- {
741
- disabled: isAdmin || defaultEdit || !editable,
742
- checked: (isAdmin || defaultEdit || formex.getIn(values, `collectionPermissions.${col.id}.edit`)) ?? false,
743
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.edit`, checked)
744
- }
745
- )
746
- }
747
- ),
748
- /* @__PURE__ */ jsxRuntime.jsx(
749
- ui.TableCell,
750
- {
751
- align: "center",
752
- children: /* @__PURE__ */ jsxRuntime.jsx(
753
- ui.Checkbox,
754
- {
755
- disabled: isAdmin || defaultDelete || !editable,
756
- checked: (isAdmin || defaultDelete || formex.getIn(values, `collectionPermissions.${col.id}.delete`)) ?? false,
757
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.delete`, checked)
758
- }
759
- )
760
- }
761
- ),
762
- /* @__PURE__ */ jsxRuntime.jsx(
763
- ui.TableCell,
764
- {
765
- align: "center",
766
- children: /* @__PURE__ */ jsxRuntime.jsx(
767
- ui.Tooltip,
768
- {
769
- title: "Allow all permissions in this collections",
770
- children: /* @__PURE__ */ jsxRuntime.jsx(
771
- ui.Button,
772
- {
773
- className: "color-inherit",
774
- onClick: () => {
775
- setFieldValue(`collectionPermissions.${col.id}.create`, true);
776
- setFieldValue(`collectionPermissions.${col.id}.read`, true);
777
- setFieldValue(`collectionPermissions.${col.id}.edit`, true);
778
- setFieldValue(`collectionPermissions.${col.id}.delete`, true);
779
- },
780
- disabled: isAdmin || !editable,
781
- variant: "text",
782
- children: "All"
783
- }
784
- )
785
- }
786
- )
787
- }
788
- )
789
- ] }, col.name))
790
- ] })
791
- ] }) }),
792
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: "You can customise the permissions that the users related to this role can perform in the entities of each collection" })
793
- ] }),
794
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
795
- /* @__PURE__ */ jsxRuntime.jsxs(
796
- ui.Select,
797
- {
798
- error: touched.config && Boolean(errors.config),
799
- size: "large",
800
- id: "createCollections",
801
- name: "createCollections",
802
- label: "Create collections",
803
- position: "item-aligned",
804
- disabled: isAdmin || !editable,
805
- onChange: (event) => setFieldValue("config.createCollections", event.target.value === "true"),
806
- value: isAdmin || values.config?.createCollections ? "true" : "false",
807
- renderValue: (value) => value === "true" ? "Yes" : "No",
808
- children: [
809
- /* @__PURE__ */ jsxRuntime.jsx(
810
- ui.SelectItem,
811
- {
812
- value: "true",
813
- children: " Yes "
814
- }
815
- ),
816
- /* @__PURE__ */ jsxRuntime.jsx(
817
- ui.SelectItem,
818
- {
819
- value: "false",
820
- children: " No "
821
- }
822
- )
823
- ]
824
- }
825
- ),
826
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user create collections" })
827
- ] }),
828
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
829
- /* @__PURE__ */ jsxRuntime.jsxs(
830
- ui.Select,
831
- {
832
- size: "large",
833
- error: touched.config && Boolean(errors.config),
834
- id: "editCollections",
835
- name: "editCollections",
836
- label: "Edit collections",
837
- disabled: isAdmin || !editable,
838
- position: "item-aligned",
839
- onChange: (event) => setFieldValue("config.editCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
840
- value: isAdmin ? "true" : values.config?.editCollections === "own" ? "own" : values.config?.editCollections ? "true" : "false",
841
- renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
842
- children: [
843
- /* @__PURE__ */ jsxRuntime.jsx(
844
- ui.SelectItem,
845
- {
846
- value: "true",
847
- children: " Yes "
848
- }
849
- ),
850
- /* @__PURE__ */ jsxRuntime.jsx(
851
- ui.SelectItem,
852
- {
853
- value: "false",
854
- children: " No "
855
- }
856
- ),
857
- /* @__PURE__ */ jsxRuntime.jsx(
858
- ui.SelectItem,
859
- {
860
- value: "own",
861
- children: " Only his/her own "
862
- }
863
- )
864
- ]
865
- }
866
- ),
867
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user edit collections" })
868
- ] }),
869
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
870
- /* @__PURE__ */ jsxRuntime.jsxs(
871
- ui.Select,
872
- {
873
- size: "large",
874
- error: touched.config && Boolean(errors.config),
875
- id: "deleteCollections",
876
- name: "deleteCollections",
877
- label: "Delete collections",
878
- disabled: isAdmin || !editable,
879
- position: "item-aligned",
880
- onChange: (event) => setFieldValue("config.deleteCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
881
- value: isAdmin ? "true" : values.config?.deleteCollections === "own" ? "own" : values.config?.deleteCollections ? "true" : "false",
882
- renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
883
- children: [
884
- /* @__PURE__ */ jsxRuntime.jsx(
885
- ui.SelectItem,
886
- {
887
- value: "true",
888
- children: " Yes "
889
- }
890
- ),
891
- /* @__PURE__ */ jsxRuntime.jsx(
892
- ui.SelectItem,
893
- {
894
- value: "false",
895
- children: " No "
896
- }
897
- ),
898
- /* @__PURE__ */ jsxRuntime.jsx(
899
- ui.SelectItem,
900
- {
901
- value: "own",
902
- children: " Only his/her own "
903
- }
904
- )
905
- ]
906
- }
907
- ),
908
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user delete collections" })
909
- ] })
910
- ] })
911
- ] }),
912
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { position: "sticky", children: [
913
- savingError && /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { className: "text-red-500 dark:text-red-500", children: savingError.message ?? "There was an error saving this role" }),
914
- /* @__PURE__ */ jsxRuntime.jsx(
915
- ui.Button,
916
- {
917
- variant: "text",
918
- onClick: () => {
919
- handleClose();
920
- },
921
- children: "Cancel"
922
- }
923
- ),
924
- /* @__PURE__ */ jsxRuntime.jsx(
925
- ui.LoadingButton,
926
- {
927
- variant: "filled",
928
- color: "primary",
929
- type: "submit",
930
- disabled: !dirty,
931
- loading: isSubmitting,
932
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
933
- children: isNewRole ? "Create role" : "Update"
934
- }
935
- )
936
- ] })
937
- ]
938
- }
939
- ) })
940
- }
941
- );
564
+ const isAdmin = values_0.isAdmin ?? false;
565
+ const defaultCreate = values_0.defaultPermissions?.create ?? false;
566
+ const defaultRead = values_0.defaultPermissions?.read ?? false;
567
+ const defaultEdit = values_0.defaultPermissions?.edit ?? false;
568
+ const defaultDelete = values_0.defaultPermissions?.delete ?? false;
569
+ let t5;
570
+ if ($[11] !== setFieldValue || $[12] !== touched || $[13] !== values_0.name) {
571
+ t5 = () => {
572
+ const idTouched = formex.getIn(touched, "id");
573
+ if (!idTouched && values_0.name) {
574
+ setFieldValue("id", core.toSnakeCase(values_0.name));
575
+ }
576
+ };
577
+ $[11] = setFieldValue;
578
+ $[12] = touched;
579
+ $[13] = values_0.name;
580
+ $[14] = t5;
581
+ } else {
582
+ t5 = $[14];
583
+ }
584
+ let t6;
585
+ if ($[15] !== touched || $[16] !== values_0.name) {
586
+ t6 = [touched, values_0.name];
587
+ $[15] = touched;
588
+ $[16] = values_0.name;
589
+ $[17] = t6;
590
+ } else {
591
+ t6 = $[17];
592
+ }
593
+ React.useEffect(t5, t6);
594
+ let t7;
595
+ let t8;
596
+ if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
597
+ t7 = {
598
+ display: "flex",
599
+ flexDirection: "column",
600
+ position: "relative",
601
+ height: "100%"
602
+ };
603
+ t8 = /* @__PURE__ */ jsxRuntime.jsx(ui.DialogTitle, { variant: "h4", gutterBottom: false, children: "Role" });
604
+ $[18] = t7;
605
+ $[19] = t8;
606
+ } else {
607
+ t7 = $[18];
608
+ t8 = $[19];
609
+ }
610
+ const t9 = touched.name && Boolean(errors_0.name);
611
+ const t10 = isAdmin || !editable;
612
+ let t11;
613
+ if ($[20] !== handleChange || $[21] !== t10 || $[22] !== t9 || $[23] !== values_0.name) {
614
+ t11 = /* @__PURE__ */ jsxRuntime.jsx(ui.TextField, { name: "name", required: true, error: t9, value: values_0.name, disabled: t10, onChange: handleChange, "aria-describedby": "name-helper-text", label: "Name" });
615
+ $[20] = handleChange;
616
+ $[21] = t10;
617
+ $[22] = t9;
618
+ $[23] = values_0.name;
619
+ $[24] = t11;
620
+ } else {
621
+ t11 = $[24];
622
+ }
623
+ const t12 = touched.name && Boolean(errors_0.name) ? errors_0.name : "Name of this role";
624
+ let t13;
625
+ if ($[25] !== t12) {
626
+ t13 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t12 });
627
+ $[25] = t12;
628
+ $[26] = t13;
629
+ } else {
630
+ t13 = $[26];
631
+ }
632
+ let t14;
633
+ if ($[27] !== t11 || $[28] !== t13) {
634
+ t14 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-8", children: [
635
+ t11,
636
+ t13
637
+ ] });
638
+ $[27] = t11;
639
+ $[28] = t13;
640
+ $[29] = t14;
641
+ } else {
642
+ t14 = $[29];
643
+ }
644
+ const t15 = touched.id && Boolean(errors_0.id);
645
+ const t16 = !isNewRole || !editable;
646
+ let t17;
647
+ if ($[30] !== handleChange || $[31] !== setFieldTouched) {
648
+ t17 = (e_2) => {
649
+ handleChange(e_2);
650
+ setFieldTouched("id", true);
651
+ };
652
+ $[30] = handleChange;
653
+ $[31] = setFieldTouched;
654
+ $[32] = t17;
655
+ } else {
656
+ t17 = $[32];
657
+ }
658
+ let t18;
659
+ if ($[33] !== t15 || $[34] !== t16 || $[35] !== t17 || $[36] !== values_0.id) {
660
+ t18 = /* @__PURE__ */ jsxRuntime.jsx(ui.TextField, { name: "id", required: true, error: t15, value: values_0.id, disabled: t16, onChange: t17, "aria-describedby": "id-helper-text", label: "ID" });
661
+ $[33] = t15;
662
+ $[34] = t16;
663
+ $[35] = t17;
664
+ $[36] = values_0.id;
665
+ $[37] = t18;
666
+ } else {
667
+ t18 = $[37];
668
+ }
669
+ const t19 = touched.id && Boolean(errors_0.id) ? errors_0.id : "ID of this role";
670
+ let t20;
671
+ if ($[38] !== t19) {
672
+ t20 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t19 });
673
+ $[38] = t19;
674
+ $[39] = t20;
675
+ } else {
676
+ t20 = $[39];
677
+ }
678
+ let t21;
679
+ if ($[40] !== t18 || $[41] !== t20) {
680
+ t21 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
681
+ t18,
682
+ t20
683
+ ] });
684
+ $[40] = t18;
685
+ $[41] = t20;
686
+ $[42] = t21;
687
+ } else {
688
+ t21 = $[42];
689
+ }
690
+ let t22;
691
+ if ($[43] === Symbol.for("react.memo_cache_sentinel")) {
692
+ t22 = /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { className: "rounded-md", children: [
693
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, {}),
694
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: "Create entities" }),
695
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: "Read entities" }),
696
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: "Update entities" }),
697
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: "Delete entities" }),
698
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center" })
699
+ ] });
700
+ $[43] = t22;
701
+ } else {
702
+ t22 = $[43];
703
+ }
704
+ let t23;
705
+ if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
706
+ t23 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { scope: "row", children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "All collections" }) });
707
+ $[44] = t23;
708
+ } else {
709
+ t23 = $[44];
710
+ }
711
+ const t24 = isAdmin || !editable;
712
+ const t25 = (isAdmin || defaultCreate) ?? false;
713
+ let t26;
714
+ if ($[45] !== setFieldValue) {
715
+ t26 = (checked) => setFieldValue("defaultPermissions.create", checked);
716
+ $[45] = setFieldValue;
717
+ $[46] = t26;
718
+ } else {
719
+ t26 = $[46];
720
+ }
721
+ let t27;
722
+ if ($[47] !== t24 || $[48] !== t25 || $[49] !== t26) {
723
+ t27 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Create entities in collections", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: t24, checked: t25, onCheckedChange: t26 }) }) });
724
+ $[47] = t24;
725
+ $[48] = t25;
726
+ $[49] = t26;
727
+ $[50] = t27;
728
+ } else {
729
+ t27 = $[50];
730
+ }
731
+ const t28 = isAdmin || !editable;
732
+ const t29 = (isAdmin || defaultRead) ?? false;
733
+ let t30;
734
+ if ($[51] !== setFieldValue) {
735
+ t30 = (checked_0) => setFieldValue("defaultPermissions.read", checked_0);
736
+ $[51] = setFieldValue;
737
+ $[52] = t30;
738
+ } else {
739
+ t30 = $[52];
740
+ }
741
+ let t31;
742
+ if ($[53] !== t28 || $[54] !== t29 || $[55] !== t30) {
743
+ t31 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Access all data in every collection", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: t28, checked: t29, onCheckedChange: t30 }) }) });
744
+ $[53] = t28;
745
+ $[54] = t29;
746
+ $[55] = t30;
747
+ $[56] = t31;
748
+ } else {
749
+ t31 = $[56];
750
+ }
751
+ const t32 = isAdmin || !editable;
752
+ const t33 = (isAdmin || defaultEdit) ?? false;
753
+ let t34;
754
+ if ($[57] !== setFieldValue) {
755
+ t34 = (checked_1) => setFieldValue("defaultPermissions.edit", checked_1);
756
+ $[57] = setFieldValue;
757
+ $[58] = t34;
758
+ } else {
759
+ t34 = $[58];
760
+ }
761
+ let t35;
762
+ if ($[59] !== t32 || $[60] !== t33 || $[61] !== t34) {
763
+ t35 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Update data in any collection", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: t32, checked: t33, onCheckedChange: t34 }) }) });
764
+ $[59] = t32;
765
+ $[60] = t33;
766
+ $[61] = t34;
767
+ $[62] = t35;
768
+ } else {
769
+ t35 = $[62];
770
+ }
771
+ const t36 = isAdmin || !editable;
772
+ const t37 = (isAdmin || defaultDelete) ?? false;
773
+ let t38;
774
+ if ($[63] !== setFieldValue) {
775
+ t38 = (checked_2) => setFieldValue("defaultPermissions.delete", checked_2);
776
+ $[63] = setFieldValue;
777
+ $[64] = t38;
778
+ } else {
779
+ t38 = $[64];
780
+ }
781
+ let t39;
782
+ if ($[65] !== t36 || $[66] !== t37 || $[67] !== t38) {
783
+ t39 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Delete data in any collection", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: t36, checked: t37, onCheckedChange: t38 }) }) });
784
+ $[65] = t36;
785
+ $[66] = t37;
786
+ $[67] = t38;
787
+ $[68] = t39;
788
+ } else {
789
+ t39 = $[68];
790
+ }
791
+ let t40;
792
+ if ($[69] === Symbol.for("react.memo_cache_sentinel")) {
793
+ t40 = /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center" });
794
+ $[69] = t40;
795
+ } else {
796
+ t40 = $[69];
797
+ }
798
+ let t41;
799
+ if ($[70] !== t27 || $[71] !== t31 || $[72] !== t35 || $[73] !== t39) {
800
+ t41 = /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
801
+ t23,
802
+ t27,
803
+ t31,
804
+ t35,
805
+ t39,
806
+ t40
807
+ ] });
808
+ $[70] = t27;
809
+ $[71] = t31;
810
+ $[72] = t35;
811
+ $[73] = t39;
812
+ $[74] = t41;
813
+ } else {
814
+ t41 = $[74];
815
+ }
816
+ let t42;
817
+ if ($[75] !== collections || $[76] !== defaultCreate || $[77] !== defaultDelete || $[78] !== defaultEdit || $[79] !== defaultRead || $[80] !== editable || $[81] !== isAdmin || $[82] !== setFieldValue || $[83] !== values_0) {
818
+ t42 = collections && collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
819
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { scope: "row", children: col.name }),
820
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: isAdmin || defaultCreate || !editable, checked: (isAdmin || defaultCreate || formex.getIn(values_0, `collectionPermissions.${col.id}.create`)) ?? false, onCheckedChange: (checked_3) => setFieldValue(`collectionPermissions.${col.id}.create`, checked_3) }) }),
821
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: isAdmin || defaultRead || !editable, checked: (isAdmin || defaultRead || formex.getIn(values_0, `collectionPermissions.${col.id}.read`)) ?? false, onCheckedChange: (checked_4) => setFieldValue(`collectionPermissions.${col.id}.read`, checked_4) }) }),
822
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: isAdmin || defaultEdit || !editable, checked: (isAdmin || defaultEdit || formex.getIn(values_0, `collectionPermissions.${col.id}.edit`)) ?? false, onCheckedChange: (checked_5) => setFieldValue(`collectionPermissions.${col.id}.edit`, checked_5) }) }),
823
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { disabled: isAdmin || defaultDelete || !editable, checked: (isAdmin || defaultDelete || formex.getIn(values_0, `collectionPermissions.${col.id}.delete`)) ?? false, onCheckedChange: (checked_6) => setFieldValue(`collectionPermissions.${col.id}.delete`, checked_6) }) }),
824
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { align: "center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { title: "Allow all permissions in this collections", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { className: "color-inherit", onClick: () => {
825
+ setFieldValue(`collectionPermissions.${col.id}.create`, true);
826
+ setFieldValue(`collectionPermissions.${col.id}.read`, true);
827
+ setFieldValue(`collectionPermissions.${col.id}.edit`, true);
828
+ setFieldValue(`collectionPermissions.${col.id}.delete`, true);
829
+ }, disabled: isAdmin || !editable, variant: "text", children: "All" }) }) })
830
+ ] }, col.name));
831
+ $[75] = collections;
832
+ $[76] = defaultCreate;
833
+ $[77] = defaultDelete;
834
+ $[78] = defaultEdit;
835
+ $[79] = defaultRead;
836
+ $[80] = editable;
837
+ $[81] = isAdmin;
838
+ $[82] = setFieldValue;
839
+ $[83] = values_0;
840
+ $[84] = t42;
841
+ } else {
842
+ t42 = $[84];
843
+ }
844
+ let t43;
845
+ if ($[85] !== t41 || $[86] !== t42) {
846
+ t43 = /* @__PURE__ */ jsxRuntime.jsx(ui.Paper, { className: "bg-inherit overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full rounded-md", children: [
847
+ t22,
848
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
849
+ t41,
850
+ t42
851
+ ] })
852
+ ] }) });
853
+ $[85] = t41;
854
+ $[86] = t42;
855
+ $[87] = t43;
856
+ } else {
857
+ t43 = $[87];
858
+ }
859
+ let t44;
860
+ if ($[88] === Symbol.for("react.memo_cache_sentinel")) {
861
+ t44 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: "You can customise the permissions that the users related to this role can perform in the entities of each collection" });
862
+ $[88] = t44;
863
+ } else {
864
+ t44 = $[88];
865
+ }
866
+ let t45;
867
+ if ($[89] !== t43) {
868
+ t45 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
869
+ t43,
870
+ t44
871
+ ] });
872
+ $[89] = t43;
873
+ $[90] = t45;
874
+ } else {
875
+ t45 = $[90];
876
+ }
877
+ const t46 = touched.config && Boolean(errors_0.config);
878
+ const t47 = isAdmin || !editable;
879
+ let t48;
880
+ if ($[91] !== setFieldValue) {
881
+ t48 = (event) => setFieldValue("config.createCollections", event.target.value === "true");
882
+ $[91] = setFieldValue;
883
+ $[92] = t48;
884
+ } else {
885
+ t48 = $[92];
886
+ }
887
+ const t49 = isAdmin || values_0.config?.createCollections ? "true" : "false";
888
+ let t50;
889
+ let t51;
890
+ if ($[93] === Symbol.for("react.memo_cache_sentinel")) {
891
+ t50 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "true", children: " Yes " });
892
+ t51 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "false", children: " No " });
893
+ $[93] = t50;
894
+ $[94] = t51;
895
+ } else {
896
+ t50 = $[93];
897
+ t51 = $[94];
898
+ }
899
+ let t52;
900
+ if ($[95] !== t46 || $[96] !== t47 || $[97] !== t48 || $[98] !== t49) {
901
+ t52 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { error: t46, size: "large", fullWidth: true, id: "createCollections", name: "createCollections", label: "Create collections", position: "item-aligned", disabled: t47, onChange: t48, value: t49, renderValue: _temp4$1, children: [
902
+ t50,
903
+ t51
904
+ ] });
905
+ $[95] = t46;
906
+ $[96] = t47;
907
+ $[97] = t48;
908
+ $[98] = t49;
909
+ $[99] = t52;
910
+ } else {
911
+ t52 = $[99];
912
+ }
913
+ const t53 = touched.config && Boolean(errors_0.config) ? errors_0.config : "Can the user create collections";
914
+ let t54;
915
+ if ($[100] !== t53) {
916
+ t54 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t53 });
917
+ $[100] = t53;
918
+ $[101] = t54;
919
+ } else {
920
+ t54 = $[101];
921
+ }
922
+ let t55;
923
+ if ($[102] !== t52 || $[103] !== t54) {
924
+ t55 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
925
+ t52,
926
+ t54
927
+ ] });
928
+ $[102] = t52;
929
+ $[103] = t54;
930
+ $[104] = t55;
931
+ } else {
932
+ t55 = $[104];
933
+ }
934
+ const t56 = touched.config && Boolean(errors_0.config);
935
+ const t57 = isAdmin || !editable;
936
+ let t58;
937
+ if ($[105] !== setFieldValue) {
938
+ t58 = (event_0) => setFieldValue("config.editCollections", event_0.target.value === "own" ? "own" : event_0.target.value === "true");
939
+ $[105] = setFieldValue;
940
+ $[106] = t58;
941
+ } else {
942
+ t58 = $[106];
943
+ }
944
+ const t59 = isAdmin ? "true" : values_0.config?.editCollections === "own" ? "own" : values_0.config?.editCollections ? "true" : "false";
945
+ let t60;
946
+ let t61;
947
+ let t62;
948
+ if ($[107] === Symbol.for("react.memo_cache_sentinel")) {
949
+ t60 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "true", children: " Yes " });
950
+ t61 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "false", children: " No " });
951
+ t62 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "own", children: " Only his/her own " });
952
+ $[107] = t60;
953
+ $[108] = t61;
954
+ $[109] = t62;
955
+ } else {
956
+ t60 = $[107];
957
+ t61 = $[108];
958
+ t62 = $[109];
959
+ }
960
+ let t63;
961
+ if ($[110] !== t56 || $[111] !== t57 || $[112] !== t58 || $[113] !== t59) {
962
+ t63 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { size: "large", fullWidth: true, error: t56, id: "editCollections", name: "editCollections", label: "Edit collections", disabled: t57, position: "item-aligned", onChange: t58, value: t59, renderValue: _temp5$1, children: [
963
+ t60,
964
+ t61,
965
+ t62
966
+ ] });
967
+ $[110] = t56;
968
+ $[111] = t57;
969
+ $[112] = t58;
970
+ $[113] = t59;
971
+ $[114] = t63;
972
+ } else {
973
+ t63 = $[114];
974
+ }
975
+ const t64 = touched.config && Boolean(errors_0.config) ? errors_0.config : "Can the user edit collections";
976
+ let t65;
977
+ if ($[115] !== t64) {
978
+ t65 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t64 });
979
+ $[115] = t64;
980
+ $[116] = t65;
981
+ } else {
982
+ t65 = $[116];
983
+ }
984
+ let t66;
985
+ if ($[117] !== t63 || $[118] !== t65) {
986
+ t66 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
987
+ t63,
988
+ t65
989
+ ] });
990
+ $[117] = t63;
991
+ $[118] = t65;
992
+ $[119] = t66;
993
+ } else {
994
+ t66 = $[119];
995
+ }
996
+ const t67 = touched.config && Boolean(errors_0.config);
997
+ const t68 = isAdmin || !editable;
998
+ let t69;
999
+ if ($[120] !== setFieldValue) {
1000
+ t69 = (event_1) => setFieldValue("config.deleteCollections", event_1.target.value === "own" ? "own" : event_1.target.value === "true");
1001
+ $[120] = setFieldValue;
1002
+ $[121] = t69;
1003
+ } else {
1004
+ t69 = $[121];
1005
+ }
1006
+ const t70 = isAdmin ? "true" : values_0.config?.deleteCollections === "own" ? "own" : values_0.config?.deleteCollections ? "true" : "false";
1007
+ let t71;
1008
+ let t72;
1009
+ let t73;
1010
+ if ($[122] === Symbol.for("react.memo_cache_sentinel")) {
1011
+ t71 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "true", children: " Yes " });
1012
+ t72 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "false", children: " No " });
1013
+ t73 = /* @__PURE__ */ jsxRuntime.jsx(ui.SelectItem, { value: "own", children: " Only his/her own " });
1014
+ $[122] = t71;
1015
+ $[123] = t72;
1016
+ $[124] = t73;
1017
+ } else {
1018
+ t71 = $[122];
1019
+ t72 = $[123];
1020
+ t73 = $[124];
1021
+ }
1022
+ let t74;
1023
+ if ($[125] !== t67 || $[126] !== t68 || $[127] !== t69 || $[128] !== t70) {
1024
+ t74 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { size: "large", fullWidth: true, error: t67, id: "deleteCollections", name: "deleteCollections", label: "Delete collections", disabled: t68, position: "item-aligned", onChange: t69, value: t70, renderValue: _temp6$1, children: [
1025
+ t71,
1026
+ t72,
1027
+ t73
1028
+ ] });
1029
+ $[125] = t67;
1030
+ $[126] = t68;
1031
+ $[127] = t69;
1032
+ $[128] = t70;
1033
+ $[129] = t74;
1034
+ } else {
1035
+ t74 = $[129];
1036
+ }
1037
+ const t75 = touched.config && Boolean(errors_0.config) ? errors_0.config : "Can the user delete collections";
1038
+ let t76;
1039
+ if ($[130] !== t75) {
1040
+ t76 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t75 });
1041
+ $[130] = t75;
1042
+ $[131] = t76;
1043
+ } else {
1044
+ t76 = $[131];
1045
+ }
1046
+ let t77;
1047
+ if ($[132] !== t74 || $[133] !== t76) {
1048
+ t77 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
1049
+ t74,
1050
+ t76
1051
+ ] });
1052
+ $[132] = t74;
1053
+ $[133] = t76;
1054
+ $[134] = t77;
1055
+ } else {
1056
+ t77 = $[134];
1057
+ }
1058
+ let t78;
1059
+ if ($[135] !== t14 || $[136] !== t21 || $[137] !== t45 || $[138] !== t55 || $[139] !== t66 || $[140] !== t77) {
1060
+ t78 = /* @__PURE__ */ jsxRuntime.jsx(ui.DialogContent, { className: "flex-grow", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
1061
+ t14,
1062
+ t21,
1063
+ t45,
1064
+ t55,
1065
+ t66,
1066
+ t77
1067
+ ] }) });
1068
+ $[135] = t14;
1069
+ $[136] = t21;
1070
+ $[137] = t45;
1071
+ $[138] = t55;
1072
+ $[139] = t66;
1073
+ $[140] = t77;
1074
+ $[141] = t78;
1075
+ } else {
1076
+ t78 = $[141];
1077
+ }
1078
+ let t79;
1079
+ if ($[142] !== savingError) {
1080
+ t79 = savingError && /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { className: "text-red-500 dark:text-red-500", children: savingError.message ?? "There was an error saving this role" });
1081
+ $[142] = savingError;
1082
+ $[143] = t79;
1083
+ } else {
1084
+ t79 = $[143];
1085
+ }
1086
+ let t80;
1087
+ if ($[144] !== handleClose) {
1088
+ t80 = /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "text", onClick: () => {
1089
+ handleClose();
1090
+ }, children: "Cancel" });
1091
+ $[144] = handleClose;
1092
+ $[145] = t80;
1093
+ } else {
1094
+ t80 = $[145];
1095
+ }
1096
+ const t81 = !dirty;
1097
+ let t82;
1098
+ if ($[146] === Symbol.for("react.memo_cache_sentinel")) {
1099
+ t82 = /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {});
1100
+ $[146] = t82;
1101
+ } else {
1102
+ t82 = $[146];
1103
+ }
1104
+ const t83 = isNewRole ? "Create role" : "Update";
1105
+ let t84;
1106
+ if ($[147] !== isSubmitting || $[148] !== t81 || $[149] !== t83) {
1107
+ t84 = /* @__PURE__ */ jsxRuntime.jsx(ui.LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t81, loading: isSubmitting, startIcon: t82, children: t83 });
1108
+ $[147] = isSubmitting;
1109
+ $[148] = t81;
1110
+ $[149] = t83;
1111
+ $[150] = t84;
1112
+ } else {
1113
+ t84 = $[150];
1114
+ }
1115
+ let t85;
1116
+ if ($[151] !== t79 || $[152] !== t80 || $[153] !== t84) {
1117
+ t85 = /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { position: "sticky", children: [
1118
+ t79,
1119
+ t80,
1120
+ t84
1121
+ ] });
1122
+ $[151] = t79;
1123
+ $[152] = t80;
1124
+ $[153] = t84;
1125
+ $[154] = t85;
1126
+ } else {
1127
+ t85 = $[154];
1128
+ }
1129
+ let t86;
1130
+ if ($[155] !== formex$1.handleSubmit || $[156] !== t78 || $[157] !== t85) {
1131
+ t86 = /* @__PURE__ */ jsxRuntime.jsxs("form", { noValidate: true, autoComplete: "off", onSubmit: formex$1.handleSubmit, style: t7, children: [
1132
+ t8,
1133
+ t78,
1134
+ t85
1135
+ ] });
1136
+ $[155] = formex$1.handleSubmit;
1137
+ $[156] = t78;
1138
+ $[157] = t85;
1139
+ $[158] = t86;
1140
+ } else {
1141
+ t86 = $[158];
1142
+ }
1143
+ let t87;
1144
+ if ($[159] !== formex$1 || $[160] !== t86) {
1145
+ t87 = /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: t86 });
1146
+ $[159] = formex$1;
1147
+ $[160] = t86;
1148
+ $[161] = t87;
1149
+ } else {
1150
+ t87 = $[161];
1151
+ }
1152
+ let t88;
1153
+ if ($[162] !== open || $[163] !== t87) {
1154
+ t88 = /* @__PURE__ */ jsxRuntime.jsx(ui.Dialog, { open, maxWidth: "4xl", children: t87 });
1155
+ $[162] = open;
1156
+ $[163] = t87;
1157
+ $[164] = t88;
1158
+ } else {
1159
+ t88 = $[164];
1160
+ }
1161
+ return t88;
942
1162
  }
943
- const DEFAULT_ROLES = [
944
- {
945
- id: "admin",
946
- name: "Admin",
947
- isAdmin: true
948
- },
949
- {
950
- id: "editor",
951
- name: "Editor",
952
- isAdmin: false,
953
- defaultPermissions: {
954
- read: true,
955
- create: true,
956
- edit: true,
957
- delete: true
958
- },
959
- config: {
960
- createCollections: true,
961
- editCollections: "own",
962
- deleteCollections: "own"
963
- }
1163
+ function _temp6$1(value_1) {
1164
+ return value_1 === "own" ? "Own" : value_1 === "true" ? "Yes" : "No";
1165
+ }
1166
+ function _temp5$1(value_0) {
1167
+ return value_0 === "own" ? "Own" : value_0 === "true" ? "Yes" : "No";
1168
+ }
1169
+ function _temp4$1(value) {
1170
+ return value === "true" ? "Yes" : "No";
1171
+ }
1172
+ function _temp3$1(values) {
1173
+ return RoleYupSchema.validate(values, {
1174
+ abortEarly: false
1175
+ }).then(_temp$2).catch(_temp2$1);
1176
+ }
1177
+ function _temp2$1(e_1) {
1178
+ const errors = {};
1179
+ e_1.inner.forEach((error) => {
1180
+ errors[error.path] = error.message;
1181
+ });
1182
+ return errors;
1183
+ }
1184
+ function _temp$2() {
1185
+ return {};
1186
+ }
1187
+ const DEFAULT_ROLES = [{
1188
+ id: "admin",
1189
+ name: "Admin",
1190
+ isAdmin: true
1191
+ }, {
1192
+ id: "editor",
1193
+ name: "Editor",
1194
+ isAdmin: false,
1195
+ defaultPermissions: {
1196
+ read: true,
1197
+ create: true,
1198
+ edit: true,
1199
+ delete: true
964
1200
  },
965
- {
966
- id: "viewer",
967
- name: "Viewer",
968
- isAdmin: false,
969
- defaultPermissions: {
970
- read: true,
971
- create: false,
972
- edit: false,
973
- delete: false
974
- }
1201
+ config: {
1202
+ createCollections: true,
1203
+ editCollections: "own",
1204
+ deleteCollections: "own"
975
1205
  }
976
- ];
977
- function RolesTable({
978
- onRoleClicked,
979
- editable
980
- }) {
1206
+ }, {
1207
+ id: "viewer",
1208
+ name: "Viewer",
1209
+ isAdmin: false,
1210
+ defaultPermissions: {
1211
+ read: true,
1212
+ create: false,
1213
+ edit: false,
1214
+ delete: false
1215
+ }
1216
+ }];
1217
+ function RolesTable(t0) {
1218
+ const $ = reactCompilerRuntime.c(25);
1219
+ const {
1220
+ onRoleClicked,
1221
+ editable
1222
+ } = t0;
981
1223
  const {
982
1224
  roles,
983
1225
  saveRole,
@@ -986,166 +1228,258 @@
986
1228
  } = useUserManagement();
987
1229
  const [roleToBeDeleted, setRoleToBeDeleted] = React.useState(void 0);
988
1230
  const [deleteInProgress, setDeleteInProgress] = React.useState(false);
989
- return /* @__PURE__ */ jsxRuntime.jsxs(
990
- "div",
991
- {
992
- className: "w-full overflow-auto",
993
- children: [
994
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
995
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
996
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "w-16" }),
997
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Role" }),
998
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "items-center", children: "Is Admin" }),
999
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Default permissions" })
1000
- ] }),
1001
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
1002
- roles && roles.map((role) => {
1003
- const canCreateAll = role.isAdmin || role.defaultPermissions?.create;
1004
- const canReadAll = role.isAdmin || role.defaultPermissions?.read;
1005
- const canUpdateAll = role.isAdmin || role.defaultPermissions?.edit;
1006
- const canDeleteAll = role.isAdmin || role.defaultPermissions?.delete;
1007
- return /* @__PURE__ */ jsxRuntime.jsxs(
1008
- ui.TableRow,
1009
- {
1010
- onClick: () => {
1011
- onRoleClicked(role);
1012
- },
1013
- children: [
1014
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { style: { width: "64px" }, children: !role.isAdmin && /* @__PURE__ */ jsxRuntime.jsx(
1015
- ui.Tooltip,
1016
- {
1017
- asChild: true,
1018
- title: "Delete this role",
1019
- children: /* @__PURE__ */ jsxRuntime.jsx(
1020
- ui.IconButton,
1021
- {
1022
- size: "small",
1023
- disabled: !editable,
1024
- onClick: (event) => {
1025
- event.stopPropagation();
1026
- return setRoleToBeDeleted(role);
1027
- },
1028
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
1029
- }
1030
- )
1031
- }
1032
- ) }),
1033
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role }) }),
1034
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "items-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked: role.isAdmin ?? false }) }),
1035
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
1036
- canCreateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Create" }),
1037
- canReadAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Read" }),
1038
- canUpdateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Update" }),
1039
- canDeleteAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Delete" })
1040
- ] }) })
1041
- ]
1042
- },
1043
- role.name
1044
- );
1045
- }),
1046
- (!roles || roles.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1047
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "You don't have any roles yet." }),
1048
- allowDefaultRolesCreation && /* @__PURE__ */ jsxRuntime.jsx(
1049
- ui.Button,
1050
- {
1051
- variant: "outlined",
1052
- onClick: () => {
1053
- DEFAULT_ROLES.forEach((role) => {
1054
- saveRole(role);
1055
- });
1056
- },
1057
- children: "Create default roles"
1058
- }
1059
- )
1060
- ] }) }) })
1061
- ] })
1062
- ] }),
1063
- /* @__PURE__ */ jsxRuntime.jsx(
1064
- core.ConfirmationDialog,
1065
- {
1066
- open: Boolean(roleToBeDeleted),
1067
- loading: deleteInProgress,
1068
- onAccept: () => {
1069
- if (roleToBeDeleted) {
1070
- setDeleteInProgress(true);
1071
- deleteRole(roleToBeDeleted).then(() => {
1072
- setRoleToBeDeleted(void 0);
1073
- }).finally(() => {
1074
- setDeleteInProgress(false);
1075
- });
1076
- }
1077
- },
1078
- onCancel: () => {
1079
- setRoleToBeDeleted(void 0);
1080
- },
1081
- title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1082
- body: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this role?" })
1083
- }
1084
- )
1085
- ]
1086
- }
1087
- );
1231
+ let t1;
1232
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1233
+ t1 = /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
1234
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "w-16" }),
1235
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Role" }),
1236
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "items-center", children: "Is Admin" }),
1237
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Default permissions" })
1238
+ ] });
1239
+ $[0] = t1;
1240
+ } else {
1241
+ t1 = $[0];
1242
+ }
1243
+ let t2;
1244
+ if ($[1] !== editable || $[2] !== onRoleClicked || $[3] !== roles) {
1245
+ t2 = roles && roles.map((role) => {
1246
+ const canCreateAll = role.isAdmin || role.defaultPermissions?.create;
1247
+ const canReadAll = role.isAdmin || role.defaultPermissions?.read;
1248
+ const canUpdateAll = role.isAdmin || role.defaultPermissions?.edit;
1249
+ const canDeleteAll = role.isAdmin || role.defaultPermissions?.delete;
1250
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { onClick: () => {
1251
+ onRoleClicked(role);
1252
+ }, children: [
1253
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { style: {
1254
+ width: "64px"
1255
+ }, children: !role.isAdmin && /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { asChild: true, title: "Delete this role", children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", disabled: !editable, onClick: (event) => {
1256
+ event.stopPropagation();
1257
+ return setRoleToBeDeleted(role);
1258
+ }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {}) }) }) }),
1259
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role }) }),
1260
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "items-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked: role.isAdmin ?? false }) }),
1261
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
1262
+ canCreateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Create" }),
1263
+ canReadAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Read" }),
1264
+ canUpdateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Update" }),
1265
+ canDeleteAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Delete" })
1266
+ ] }) })
1267
+ ] }, role.name);
1268
+ });
1269
+ $[1] = editable;
1270
+ $[2] = onRoleClicked;
1271
+ $[3] = roles;
1272
+ $[4] = t2;
1273
+ } else {
1274
+ t2 = $[4];
1275
+ }
1276
+ let t3;
1277
+ if ($[5] !== allowDefaultRolesCreation || $[6] !== roles || $[7] !== saveRole) {
1278
+ t3 = (!roles || roles.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1279
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "You don't have any roles yet." }),
1280
+ allowDefaultRolesCreation && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "outlined", onClick: () => {
1281
+ DEFAULT_ROLES.forEach((role_0) => {
1282
+ saveRole(role_0);
1283
+ });
1284
+ }, children: "Create default roles" })
1285
+ ] }) }) });
1286
+ $[5] = allowDefaultRolesCreation;
1287
+ $[6] = roles;
1288
+ $[7] = saveRole;
1289
+ $[8] = t3;
1290
+ } else {
1291
+ t3 = $[8];
1292
+ }
1293
+ let t4;
1294
+ if ($[9] !== t2 || $[10] !== t3) {
1295
+ t4 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
1296
+ t1,
1297
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
1298
+ t2,
1299
+ t3
1300
+ ] })
1301
+ ] });
1302
+ $[9] = t2;
1303
+ $[10] = t3;
1304
+ $[11] = t4;
1305
+ } else {
1306
+ t4 = $[11];
1307
+ }
1308
+ const t5 = Boolean(roleToBeDeleted);
1309
+ let t6;
1310
+ if ($[12] !== deleteRole || $[13] !== roleToBeDeleted) {
1311
+ t6 = () => {
1312
+ if (roleToBeDeleted) {
1313
+ setDeleteInProgress(true);
1314
+ deleteRole(roleToBeDeleted).then(() => {
1315
+ setRoleToBeDeleted(void 0);
1316
+ }).finally(() => {
1317
+ setDeleteInProgress(false);
1318
+ });
1319
+ }
1320
+ };
1321
+ $[12] = deleteRole;
1322
+ $[13] = roleToBeDeleted;
1323
+ $[14] = t6;
1324
+ } else {
1325
+ t6 = $[14];
1326
+ }
1327
+ let t7;
1328
+ let t8;
1329
+ let t9;
1330
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
1331
+ t7 = () => {
1332
+ setRoleToBeDeleted(void 0);
1333
+ };
1334
+ t8 = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" });
1335
+ t9 = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this role?" });
1336
+ $[15] = t7;
1337
+ $[16] = t8;
1338
+ $[17] = t9;
1339
+ } else {
1340
+ t7 = $[15];
1341
+ t8 = $[16];
1342
+ t9 = $[17];
1343
+ }
1344
+ let t10;
1345
+ if ($[18] !== deleteInProgress || $[19] !== t5 || $[20] !== t6) {
1346
+ t10 = /* @__PURE__ */ jsxRuntime.jsx(core.ConfirmationDialog, { open: t5, loading: deleteInProgress, onAccept: t6, onCancel: t7, title: t8, body: t9 });
1347
+ $[18] = deleteInProgress;
1348
+ $[19] = t5;
1349
+ $[20] = t6;
1350
+ $[21] = t10;
1351
+ } else {
1352
+ t10 = $[21];
1353
+ }
1354
+ let t11;
1355
+ if ($[22] !== t10 || $[23] !== t4) {
1356
+ t11 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full overflow-auto", children: [
1357
+ t4,
1358
+ t10
1359
+ ] });
1360
+ $[22] = t10;
1361
+ $[23] = t4;
1362
+ $[24] = t11;
1363
+ } else {
1364
+ t11 = $[24];
1365
+ }
1366
+ return t11;
1088
1367
  }
1089
- const RolesView = React.memo(
1090
- function RolesView2({ children }) {
1091
- const { collections } = core.useNavigationController();
1092
- const [dialogOpen, setDialogOpen] = React.useState(false);
1093
- const [selectedRole, setSelectedRole] = React.useState();
1094
- const { canEditRoles } = useUserManagement();
1095
- const onRoleClicked = React.useCallback((user) => {
1368
+ const RolesView = React.memo(function RolesView2(t0) {
1369
+ const $ = reactCompilerRuntime.c(23);
1370
+ const {
1371
+ children
1372
+ } = t0;
1373
+ const {
1374
+ collections
1375
+ } = core.useNavigationController();
1376
+ const [dialogOpen, setDialogOpen] = React.useState(false);
1377
+ const [selectedRole, setSelectedRole] = React.useState();
1378
+ const {
1379
+ canEditRoles
1380
+ } = useUserManagement();
1381
+ let t1;
1382
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1383
+ t1 = (user) => {
1096
1384
  setDialogOpen(true);
1097
1385
  setSelectedRole(user);
1098
- }, []);
1099
- const handleClose = () => {
1386
+ };
1387
+ $[0] = t1;
1388
+ } else {
1389
+ t1 = $[0];
1390
+ }
1391
+ const onRoleClicked = t1;
1392
+ let t2;
1393
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
1394
+ t2 = () => {
1100
1395
  setSelectedRole(void 0);
1101
1396
  setDialogOpen(false);
1102
1397
  };
1103
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1398
+ $[1] = t2;
1399
+ } else {
1400
+ t2 = $[1];
1401
+ }
1402
+ const handleClose = t2;
1403
+ let t3;
1404
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
1405
+ t3 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { gutterBottom: true, variant: "h4", className: "flex-grow", component: "h4", children: "Roles" });
1406
+ $[2] = t3;
1407
+ } else {
1408
+ t3 = $[2];
1409
+ }
1410
+ const t4 = !canEditRoles ? "Update plans to customise roles" : void 0;
1411
+ const t5 = !canEditRoles;
1412
+ let t6;
1413
+ let t7;
1414
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
1415
+ t6 = /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {});
1416
+ t7 = () => setDialogOpen(true);
1417
+ $[3] = t6;
1418
+ $[4] = t7;
1419
+ } else {
1420
+ t6 = $[3];
1421
+ t7 = $[4];
1422
+ }
1423
+ let t8;
1424
+ if ($[5] !== t5) {
1425
+ t8 = /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "large", disabled: t5, startIcon: t6, onClick: t7, children: "Add role" });
1426
+ $[5] = t5;
1427
+ $[6] = t8;
1428
+ } else {
1429
+ t8 = $[6];
1430
+ }
1431
+ let t9;
1432
+ if ($[7] !== t4 || $[8] !== t8) {
1433
+ t9 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mt-12", children: [
1434
+ t3,
1435
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { asChild: true, title: t4, children: t8 })
1436
+ ] });
1437
+ $[7] = t4;
1438
+ $[8] = t8;
1439
+ $[9] = t9;
1440
+ } else {
1441
+ t9 = $[9];
1442
+ }
1443
+ const t10 = Boolean(canEditRoles);
1444
+ let t11;
1445
+ if ($[10] !== t10) {
1446
+ t11 = /* @__PURE__ */ jsxRuntime.jsx(RolesTable, { onRoleClicked, editable: t10 });
1447
+ $[10] = t10;
1448
+ $[11] = t11;
1449
+ } else {
1450
+ t11 = $[11];
1451
+ }
1452
+ const t12 = selectedRole?.id ?? "new";
1453
+ let t13;
1454
+ if ($[12] !== canEditRoles || $[13] !== collections || $[14] !== dialogOpen || $[15] !== selectedRole || $[16] !== t12) {
1455
+ t13 = /* @__PURE__ */ jsxRuntime.jsx(RolesDetailsForm, { open: dialogOpen, role: selectedRole, editable: canEditRoles, collections, handleClose }, t12);
1456
+ $[12] = canEditRoles;
1457
+ $[13] = collections;
1458
+ $[14] = dialogOpen;
1459
+ $[15] = selectedRole;
1460
+ $[16] = t12;
1461
+ $[17] = t13;
1462
+ } else {
1463
+ t13 = $[17];
1464
+ }
1465
+ let t14;
1466
+ if ($[18] !== children || $[19] !== t11 || $[20] !== t13 || $[21] !== t9) {
1467
+ t14 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1104
1468
  children,
1105
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mt-12", children: [
1106
- /* @__PURE__ */ jsxRuntime.jsx(
1107
- ui.Typography,
1108
- {
1109
- gutterBottom: true,
1110
- variant: "h4",
1111
- className: "flex-grow",
1112
- component: "h4",
1113
- children: "Roles"
1114
- }
1115
- ),
1116
- /* @__PURE__ */ jsxRuntime.jsx(
1117
- ui.Tooltip,
1118
- {
1119
- asChild: true,
1120
- title: !canEditRoles ? "Update plans to customise roles" : void 0,
1121
- children: /* @__PURE__ */ jsxRuntime.jsx(
1122
- ui.Button,
1123
- {
1124
- size: "large",
1125
- disabled: !canEditRoles,
1126
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1127
- onClick: () => setDialogOpen(true),
1128
- children: "Add role"
1129
- }
1130
- )
1131
- }
1132
- )
1133
- ] }),
1134
- /* @__PURE__ */ jsxRuntime.jsx(RolesTable, { onRoleClicked, editable: Boolean(canEditRoles) }),
1135
- /* @__PURE__ */ jsxRuntime.jsx(
1136
- RolesDetailsForm,
1137
- {
1138
- open: dialogOpen,
1139
- role: selectedRole,
1140
- editable: canEditRoles,
1141
- collections,
1142
- handleClose
1143
- },
1144
- selectedRole?.id ?? "new"
1145
- )
1469
+ t9,
1470
+ t11,
1471
+ t13
1146
1472
  ] });
1473
+ $[18] = children;
1474
+ $[19] = t11;
1475
+ $[20] = t13;
1476
+ $[21] = t9;
1477
+ $[22] = t14;
1478
+ } else {
1479
+ t14 = $[22];
1147
1480
  }
1148
- );
1481
+ return t14;
1482
+ });
1149
1483
  const UserYupSchema = Yup__namespace.object().shape({
1150
1484
  displayName: Yup__namespace.string().required("Required"),
1151
1485
  email: Yup__namespace.string().email().required("Required"),
@@ -1164,11 +1498,13 @@
1164
1498
  }
1165
1499
  return true;
1166
1500
  }
1167
- function UserDetailsForm({
1168
- open,
1169
- user: userProp,
1170
- handleClose
1171
- }) {
1501
+ function UserDetailsForm(t0) {
1502
+ const $ = reactCompilerRuntime.c(74);
1503
+ const {
1504
+ open,
1505
+ user: userProp,
1506
+ handleClose
1507
+ } = t0;
1172
1508
  const snackbarController = core.useSnackbarController();
1173
1509
  const {
1174
1510
  user: loggedInUser
@@ -1179,173 +1515,331 @@
1179
1515
  roles
1180
1516
  } = useUserManagement();
1181
1517
  const isNewUser = !userProp;
1182
- const onUserUpdated = React.useCallback((savedUser) => {
1183
- if (!loggedInUser) {
1184
- throw new Error("Logged user not found");
1185
- }
1186
- try {
1187
- canUserBeEdited(loggedInUser, savedUser, users, roles, userProp);
1188
- return saveUser(savedUser);
1189
- } catch (e) {
1190
- return Promise.reject(e);
1191
- }
1192
- }, [roles, saveUser, userProp, users, loggedInUser]);
1193
- const formex$1 = formex.useCreateFormex({
1194
- initialValues: userProp ?? {
1518
+ let t1;
1519
+ if ($[0] !== loggedInUser || $[1] !== roles || $[2] !== saveUser || $[3] !== userProp || $[4] !== users) {
1520
+ t1 = (savedUser) => {
1521
+ if (!loggedInUser) {
1522
+ throw new Error("Logged user not found");
1523
+ }
1524
+ try {
1525
+ canUserBeEdited(loggedInUser, savedUser, users, roles, userProp);
1526
+ return saveUser(savedUser);
1527
+ } catch (t210) {
1528
+ const e = t210;
1529
+ return Promise.reject(e);
1530
+ }
1531
+ };
1532
+ $[0] = loggedInUser;
1533
+ $[1] = roles;
1534
+ $[2] = saveUser;
1535
+ $[3] = userProp;
1536
+ $[4] = users;
1537
+ $[5] = t1;
1538
+ } else {
1539
+ t1 = $[5];
1540
+ }
1541
+ const onUserUpdated = t1;
1542
+ let t2;
1543
+ if ($[6] !== roles || $[7] !== userProp) {
1544
+ t2 = userProp ?? {
1195
1545
  displayName: "",
1196
1546
  email: "",
1197
- roles: roles.filter((r) => r.id === "editor")
1198
- },
1199
- validation: (values2) => {
1200
- return UserYupSchema.validate(values2, { abortEarly: false }).then(() => {
1201
- return {};
1202
- }).catch((e) => {
1203
- return e.inner.reduce((acc, error) => {
1204
- acc[error.path] = error.message;
1205
- return acc;
1206
- }, {});
1547
+ roles: roles.filter(_temp$1)
1548
+ };
1549
+ $[6] = roles;
1550
+ $[7] = userProp;
1551
+ $[8] = t2;
1552
+ } else {
1553
+ t2 = $[8];
1554
+ }
1555
+ let t3;
1556
+ if ($[9] !== handleClose || $[10] !== onUserUpdated || $[11] !== snackbarController) {
1557
+ t3 = (user, formexController) => onUserUpdated(user).then(() => {
1558
+ handleClose();
1559
+ formexController.resetForm({
1560
+ values: user
1207
1561
  });
1208
- },
1209
- onSubmit: (user, formexController) => {
1210
- return onUserUpdated(user).then(() => {
1211
- handleClose();
1212
- formexController.resetForm({
1213
- values: user
1214
- });
1215
- }).catch((e) => {
1216
- snackbarController.open({
1217
- type: "error",
1218
- message: e.message
1219
- });
1562
+ }).catch((e_1) => {
1563
+ snackbarController.open({
1564
+ type: "error",
1565
+ message: e_1.message
1220
1566
  });
1221
- }
1222
- });
1567
+ });
1568
+ $[9] = handleClose;
1569
+ $[10] = onUserUpdated;
1570
+ $[11] = snackbarController;
1571
+ $[12] = t3;
1572
+ } else {
1573
+ t3 = $[12];
1574
+ }
1575
+ let t4;
1576
+ if ($[13] !== t2 || $[14] !== t3) {
1577
+ t4 = {
1578
+ initialValues: t2,
1579
+ validation: _temp5,
1580
+ onSubmit: t3
1581
+ };
1582
+ $[13] = t2;
1583
+ $[14] = t3;
1584
+ $[15] = t4;
1585
+ } else {
1586
+ t4 = $[15];
1587
+ }
1588
+ const formex$1 = formex.useCreateFormex(t4);
1223
1589
  const {
1224
1590
  isSubmitting,
1225
- touched,
1226
1591
  handleChange,
1227
- values,
1592
+ values: values_0,
1228
1593
  errors,
1229
1594
  setFieldValue,
1230
1595
  dirty,
1231
1596
  handleSubmit,
1232
1597
  submitCount
1233
1598
  } = formex$1;
1234
- return /* @__PURE__ */ jsxRuntime.jsx(
1235
- ui.Dialog,
1236
- {
1237
- open,
1238
- onOpenChange: (open2) => !open2 ? handleClose() : void 0,
1239
- maxWidth: "4xl",
1240
- children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
1241
- "form",
1242
- {
1243
- onSubmit: handleSubmit,
1244
- autoComplete: "off",
1245
- noValidate: true,
1246
- style: {
1247
- display: "flex",
1248
- flexDirection: "column",
1249
- position: "relative",
1250
- height: "100%"
1251
- },
1252
- children: [
1253
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "h-full flex-grow", children: [
1254
- /* @__PURE__ */ jsxRuntime.jsx(
1255
- "div",
1256
- {
1257
- className: "flex flex-row pt-4 pb-4",
1258
- children: /* @__PURE__ */ jsxRuntime.jsx(
1259
- ui.Typography,
1260
- {
1261
- variant: "h4",
1262
- className: "flex-grow",
1263
- children: "User"
1264
- }
1265
- )
1266
- }
1267
- ),
1268
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
1269
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1270
- /* @__PURE__ */ jsxRuntime.jsx(
1271
- ui.TextField,
1272
- {
1273
- name: "displayName",
1274
- required: true,
1275
- error: submitCount > 0 && Boolean(errors.displayName),
1276
- value: values.displayName ?? "",
1277
- onChange: handleChange,
1278
- "aria-describedby": "name-helper-text",
1279
- label: "Name"
1280
- }
1281
- ),
1282
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.displayName) ? errors.displayName : "Name of this user" })
1283
- ] }),
1284
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1285
- /* @__PURE__ */ jsxRuntime.jsx(
1286
- ui.TextField,
1287
- {
1288
- required: true,
1289
- error: submitCount > 0 && Boolean(errors.email),
1290
- name: "email",
1291
- value: values.email ?? "",
1292
- onChange: handleChange,
1293
- "aria-describedby": "email-helper-text",
1294
- label: "Email"
1295
- }
1296
- ),
1297
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.email) ? errors.email : "Email of this user" })
1298
- ] }),
1299
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
1300
- ui.MultiSelect,
1301
- {
1302
- className: "w-full",
1303
- label: "Roles",
1304
- value: values.roles?.map((r) => r.id) ?? [],
1305
- onValueChange: (value) => setFieldValue("roles", value.map((id) => roles.find((r) => r.id === id))),
1306
- children: roles.map((userRole) => /* @__PURE__ */ jsxRuntime.jsx(
1307
- ui.MultiSelectItem,
1308
- {
1309
- value: userRole.id,
1310
- children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1311
- },
1312
- userRole.id
1313
- ))
1314
- }
1315
- ) })
1316
- ] })
1317
- ] }),
1318
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { children: [
1319
- /* @__PURE__ */ jsxRuntime.jsx(
1320
- ui.Button,
1321
- {
1322
- variant: "text",
1323
- onClick: () => {
1324
- handleClose();
1325
- },
1326
- children: "Cancel"
1327
- }
1328
- ),
1329
- /* @__PURE__ */ jsxRuntime.jsx(
1330
- ui.LoadingButton,
1331
- {
1332
- variant: "filled",
1333
- color: "primary",
1334
- type: "submit",
1335
- disabled: !dirty,
1336
- loading: isSubmitting,
1337
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
1338
- children: isNewUser ? "Create user" : "Update"
1339
- }
1340
- )
1341
- ] })
1342
- ]
1343
- }
1344
- ) })
1345
- }
1346
- );
1599
+ let t5;
1600
+ if ($[16] !== handleClose) {
1601
+ t5 = (open_0) => !open_0 ? handleClose() : void 0;
1602
+ $[16] = handleClose;
1603
+ $[17] = t5;
1604
+ } else {
1605
+ t5 = $[17];
1606
+ }
1607
+ let t6;
1608
+ let t7;
1609
+ if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
1610
+ t6 = {
1611
+ display: "flex",
1612
+ flexDirection: "column",
1613
+ position: "relative",
1614
+ height: "100%"
1615
+ };
1616
+ t7 = /* @__PURE__ */ jsxRuntime.jsx(ui.DialogTitle, { variant: "h4", gutterBottom: false, children: "User" });
1617
+ $[18] = t6;
1618
+ $[19] = t7;
1619
+ } else {
1620
+ t6 = $[18];
1621
+ t7 = $[19];
1622
+ }
1623
+ const t8 = submitCount > 0 && Boolean(errors.displayName);
1624
+ const t9 = values_0.displayName ?? "";
1625
+ let t10;
1626
+ if ($[20] !== handleChange || $[21] !== t8 || $[22] !== t9) {
1627
+ t10 = /* @__PURE__ */ jsxRuntime.jsx(ui.TextField, { name: "displayName", required: true, error: t8, value: t9, onChange: handleChange, "aria-describedby": "name-helper-text", label: "Name" });
1628
+ $[20] = handleChange;
1629
+ $[21] = t8;
1630
+ $[22] = t9;
1631
+ $[23] = t10;
1632
+ } else {
1633
+ t10 = $[23];
1634
+ }
1635
+ const t11 = submitCount > 0 && Boolean(errors.displayName) ? errors.displayName : "Name of this user";
1636
+ let t12;
1637
+ if ($[24] !== t11) {
1638
+ t12 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t11 });
1639
+ $[24] = t11;
1640
+ $[25] = t12;
1641
+ } else {
1642
+ t12 = $[25];
1643
+ }
1644
+ let t13;
1645
+ if ($[26] !== t10 || $[27] !== t12) {
1646
+ t13 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1647
+ t10,
1648
+ t12
1649
+ ] });
1650
+ $[26] = t10;
1651
+ $[27] = t12;
1652
+ $[28] = t13;
1653
+ } else {
1654
+ t13 = $[28];
1655
+ }
1656
+ const t14 = submitCount > 0 && Boolean(errors.email);
1657
+ const t15 = values_0.email ?? "";
1658
+ let t16;
1659
+ if ($[29] !== handleChange || $[30] !== t14 || $[31] !== t15) {
1660
+ t16 = /* @__PURE__ */ jsxRuntime.jsx(ui.TextField, { required: true, error: t14, name: "email", value: t15, onChange: handleChange, "aria-describedby": "email-helper-text", label: "Email" });
1661
+ $[29] = handleChange;
1662
+ $[30] = t14;
1663
+ $[31] = t15;
1664
+ $[32] = t16;
1665
+ } else {
1666
+ t16 = $[32];
1667
+ }
1668
+ const t17 = submitCount > 0 && Boolean(errors.email) ? errors.email : "Email of this user";
1669
+ let t18;
1670
+ if ($[33] !== t17) {
1671
+ t18 = /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: t17 });
1672
+ $[33] = t17;
1673
+ $[34] = t18;
1674
+ } else {
1675
+ t18 = $[34];
1676
+ }
1677
+ let t19;
1678
+ if ($[35] !== t16 || $[36] !== t18) {
1679
+ t19 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1680
+ t16,
1681
+ t18
1682
+ ] });
1683
+ $[35] = t16;
1684
+ $[36] = t18;
1685
+ $[37] = t19;
1686
+ } else {
1687
+ t19 = $[37];
1688
+ }
1689
+ let t20;
1690
+ if ($[38] !== values_0.roles) {
1691
+ t20 = values_0.roles?.map(_temp6) ?? [];
1692
+ $[38] = values_0.roles;
1693
+ $[39] = t20;
1694
+ } else {
1695
+ t20 = $[39];
1696
+ }
1697
+ let t21;
1698
+ if ($[40] !== roles || $[41] !== setFieldValue) {
1699
+ t21 = (value) => setFieldValue("roles", value.map((id) => roles.find((r_1) => r_1.id === id)));
1700
+ $[40] = roles;
1701
+ $[41] = setFieldValue;
1702
+ $[42] = t21;
1703
+ } else {
1704
+ t21 = $[42];
1705
+ }
1706
+ let t22;
1707
+ if ($[43] !== roles) {
1708
+ t22 = roles.map(_temp7);
1709
+ $[43] = roles;
1710
+ $[44] = t22;
1711
+ } else {
1712
+ t22 = $[44];
1713
+ }
1714
+ let t23;
1715
+ if ($[45] !== t20 || $[46] !== t21 || $[47] !== t22) {
1716
+ t23 = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(ui.MultiSelect, { className: "w-full", label: "Roles", value: t20, onValueChange: t21, children: t22 }) });
1717
+ $[45] = t20;
1718
+ $[46] = t21;
1719
+ $[47] = t22;
1720
+ $[48] = t23;
1721
+ } else {
1722
+ t23 = $[48];
1723
+ }
1724
+ let t24;
1725
+ if ($[49] !== t13 || $[50] !== t19 || $[51] !== t23) {
1726
+ t24 = /* @__PURE__ */ jsxRuntime.jsx(ui.DialogContent, { className: "h-full flex-grow", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
1727
+ t13,
1728
+ t19,
1729
+ t23
1730
+ ] }) });
1731
+ $[49] = t13;
1732
+ $[50] = t19;
1733
+ $[51] = t23;
1734
+ $[52] = t24;
1735
+ } else {
1736
+ t24 = $[52];
1737
+ }
1738
+ let t25;
1739
+ if ($[53] !== handleClose) {
1740
+ t25 = /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "text", onClick: () => {
1741
+ handleClose();
1742
+ }, children: "Cancel" });
1743
+ $[53] = handleClose;
1744
+ $[54] = t25;
1745
+ } else {
1746
+ t25 = $[54];
1747
+ }
1748
+ const t26 = !dirty;
1749
+ let t27;
1750
+ if ($[55] === Symbol.for("react.memo_cache_sentinel")) {
1751
+ t27 = /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {});
1752
+ $[55] = t27;
1753
+ } else {
1754
+ t27 = $[55];
1755
+ }
1756
+ const t28 = isNewUser ? "Create user" : "Update";
1757
+ let t29;
1758
+ if ($[56] !== isSubmitting || $[57] !== t26 || $[58] !== t28) {
1759
+ t29 = /* @__PURE__ */ jsxRuntime.jsx(ui.LoadingButton, { variant: "filled", color: "primary", type: "submit", disabled: t26, loading: isSubmitting, startIcon: t27, children: t28 });
1760
+ $[56] = isSubmitting;
1761
+ $[57] = t26;
1762
+ $[58] = t28;
1763
+ $[59] = t29;
1764
+ } else {
1765
+ t29 = $[59];
1766
+ }
1767
+ let t30;
1768
+ if ($[60] !== t25 || $[61] !== t29) {
1769
+ t30 = /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { children: [
1770
+ t25,
1771
+ t29
1772
+ ] });
1773
+ $[60] = t25;
1774
+ $[61] = t29;
1775
+ $[62] = t30;
1776
+ } else {
1777
+ t30 = $[62];
1778
+ }
1779
+ let t31;
1780
+ if ($[63] !== handleSubmit || $[64] !== t24 || $[65] !== t30) {
1781
+ t31 = /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, autoComplete: "off", noValidate: true, style: t6, children: [
1782
+ t7,
1783
+ t24,
1784
+ t30
1785
+ ] });
1786
+ $[63] = handleSubmit;
1787
+ $[64] = t24;
1788
+ $[65] = t30;
1789
+ $[66] = t31;
1790
+ } else {
1791
+ t31 = $[66];
1792
+ }
1793
+ let t32;
1794
+ if ($[67] !== formex$1 || $[68] !== t31) {
1795
+ t32 = /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: t31 });
1796
+ $[67] = formex$1;
1797
+ $[68] = t31;
1798
+ $[69] = t32;
1799
+ } else {
1800
+ t32 = $[69];
1801
+ }
1802
+ let t33;
1803
+ if ($[70] !== open || $[71] !== t32 || $[72] !== t5) {
1804
+ t33 = /* @__PURE__ */ jsxRuntime.jsx(ui.Dialog, { open, onOpenChange: t5, maxWidth: "4xl", children: t32 });
1805
+ $[70] = open;
1806
+ $[71] = t32;
1807
+ $[72] = t5;
1808
+ $[73] = t33;
1809
+ } else {
1810
+ t33 = $[73];
1811
+ }
1812
+ return t33;
1813
+ }
1814
+ function _temp7(userRole) {
1815
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.MultiSelectItem, { value: userRole.id, children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id) }, userRole.id);
1816
+ }
1817
+ function _temp6(r_0) {
1818
+ return r_0.id;
1819
+ }
1820
+ function _temp5(values) {
1821
+ return UserYupSchema.validate(values, {
1822
+ abortEarly: false
1823
+ }).then(_temp2).catch(_temp4);
1347
1824
  }
1348
- function UsersTable({ onUserClicked }) {
1825
+ function _temp4(e_0) {
1826
+ return e_0.inner.reduce(_temp3, {});
1827
+ }
1828
+ function _temp3(acc, error) {
1829
+ acc[error.path] = error.message;
1830
+ return acc;
1831
+ }
1832
+ function _temp2() {
1833
+ return {};
1834
+ }
1835
+ function _temp$1(r) {
1836
+ return r.id === "editor";
1837
+ }
1838
+ function UsersTable(t0) {
1839
+ const $ = reactCompilerRuntime.c(28);
1840
+ const {
1841
+ onUserClicked
1842
+ } = t0;
1349
1843
  const {
1350
1844
  users,
1351
1845
  saveUser,
@@ -1358,273 +1852,438 @@
1358
1852
  const dateFormat = customizationController?.dateTimeFormat ?? core.defaultDateFormat;
1359
1853
  const [userToBeDeleted, setUserToBeDeleted] = React.useState(void 0);
1360
1854
  const [deleteInProgress, setDeleteInProgress] = React.useState(false);
1361
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-auto", children: [
1362
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
1363
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
1364
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "truncate w-16" }),
1365
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Email" }),
1366
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Name" }),
1367
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Roles" }),
1368
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Created on" })
1369
- ] }),
1855
+ let t1;
1856
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
1857
+ t1 = /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
1858
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "truncate w-16" }),
1859
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Email" }),
1860
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Name" }),
1861
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Roles" }),
1862
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Created on" })
1863
+ ] });
1864
+ $[0] = t1;
1865
+ } else {
1866
+ t1 = $[0];
1867
+ }
1868
+ let t2;
1869
+ if ($[1] !== dateFormat || $[2] !== dateUtilsLocale || $[3] !== onUserClicked || $[4] !== users) {
1870
+ t2 = users && users.map((user) => {
1871
+ const userRoles = user.roles;
1872
+ const formattedDate = user.created_on ? dateFns.format(user.created_on, dateFormat, {
1873
+ locale: dateUtilsLocale
1874
+ }) : "";
1875
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { onClick: () => {
1876
+ onUserClicked(user);
1877
+ }, children: [
1878
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "w-10", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { asChild: true, title: "Delete this user", children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "small", onClick: (event) => {
1879
+ event.stopPropagation();
1880
+ return setUserToBeDeleted(user);
1881
+ }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {}) }) }) }),
1882
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.email }),
1883
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "font-medium align-left", children: user.displayName }),
1884
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "align-left", children: userRoles ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: userRoles.map(_temp) }) : null }),
1885
+ /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: formattedDate })
1886
+ ] }, "row_" + user.uid);
1887
+ });
1888
+ $[1] = dateFormat;
1889
+ $[2] = dateUtilsLocale;
1890
+ $[3] = onUserClicked;
1891
+ $[4] = users;
1892
+ $[5] = t2;
1893
+ } else {
1894
+ t2 = $[5];
1895
+ }
1896
+ let t3;
1897
+ if ($[6] !== authController || $[7] !== saveUser || $[8] !== snackbarController || $[9] !== users) {
1898
+ t3 = (!users || users.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1899
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "There are no users yet" }),
1900
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "outlined", onClick: () => {
1901
+ if (!authController.user?.uid) {
1902
+ throw Error("UsersTable, authController misconfiguration");
1903
+ }
1904
+ saveUser({
1905
+ uid: authController.user?.uid,
1906
+ email: authController.user?.email,
1907
+ displayName: authController.user?.displayName,
1908
+ photoURL: authController.user?.photoURL,
1909
+ providerId: authController.user?.providerId,
1910
+ isAnonymous: authController.user?.isAnonymous,
1911
+ roles: [{
1912
+ id: "admin",
1913
+ name: "Admin"
1914
+ }],
1915
+ created_on: /* @__PURE__ */ new Date()
1916
+ }).then(() => {
1917
+ snackbarController.open({
1918
+ type: "success",
1919
+ message: "User added successfully"
1920
+ });
1921
+ }).catch((error) => {
1922
+ snackbarController.open({
1923
+ type: "error",
1924
+ message: "Error adding user: " + error.message
1925
+ });
1926
+ });
1927
+ }, children: "Add the logged user as an admin" })
1928
+ ] }) }) });
1929
+ $[6] = authController;
1930
+ $[7] = saveUser;
1931
+ $[8] = snackbarController;
1932
+ $[9] = users;
1933
+ $[10] = t3;
1934
+ } else {
1935
+ t3 = $[10];
1936
+ }
1937
+ let t4;
1938
+ if ($[11] !== t2 || $[12] !== t3) {
1939
+ t4 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
1940
+ t1,
1370
1941
  /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
1371
- users && users.map((user) => {
1372
- const userRoles = user.roles;
1373
- const formattedDate = user.created_on ? dateFns.format(user.created_on, dateFormat, { locale: dateUtilsLocale }) : "";
1374
- return /* @__PURE__ */ jsxRuntime.jsxs(
1375
- ui.TableRow,
1376
- {
1377
- onClick: () => {
1378
- onUserClicked(user);
1379
- },
1380
- children: [
1381
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "w-10", children: /* @__PURE__ */ jsxRuntime.jsx(
1382
- ui.Tooltip,
1383
- {
1384
- asChild: true,
1385
- title: "Delete this user",
1386
- children: /* @__PURE__ */ jsxRuntime.jsx(
1387
- ui.IconButton,
1388
- {
1389
- size: "small",
1390
- onClick: (event) => {
1391
- event.stopPropagation();
1392
- return setUserToBeDeleted(user);
1393
- },
1394
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
1395
- }
1396
- )
1397
- }
1398
- ) }),
1399
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.email }),
1400
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "font-medium align-left", children: user.displayName }),
1401
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "align-left", children: userRoles ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: userRoles.map(
1402
- (userRole) => /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1403
- ) }) : null }),
1404
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: formattedDate })
1405
- ]
1406
- },
1407
- "row_" + user.uid
1408
- );
1409
- }),
1410
- (!users || users.length === 0) && /* @__PURE__ */ jsxRuntime.jsx(ui.TableRow, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { colspan: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.CenteredView, { className: "flex flex-col gap-4 my-8 items-center", children: [
1411
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "There are no users yet" }),
1412
- /* @__PURE__ */ jsxRuntime.jsx(
1413
- ui.Button,
1414
- {
1415
- variant: "outlined",
1416
- onClick: () => {
1417
- if (!authController.user?.uid) {
1418
- throw Error("UsersTable, authController misconfiguration");
1419
- }
1420
- saveUser({
1421
- uid: authController.user?.uid,
1422
- email: authController.user?.email,
1423
- displayName: authController.user?.displayName,
1424
- photoURL: authController.user?.photoURL,
1425
- providerId: authController.user?.providerId,
1426
- isAnonymous: authController.user?.isAnonymous,
1427
- roles: [{ id: "admin", name: "Admin" }],
1428
- created_on: /* @__PURE__ */ new Date()
1429
- }).then(() => {
1430
- snackbarController.open({
1431
- type: "success",
1432
- message: "User added successfully"
1433
- });
1434
- }).catch((error) => {
1435
- snackbarController.open({
1436
- type: "error",
1437
- message: "Error adding user: " + error.message
1438
- });
1439
- });
1440
- },
1441
- children: "Add the logged user as an admin"
1442
- }
1443
- )
1444
- ] }) }) })
1942
+ t2,
1943
+ t3
1445
1944
  ] })
1446
- ] }),
1447
- /* @__PURE__ */ jsxRuntime.jsx(
1448
- core.ConfirmationDialog,
1449
- {
1450
- open: Boolean(userToBeDeleted),
1451
- loading: deleteInProgress,
1452
- onAccept: () => {
1453
- if (userToBeDeleted) {
1454
- setDeleteInProgress(true);
1455
- deleteUser(userToBeDeleted).then(() => {
1456
- setUserToBeDeleted(void 0);
1457
- }).catch((error) => {
1458
- snackbarController.open({
1459
- type: "error",
1460
- message: "Error deleting user: " + error.message
1461
- });
1462
- }).finally(() => {
1463
- setDeleteInProgress(false);
1464
- });
1465
- }
1466
- },
1467
- onCancel: () => {
1945
+ ] });
1946
+ $[11] = t2;
1947
+ $[12] = t3;
1948
+ $[13] = t4;
1949
+ } else {
1950
+ t4 = $[13];
1951
+ }
1952
+ const t5 = Boolean(userToBeDeleted);
1953
+ let t6;
1954
+ if ($[14] !== deleteUser || $[15] !== snackbarController || $[16] !== userToBeDeleted) {
1955
+ t6 = () => {
1956
+ if (userToBeDeleted) {
1957
+ setDeleteInProgress(true);
1958
+ deleteUser(userToBeDeleted).then(() => {
1468
1959
  setUserToBeDeleted(void 0);
1469
- },
1470
- title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1471
- body: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this user?" })
1960
+ }).catch((error_0) => {
1961
+ snackbarController.open({
1962
+ type: "error",
1963
+ message: "Error deleting user: " + error_0.message
1964
+ });
1965
+ }).finally(() => {
1966
+ setDeleteInProgress(false);
1967
+ });
1472
1968
  }
1473
- )
1474
- ] });
1969
+ };
1970
+ $[14] = deleteUser;
1971
+ $[15] = snackbarController;
1972
+ $[16] = userToBeDeleted;
1973
+ $[17] = t6;
1974
+ } else {
1975
+ t6 = $[17];
1976
+ }
1977
+ let t7;
1978
+ let t8;
1979
+ let t9;
1980
+ if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
1981
+ t7 = () => {
1982
+ setUserToBeDeleted(void 0);
1983
+ };
1984
+ t8 = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" });
1985
+ t9 = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this user?" });
1986
+ $[18] = t7;
1987
+ $[19] = t8;
1988
+ $[20] = t9;
1989
+ } else {
1990
+ t7 = $[18];
1991
+ t8 = $[19];
1992
+ t9 = $[20];
1993
+ }
1994
+ let t10;
1995
+ if ($[21] !== deleteInProgress || $[22] !== t5 || $[23] !== t6) {
1996
+ t10 = /* @__PURE__ */ jsxRuntime.jsx(core.ConfirmationDialog, { open: t5, loading: deleteInProgress, onAccept: t6, onCancel: t7, title: t8, body: t9 });
1997
+ $[21] = deleteInProgress;
1998
+ $[22] = t5;
1999
+ $[23] = t6;
2000
+ $[24] = t10;
2001
+ } else {
2002
+ t10 = $[24];
2003
+ }
2004
+ let t11;
2005
+ if ($[25] !== t10 || $[26] !== t4) {
2006
+ t11 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-auto", children: [
2007
+ t4,
2008
+ t10
2009
+ ] });
2010
+ $[25] = t10;
2011
+ $[26] = t4;
2012
+ $[27] = t11;
2013
+ } else {
2014
+ t11 = $[27];
2015
+ }
2016
+ return t11;
1475
2017
  }
1476
- const UsersView = function UsersView2({ children }) {
2018
+ function _temp(userRole) {
2019
+ return /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id);
2020
+ }
2021
+ const UsersView = function UsersView2(t0) {
2022
+ const $ = reactCompilerRuntime.c(16);
2023
+ const {
2024
+ children
2025
+ } = t0;
1477
2026
  const [dialogOpen, setDialogOpen] = React.useState();
1478
2027
  const [selectedUser, setSelectedUser] = React.useState();
1479
- const { users, usersLimit } = useUserManagement();
1480
- const reachedUsersLimit = usersLimit !== void 0 && (users && users.length >= usersLimit);
1481
- const onUserClicked = React.useCallback((user) => {
1482
- setSelectedUser(user);
1483
- setDialogOpen(true);
1484
- }, []);
1485
- const handleClose = React.useCallback(() => {
1486
- setDialogOpen(false);
1487
- setSelectedUser(void 0);
1488
- }, []);
1489
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1490
- children,
1491
- /* @__PURE__ */ jsxRuntime.jsxs(
1492
- "div",
1493
- {
1494
- className: "flex items-center mt-12",
1495
- children: [
1496
- /* @__PURE__ */ jsxRuntime.jsx(
1497
- ui.Typography,
1498
- {
1499
- gutterBottom: true,
1500
- variant: "h4",
1501
- className: "flex-grow",
1502
- component: "h4",
1503
- children: "Users"
1504
- }
1505
- ),
1506
- /* @__PURE__ */ jsxRuntime.jsx(
1507
- ui.Button,
1508
- {
1509
- size: "large",
1510
- disabled: reachedUsersLimit,
1511
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1512
- onClick: () => setDialogOpen(true),
1513
- children: "Add user"
1514
- }
1515
- )
1516
- ]
1517
- }
1518
- ),
1519
- /* @__PURE__ */ jsxRuntime.jsx(UsersTable, { onUserClicked }),
1520
- /* @__PURE__ */ jsxRuntime.jsx(
1521
- UserDetailsForm,
1522
- {
1523
- open: dialogOpen ?? false,
1524
- user: selectedUser,
1525
- handleClose
1526
- },
1527
- selectedUser?.uid ?? "new"
1528
- )
1529
- ] });
2028
+ const {
2029
+ users,
2030
+ usersLimit
2031
+ } = useUserManagement();
2032
+ const reachedUsersLimit = usersLimit !== void 0 && users && users.length >= usersLimit;
2033
+ let t1;
2034
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2035
+ t1 = (user) => {
2036
+ setSelectedUser(user);
2037
+ setDialogOpen(true);
2038
+ };
2039
+ $[0] = t1;
2040
+ } else {
2041
+ t1 = $[0];
2042
+ }
2043
+ const onUserClicked = t1;
2044
+ let t2;
2045
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
2046
+ t2 = () => {
2047
+ setDialogOpen(false);
2048
+ setSelectedUser(void 0);
2049
+ };
2050
+ $[1] = t2;
2051
+ } else {
2052
+ t2 = $[1];
2053
+ }
2054
+ const handleClose = t2;
2055
+ let t3;
2056
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
2057
+ t3 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { gutterBottom: true, variant: "h4", className: "flex-grow", component: "h4", children: "Users" });
2058
+ $[2] = t3;
2059
+ } else {
2060
+ t3 = $[2];
2061
+ }
2062
+ let t4;
2063
+ let t5;
2064
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
2065
+ t4 = /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {});
2066
+ t5 = () => setDialogOpen(true);
2067
+ $[3] = t4;
2068
+ $[4] = t5;
2069
+ } else {
2070
+ t4 = $[3];
2071
+ t5 = $[4];
2072
+ }
2073
+ let t6;
2074
+ if ($[5] !== reachedUsersLimit) {
2075
+ t6 = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mt-12", children: [
2076
+ t3,
2077
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "large", disabled: reachedUsersLimit, startIcon: t4, onClick: t5, children: "Add user" })
2078
+ ] });
2079
+ $[5] = reachedUsersLimit;
2080
+ $[6] = t6;
2081
+ } else {
2082
+ t6 = $[6];
2083
+ }
2084
+ let t7;
2085
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
2086
+ t7 = /* @__PURE__ */ jsxRuntime.jsx(UsersTable, { onUserClicked });
2087
+ $[7] = t7;
2088
+ } else {
2089
+ t7 = $[7];
2090
+ }
2091
+ const t8 = selectedUser?.uid ?? "new";
2092
+ const t9 = dialogOpen ?? false;
2093
+ let t10;
2094
+ if ($[8] !== selectedUser || $[9] !== t8 || $[10] !== t9) {
2095
+ t10 = /* @__PURE__ */ jsxRuntime.jsx(UserDetailsForm, { open: t9, user: selectedUser, handleClose }, t8);
2096
+ $[8] = selectedUser;
2097
+ $[9] = t8;
2098
+ $[10] = t9;
2099
+ $[11] = t10;
2100
+ } else {
2101
+ t10 = $[11];
2102
+ }
2103
+ let t11;
2104
+ if ($[12] !== children || $[13] !== t10 || $[14] !== t6) {
2105
+ t11 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
2106
+ children,
2107
+ t6,
2108
+ t7,
2109
+ t10
2110
+ ] });
2111
+ $[12] = children;
2112
+ $[13] = t10;
2113
+ $[14] = t6;
2114
+ $[15] = t11;
2115
+ } else {
2116
+ t11 = $[15];
2117
+ }
2118
+ return t11;
1530
2119
  };
1531
- function useUserManagementPlugin({ userManagement }) {
2120
+ function useUserManagementPlugin(t0) {
2121
+ const $ = reactCompilerRuntime.c(12);
2122
+ const {
2123
+ userManagement
2124
+ } = t0;
1532
2125
  const noUsers = userManagement.users.length === 0;
1533
2126
  const noRoles = userManagement.roles.length === 0;
1534
- return {
1535
- key: "user_management",
1536
- loading: userManagement.loading,
1537
- homePage: {
1538
- additionalChildrenStart: noUsers || noRoles ? /* @__PURE__ */ jsxRuntime.jsx(
1539
- IntroWidget,
1540
- {
1541
- noUsers,
1542
- noRoles,
1543
- userManagement
1544
- }
1545
- ) : void 0
1546
- },
1547
- provider: {
2127
+ let t1;
2128
+ if ($[0] !== noRoles || $[1] !== noUsers || $[2] !== userManagement) {
2129
+ t1 = noUsers || noRoles ? /* @__PURE__ */ jsxRuntime.jsx(IntroWidget, { noUsers, noRoles, userManagement }) : void 0;
2130
+ $[0] = noRoles;
2131
+ $[1] = noUsers;
2132
+ $[2] = userManagement;
2133
+ $[3] = t1;
2134
+ } else {
2135
+ t1 = $[3];
2136
+ }
2137
+ let t2;
2138
+ if ($[4] !== t1) {
2139
+ t2 = {
2140
+ additionalChildrenStart: t1
2141
+ };
2142
+ $[4] = t1;
2143
+ $[5] = t2;
2144
+ } else {
2145
+ t2 = $[5];
2146
+ }
2147
+ let t3;
2148
+ if ($[6] !== userManagement) {
2149
+ t3 = {
1548
2150
  Component: UserManagementProvider,
1549
2151
  props: {
1550
2152
  userManagement
1551
2153
  }
1552
- }
1553
- };
2154
+ };
2155
+ $[6] = userManagement;
2156
+ $[7] = t3;
2157
+ } else {
2158
+ t3 = $[7];
2159
+ }
2160
+ let t4;
2161
+ if ($[8] !== t2 || $[9] !== t3 || $[10] !== userManagement.loading) {
2162
+ t4 = {
2163
+ key: "user_management",
2164
+ loading: userManagement.loading,
2165
+ homePage: t2,
2166
+ provider: t3
2167
+ };
2168
+ $[8] = t2;
2169
+ $[9] = t3;
2170
+ $[10] = userManagement.loading;
2171
+ $[11] = t4;
2172
+ } else {
2173
+ t4 = $[11];
2174
+ }
2175
+ return t4;
1554
2176
  }
1555
- function IntroWidget({
1556
- noUsers,
1557
- noRoles,
1558
- userManagement
1559
- }) {
2177
+ function IntroWidget(t0) {
2178
+ const $ = reactCompilerRuntime.c(17);
2179
+ const {
2180
+ noUsers,
2181
+ noRoles,
2182
+ userManagement
2183
+ } = t0;
1560
2184
  const authController = core.useAuthController();
1561
2185
  const snackbarController = core.useSnackbarController();
1562
2186
  const buttonLabel = noUsers && noRoles ? "Create default roles and add current user as admin" : noUsers ? "Add current user as admin" : noRoles ? "Create default roles" : void 0;
1563
- return /* @__PURE__ */ jsxRuntime.jsxs(
1564
- ui.Paper,
1565
- {
1566
- className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-surface-accent-800 gap-2",
1567
- children: [
1568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" }),
1569
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { children: "You have no users or roles defined. You can create default roles and add the current user as admin." }),
1570
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { onClick: () => {
1571
- if (!authController.user?.uid) {
1572
- throw Error("UsersTable, authController misconfiguration");
1573
- }
1574
- if (noUsers) {
1575
- userManagement.saveUser({
1576
- uid: authController.user?.uid,
1577
- email: authController.user?.email,
1578
- displayName: authController.user?.displayName,
1579
- photoURL: authController.user?.photoURL,
1580
- providerId: authController.user?.providerId,
1581
- isAnonymous: authController.user?.isAnonymous,
1582
- roles: [{
1583
- id: "admin",
1584
- name: "Admin"
1585
- }],
1586
- created_on: /* @__PURE__ */ new Date()
1587
- }).then(() => {
1588
- snackbarController.open({
1589
- type: "success",
1590
- message: "User added successfully"
1591
- });
1592
- }).catch((error) => {
1593
- snackbarController.open({
1594
- type: "error",
1595
- message: "Error adding user: " + error.message
1596
- });
1597
- });
1598
- }
1599
- if (noRoles) {
1600
- DEFAULT_ROLES.forEach((role) => {
1601
- userManagement.saveRole(role);
1602
- });
1603
- }
1604
- }, children: [
1605
- /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1606
- buttonLabel
1607
- ] })
1608
- ]
1609
- }
1610
- );
2187
+ let t1;
2188
+ let t2;
2189
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
2190
+ t1 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" });
2191
+ t2 = /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { children: "You have no users or roles defined. You can create default roles and add the current user as admin." });
2192
+ $[0] = t1;
2193
+ $[1] = t2;
2194
+ } else {
2195
+ t1 = $[0];
2196
+ t2 = $[1];
2197
+ }
2198
+ let t3;
2199
+ if ($[2] !== authController.user?.displayName || $[3] !== authController.user?.email || $[4] !== authController.user?.isAnonymous || $[5] !== authController.user?.photoURL || $[6] !== authController.user?.providerId || $[7] !== authController.user?.uid || $[8] !== noRoles || $[9] !== noUsers || $[10] !== snackbarController || $[11] !== userManagement) {
2200
+ t3 = () => {
2201
+ if (!authController.user?.uid) {
2202
+ throw Error("UsersTable, authController misconfiguration");
2203
+ }
2204
+ if (noUsers) {
2205
+ userManagement.saveUser({
2206
+ uid: authController.user?.uid,
2207
+ email: authController.user?.email,
2208
+ displayName: authController.user?.displayName,
2209
+ photoURL: authController.user?.photoURL,
2210
+ providerId: authController.user?.providerId,
2211
+ isAnonymous: authController.user?.isAnonymous,
2212
+ roles: [{
2213
+ id: "admin",
2214
+ name: "Admin"
2215
+ }],
2216
+ created_on: /* @__PURE__ */ new Date()
2217
+ }).then(() => {
2218
+ snackbarController.open({
2219
+ type: "success",
2220
+ message: "User added successfully"
2221
+ });
2222
+ }).catch((error) => {
2223
+ snackbarController.open({
2224
+ type: "error",
2225
+ message: "Error adding user: " + error.message
2226
+ });
2227
+ });
2228
+ }
2229
+ if (noRoles) {
2230
+ DEFAULT_ROLES.forEach((role) => {
2231
+ userManagement.saveRole(role);
2232
+ });
2233
+ }
2234
+ };
2235
+ $[2] = authController.user?.displayName;
2236
+ $[3] = authController.user?.email;
2237
+ $[4] = authController.user?.isAnonymous;
2238
+ $[5] = authController.user?.photoURL;
2239
+ $[6] = authController.user?.providerId;
2240
+ $[7] = authController.user?.uid;
2241
+ $[8] = noRoles;
2242
+ $[9] = noUsers;
2243
+ $[10] = snackbarController;
2244
+ $[11] = userManagement;
2245
+ $[12] = t3;
2246
+ } else {
2247
+ t3 = $[12];
2248
+ }
2249
+ let t4;
2250
+ if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
2251
+ t4 = /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {});
2252
+ $[13] = t4;
2253
+ } else {
2254
+ t4 = $[13];
2255
+ }
2256
+ let t5;
2257
+ if ($[14] !== buttonLabel || $[15] !== t3) {
2258
+ t5 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Paper, { className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-surface-accent-800 gap-2", children: [
2259
+ t1,
2260
+ t2,
2261
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { onClick: t3, children: [
2262
+ t4,
2263
+ buttonLabel
2264
+ ] })
2265
+ ] });
2266
+ $[14] = buttonLabel;
2267
+ $[15] = t3;
2268
+ $[16] = t5;
2269
+ } else {
2270
+ t5 = $[16];
2271
+ }
2272
+ return t5;
1611
2273
  }
1612
- const userManagementAdminViews = [
1613
- {
1614
- path: "users",
1615
- name: "CMS Users",
1616
- group: "Admin",
1617
- icon: "face",
1618
- view: /* @__PURE__ */ jsxRuntime.jsx(UsersView, {})
1619
- },
1620
- {
1621
- path: "roles",
1622
- name: "Roles",
1623
- group: "Admin",
1624
- icon: "gpp_good",
1625
- view: /* @__PURE__ */ jsxRuntime.jsx(RolesView, {})
1626
- }
1627
- ];
2274
+ const userManagementAdminViews = [{
2275
+ path: "users",
2276
+ name: "CMS Users",
2277
+ group: "Admin",
2278
+ icon: "face",
2279
+ view: /* @__PURE__ */ jsxRuntime.jsx(UsersView, {})
2280
+ }, {
2281
+ path: "roles",
2282
+ name: "Roles",
2283
+ group: "Admin",
2284
+ icon: "gpp_good",
2285
+ view: /* @__PURE__ */ jsxRuntime.jsx(RolesView, {})
2286
+ }];
1628
2287
  exports2.IntroWidget = IntroWidget;
1629
2288
  exports2.RESERVED_GROUPS = RESERVED_GROUPS;
1630
2289
  exports2.RoleChip = RoleChip;