@firecms/user_management 3.0.0-beta.10 → 3.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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" } });
@@ -155,6 +155,7 @@
155
155
  return `rgba(${r}, ${g}, ${b}, ${alpha})`;
156
156
  }
157
157
  function useBuildUserManagement({
158
+ authController,
158
159
  dataSourceDelegate,
159
160
  usersPath = "__FIRECMS/config/users",
160
161
  rolesPath = "__FIRECMS/config/roles",
@@ -163,6 +164,9 @@
163
164
  allowDefaultRolesCreation,
164
165
  includeCollectionConfigPermissions
165
166
  }) {
167
+ if (!authController) {
168
+ throw Error("useBuildUserManagement: You need to provide an authController since version 3.0.0-beta.11. Check https://firecms.co/docs/pro/migrating_from_v3_beta");
169
+ }
166
170
  const [rolesLoading, setRolesLoading] = React.useState(true);
167
171
  const [usersLoading, setUsersLoading] = React.useState(true);
168
172
  const [roles, setRoles] = React.useState([]);
@@ -173,14 +177,13 @@
173
177
  }));
174
178
  const [rolesError, setRolesError] = React.useState();
175
179
  const [usersError, setUsersError] = React.useState();
176
- const loading = rolesLoading || usersLoading;
180
+ const _usersLoading = usersLoading;
181
+ const _rolesLoading = rolesLoading;
182
+ const loading = _rolesLoading || _usersLoading;
177
183
  React.useEffect(() => {
178
184
  if (!dataSourceDelegate || !rolesPath) return;
179
185
  if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
180
- if (dataSourceDelegate.authenticated !== void 0 && !dataSourceDelegate.authenticated) {
181
- setRolesLoading(false);
182
- return;
183
- }
186
+ if (authController?.initialLoading) return;
184
187
  setRolesLoading(true);
185
188
  return dataSourceDelegate.listenCollection?.({
186
189
  path: rolesPath,
@@ -188,8 +191,9 @@
188
191
  setRolesError(void 0);
189
192
  try {
190
193
  const newRoles = entityToRoles(entities);
191
- if (!equal(newRoles, roles))
194
+ if (!equal(newRoles, roles)) {
192
195
  setRoles(newRoles);
196
+ }
193
197
  } catch (e) {
194
198
  setRoles([]);
195
199
  console.error("Error loading roles", e);
@@ -197,53 +201,54 @@
197
201
  }
198
202
  setRolesLoading(false);
199
203
  },
200
- onError(e) {
204
+ onError(e_0) {
201
205
  setRoles([]);
202
- console.error("Error loading roles", e);
203
- setRolesError(e);
206
+ console.error("Error loading roles", e_0);
207
+ setRolesError(e_0);
204
208
  setRolesLoading(false);
205
209
  }
206
210
  });
207
- }, [dataSourceDelegate?.initialised, dataSourceDelegate?.authenticated, rolesPath]);
211
+ }, [dataSourceDelegate?.initialised, authController?.initialLoading, authController?.user?.uid, rolesPath]);
208
212
  React.useEffect(() => {
209
213
  if (!dataSourceDelegate || !usersPath) return;
210
- if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) return;
211
- if (dataSourceDelegate.authenticated !== void 0 && !dataSourceDelegate.authenticated) {
212
- setUsersLoading(false);
214
+ if (dataSourceDelegate.initialised !== void 0 && !dataSourceDelegate.initialised) {
215
+ return;
216
+ }
217
+ if (authController?.initialLoading) {
213
218
  return;
214
219
  }
215
220
  setUsersLoading(true);
216
221
  return dataSourceDelegate.listenCollection?.({
217
222
  path: usersPath,
218
- onUpdate(entities) {
223
+ onUpdate(entities_0) {
224
+ console.debug("Updating users", entities_0);
219
225
  setUsersError(void 0);
220
226
  try {
221
- const newUsers = entitiesToUsers(entities);
222
- if (!equal(newUsers, usersWithRoleIds))
223
- setUsersWithRoleIds(newUsers);
224
- } catch (e) {
227
+ const newUsers = entitiesToUsers(entities_0);
228
+ setUsersWithRoleIds(newUsers);
229
+ } catch (e_1) {
225
230
  setUsersWithRoleIds([]);
226
- console.error("Error loading users", e);
227
- setUsersError(e);
231
+ console.error("Error loading users", e_1);
232
+ setUsersError(e_1);
228
233
  }
229
234
  setUsersLoading(false);
230
235
  },
231
- onError(e) {
236
+ onError(e_2) {
237
+ console.error("Error loading users", e_2);
232
238
  setUsersWithRoleIds([]);
233
- console.error("Error loading users", e);
234
- setUsersError(e);
239
+ setUsersError(e_2);
235
240
  setUsersLoading(false);
236
241
  }
237
242
  });
238
- }, [dataSourceDelegate?.initialised, dataSourceDelegate?.authenticated, usersPath]);
243
+ }, [dataSourceDelegate?.initialised, authController?.initialLoading, authController?.user?.uid, usersPath]);
239
244
  const saveUser = React.useCallback(async (user) => {
240
245
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
241
246
  if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
242
247
  console.debug("Persisting user", user);
243
- const roleIds = user.roles?.map((r) => r.id);
248
+ const roleIds = user.roles?.map((r_0) => r_0.id);
244
249
  const email = user.email?.toLowerCase().trim();
245
250
  if (!email) throw Error("Email is required");
246
- const userExists = users.find((u) => u.email?.toLowerCase() === email);
251
+ const userExists = users.find((u_0) => u_0.email?.toLowerCase() === email);
247
252
  const data = {
248
253
  ...user,
249
254
  roles: roleIds ?? []
@@ -275,58 +280,78 @@
275
280
  return;
276
281
  });
277
282
  }, [rolesPath, dataSourceDelegate?.initialised]);
278
- const deleteUser = React.useCallback(async (user) => {
283
+ const deleteUser = React.useCallback(async (user_0) => {
279
284
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
280
285
  if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
281
- console.debug("Deleting", user);
282
- const { uid } = user;
286
+ console.debug("Deleting", user_0);
287
+ const {
288
+ uid
289
+ } = user_0;
283
290
  const entity = {
284
291
  path: usersPath,
285
292
  id: uid,
286
293
  values: {}
287
294
  };
288
- await dataSourceDelegate.deleteEntity({ entity });
295
+ await dataSourceDelegate.deleteEntity({
296
+ entity
297
+ });
289
298
  }, [usersPath, dataSourceDelegate?.initialised]);
290
- const deleteRole = React.useCallback(async (role) => {
299
+ const deleteRole = React.useCallback(async (role_0) => {
291
300
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
292
301
  if (!rolesPath) throw Error("useBuildUserManagement Firestore not initialised");
293
- console.debug("Deleting", role);
294
- const { id } = role;
295
- const entity = {
302
+ console.debug("Deleting", role_0);
303
+ const {
304
+ id: id_0
305
+ } = role_0;
306
+ const entity_0 = {
296
307
  path: rolesPath,
297
- id,
308
+ id: id_0,
298
309
  values: {}
299
310
  };
300
- await dataSourceDelegate.deleteEntity({ entity });
311
+ await dataSourceDelegate.deleteEntity({
312
+ entity: entity_0
313
+ });
301
314
  }, [rolesPath, dataSourceDelegate?.initialised]);
302
315
  const collectionPermissions = React.useCallback(({
303
316
  collection,
304
- user
317
+ user: user_1
305
318
  }) => resolveUserRolePermissions({
306
319
  collection,
307
- user
320
+ user: user_1
308
321
  }), []);
309
- const defineRolesFor = React.useCallback((user) => {
310
- if (!users) throw Error("Users not loaded");
311
- const mgmtUser = users.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
322
+ const defineRolesFor = React.useCallback((user_2) => {
323
+ if (!usersWithRoleIds) throw Error("Users not loaded");
324
+ const users_0 = usersWithRoleIds.map((u_1) => ({
325
+ ...u_1,
326
+ roles: roles.filter((r_1) => u_1.roles?.includes(r_1.id))
327
+ }));
328
+ const mgmtUser = users_0.find((u_2) => u_2.email?.toLowerCase() === user_2?.email?.toLowerCase());
312
329
  return mgmtUser?.roles;
313
- }, [users]);
314
- const authenticator = React.useCallback(({ user }) => {
315
- console.debug("Authenticating user", user);
330
+ }, [roles, usersWithRoleIds]);
331
+ const authenticator = React.useCallback(({
332
+ user: user_3
333
+ }) => {
316
334
  if (loading) {
317
- console.warn("User management is still loading");
318
335
  return false;
319
336
  }
320
337
  if (users.length === 0) {
338
+ console.warn("No users created yet");
321
339
  return true;
322
340
  }
323
- const mgmtUser = users.find((u) => u.email?.toLowerCase() === user?.email?.toLowerCase());
324
- if (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);
325
344
  return true;
326
345
  }
327
346
  throw Error("Could not find a user with the provided email in the user management system.");
328
- }, [loading, users, usersError, rolesError]);
329
- const isAdmin = roles.some((r) => r.id === "admin");
347
+ }, [loading, users]);
348
+ const userRoles = authController.user ? defineRolesFor(authController.user) : void 0;
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]);
330
355
  return {
331
356
  loading,
332
357
  roles,
@@ -344,7 +369,14 @@
344
369
  includeCollectionConfigPermissions: Boolean(includeCollectionConfigPermissions),
345
370
  collectionPermissions,
346
371
  defineRolesFor,
347
- authenticator
372
+ authenticator,
373
+ ...authController,
374
+ initialLoading: authController.initialLoading || loading,
375
+ userRoles,
376
+ user: authController.user ? {
377
+ ...authController.user,
378
+ roles: userRoles
379
+ } : null
348
380
  };
349
381
  }
350
382
  const entitiesToUsers = (docs) => {
@@ -366,32 +398,64 @@
366
398
  }));
367
399
  };
368
400
  const UserManagementContext = React.createContext({});
369
- function UserManagementProvider({
370
- children,
371
- userManagement
372
- }) {
373
- 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;
374
417
  }
375
- const useUserManagement = () => React.useContext(UserManagementContext);
376
- 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;
377
426
  let colorScheme;
378
427
  if (role.isAdmin) {
379
428
  colorScheme = "blueDarker";
380
- } else if (role.id === "editor") {
381
- colorScheme = "yellowLight";
382
- } else if (role.id === "viewer") {
383
- colorScheme = "grayLight";
384
- } else {
385
- colorScheme = ui.getColorSchemeForSeed(role.id);
386
- }
387
- return /* @__PURE__ */ jsxRuntime.jsx(
388
- ui.Chip,
389
- {
390
- colorScheme,
391
- children: role.name
392
- },
393
- role.id
394
- );
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;
395
459
  }
396
460
  const RoleYupSchema = Yup__namespace.object().shape({
397
461
  id: Yup__namespace.string().required("Required"),
@@ -399,564 +463,763 @@
399
463
  });
400
464
  function canRoleBeEdited(loggedUser) {
401
465
  const loggedUserIsAdmin = loggedUser.roles?.map((r) => r.id).includes("admin");
466
+ console.log("loggedUserIsAdmin", loggedUser);
402
467
  if (!loggedUserIsAdmin) {
403
468
  throw new Error("Only admins can edit roles");
404
469
  }
405
470
  return true;
406
471
  }
407
- function RolesDetailsForm({
408
- open,
409
- role,
410
- editable,
411
- handleClose,
412
- collections
413
- }) {
414
- 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();
415
484
  const isNewRole = !role;
416
485
  const {
417
486
  user: loggedInUser
418
487
  } = core.useAuthController();
419
488
  const [savingError, setSavingError] = React.useState();
420
- const onRoleUpdated = React.useCallback((role2) => {
421
- setSavingError(void 0);
422
- if (!loggedInUser) throw new Error("User not found");
423
- canRoleBeEdited(loggedInUser);
424
- return saveRole(role2);
425
- }, [saveRole, loggedInUser]);
426
- const formex$1 = formex.useCreateFormex({
427
- 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 ?? {
428
509
  name: ""
429
- },
430
- 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) => {
431
519
  try {
432
- return onRoleUpdated(role2).then(() => {
520
+ return onRoleUpdated(role_1).then(() => {
433
521
  formexController.resetForm({
434
- values: role2
522
+ values: role_1
435
523
  });
436
524
  handleClose();
437
- }).catch((e) => {
438
- setSavingError(e);
525
+ }).catch((e_0) => {
526
+ setSavingError(e_0);
439
527
  });
440
- } catch (e) {
528
+ } catch (t410) {
529
+ const e = t410;
441
530
  setSavingError(e);
442
531
  return Promise.resolve();
443
532
  }
444
- },
445
- validation: (values2) => {
446
- return RoleYupSchema.validate(values2, { abortEarly: false }).then(() => ({})).catch((e) => {
447
- const errors2 = {};
448
- e.inner.forEach((error) => {
449
- errors2[error.path] = error.message;
450
- });
451
- return errors2;
452
- });
453
- }
454
- });
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);
455
554
  const {
456
555
  isSubmitting,
457
556
  touched,
458
- values,
459
- errors,
557
+ values: values_0,
558
+ errors: errors_0,
460
559
  handleChange,
461
560
  setFieldValue,
462
561
  dirty,
463
562
  setFieldTouched
464
563
  } = formex$1;
465
- const isAdmin = values.isAdmin ?? false;
466
- const defaultCreate = values.defaultPermissions?.create ?? false;
467
- const defaultRead = values.defaultPermissions?.read ?? false;
468
- const defaultEdit = values.defaultPermissions?.edit ?? false;
469
- const defaultDelete = values.defaultPermissions?.delete ?? false;
470
- React.useEffect(() => {
471
- const idTouched = formex.getIn(touched, "id");
472
- if (!idTouched && values.name) {
473
- setFieldValue("id", core.toSnakeCase(values.name));
474
- }
475
- }, [touched, values.name]);
476
- return /* @__PURE__ */ jsxRuntime.jsx(
477
- ui.Dialog,
478
- {
479
- open,
480
- maxWidth: "4xl",
481
- children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
482
- "form",
483
- {
484
- noValidate: true,
485
- autoComplete: "off",
486
- onSubmit: formex$1.handleSubmit,
487
- style: {
488
- display: "flex",
489
- flexDirection: "column",
490
- position: "relative",
491
- height: "100%"
492
- },
493
- children: [
494
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "flex-grow", children: [
495
- /* @__PURE__ */ jsxRuntime.jsx(
496
- "div",
497
- {
498
- className: "flex flex-row pt-12 pb-8",
499
- children: /* @__PURE__ */ jsxRuntime.jsx(
500
- ui.Typography,
501
- {
502
- variant: "h4",
503
- className: "flex-grow",
504
- children: "Role"
505
- }
506
- )
507
- }
508
- ),
509
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
510
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-8", children: [
511
- /* @__PURE__ */ jsxRuntime.jsx(
512
- ui.TextField,
513
- {
514
- name: "name",
515
- required: true,
516
- error: touched.name && Boolean(errors.name),
517
- value: values.name,
518
- disabled: isAdmin || !editable,
519
- onChange: handleChange,
520
- "aria-describedby": "name-helper-text",
521
- label: "Name"
522
- }
523
- ),
524
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.name && Boolean(errors.name) ? errors.name : "Name of this role" })
525
- ] }),
526
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
527
- /* @__PURE__ */ jsxRuntime.jsx(
528
- ui.TextField,
529
- {
530
- name: "id",
531
- required: true,
532
- error: touched.id && Boolean(errors.id),
533
- value: values.id,
534
- disabled: !isNewRole || !editable,
535
- onChange: (e) => {
536
- handleChange(e);
537
- setFieldTouched("id", true);
538
- },
539
- "aria-describedby": "id-helper-text",
540
- label: "ID"
541
- }
542
- ),
543
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.id && Boolean(errors.id) ? errors.id : "ID of this role" })
544
- ] }),
545
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
546
- /* @__PURE__ */ jsxRuntime.jsx(ui.Paper, { className: "bg-inherit overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full rounded-md", children: [
547
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { className: "rounded-md", children: [
548
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, {}),
549
- /* @__PURE__ */ jsxRuntime.jsx(
550
- ui.TableCell,
551
- {
552
- align: "center",
553
- children: "Create entities"
554
- }
555
- ),
556
- /* @__PURE__ */ jsxRuntime.jsx(
557
- ui.TableCell,
558
- {
559
- align: "center",
560
- children: "Read entities"
561
- }
562
- ),
563
- /* @__PURE__ */ jsxRuntime.jsx(
564
- ui.TableCell,
565
- {
566
- align: "center",
567
- children: "Update entities"
568
- }
569
- ),
570
- /* @__PURE__ */ jsxRuntime.jsx(
571
- ui.TableCell,
572
- {
573
- align: "center",
574
- children: "Delete entities"
575
- }
576
- ),
577
- /* @__PURE__ */ jsxRuntime.jsx(
578
- ui.TableCell,
579
- {
580
- align: "center"
581
- }
582
- )
583
- ] }),
584
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
585
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
586
- /* @__PURE__ */ jsxRuntime.jsx(
587
- ui.TableCell,
588
- {
589
- scope: "row",
590
- children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "All collections" })
591
- }
592
- ),
593
- /* @__PURE__ */ jsxRuntime.jsx(
594
- ui.TableCell,
595
- {
596
- align: "center",
597
- children: /* @__PURE__ */ jsxRuntime.jsx(
598
- ui.Tooltip,
599
- {
600
- title: "Create entities in collections",
601
- children: /* @__PURE__ */ jsxRuntime.jsx(
602
- ui.Checkbox,
603
- {
604
- disabled: isAdmin || !editable,
605
- checked: (isAdmin || defaultCreate) ?? false,
606
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.create", checked)
607
- }
608
- )
609
- }
610
- )
611
- }
612
- ),
613
- /* @__PURE__ */ jsxRuntime.jsx(
614
- ui.TableCell,
615
- {
616
- align: "center",
617
- children: /* @__PURE__ */ jsxRuntime.jsx(
618
- ui.Tooltip,
619
- {
620
- title: "Access all data in every collection",
621
- children: /* @__PURE__ */ jsxRuntime.jsx(
622
- ui.Checkbox,
623
- {
624
- disabled: isAdmin || !editable,
625
- checked: (isAdmin || defaultRead) ?? false,
626
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.read", checked)
627
- }
628
- )
629
- }
630
- )
631
- }
632
- ),
633
- /* @__PURE__ */ jsxRuntime.jsx(
634
- ui.TableCell,
635
- {
636
- align: "center",
637
- children: /* @__PURE__ */ jsxRuntime.jsx(
638
- ui.Tooltip,
639
- {
640
- title: "Update data in any collection",
641
- children: /* @__PURE__ */ jsxRuntime.jsx(
642
- ui.Checkbox,
643
- {
644
- disabled: isAdmin || !editable,
645
- checked: (isAdmin || defaultEdit) ?? false,
646
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.edit", checked)
647
- }
648
- )
649
- }
650
- )
651
- }
652
- ),
653
- /* @__PURE__ */ jsxRuntime.jsx(
654
- ui.TableCell,
655
- {
656
- align: "center",
657
- children: /* @__PURE__ */ jsxRuntime.jsx(
658
- ui.Tooltip,
659
- {
660
- title: "Delete data in any collection",
661
- children: /* @__PURE__ */ jsxRuntime.jsx(
662
- ui.Checkbox,
663
- {
664
- disabled: isAdmin || !editable,
665
- checked: (isAdmin || defaultDelete) ?? false,
666
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.delete", checked)
667
- }
668
- )
669
- }
670
- )
671
- }
672
- ),
673
- /* @__PURE__ */ jsxRuntime.jsx(
674
- ui.TableCell,
675
- {
676
- align: "center"
677
- }
678
- )
679
- ] }),
680
- collections && collections.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
681
- /* @__PURE__ */ jsxRuntime.jsx(
682
- ui.TableCell,
683
- {
684
- scope: "row",
685
- children: col.name
686
- }
687
- ),
688
- /* @__PURE__ */ jsxRuntime.jsx(
689
- ui.TableCell,
690
- {
691
- align: "center",
692
- children: /* @__PURE__ */ jsxRuntime.jsx(
693
- ui.Checkbox,
694
- {
695
- disabled: isAdmin || defaultCreate || !editable,
696
- checked: (isAdmin || defaultCreate || formex.getIn(values, `collectionPermissions.${col.id}.create`)) ?? false,
697
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.create`, checked)
698
- }
699
- )
700
- }
701
- ),
702
- /* @__PURE__ */ jsxRuntime.jsx(
703
- ui.TableCell,
704
- {
705
- align: "center",
706
- children: /* @__PURE__ */ jsxRuntime.jsx(
707
- ui.Checkbox,
708
- {
709
- disabled: isAdmin || defaultRead || !editable,
710
- checked: (isAdmin || defaultRead || formex.getIn(values, `collectionPermissions.${col.id}.read`)) ?? false,
711
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.read`, checked)
712
- }
713
- )
714
- }
715
- ),
716
- /* @__PURE__ */ jsxRuntime.jsx(
717
- ui.TableCell,
718
- {
719
- align: "center",
720
- children: /* @__PURE__ */ jsxRuntime.jsx(
721
- ui.Checkbox,
722
- {
723
- disabled: isAdmin || defaultEdit || !editable,
724
- checked: (isAdmin || defaultEdit || formex.getIn(values, `collectionPermissions.${col.id}.edit`)) ?? false,
725
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.edit`, checked)
726
- }
727
- )
728
- }
729
- ),
730
- /* @__PURE__ */ jsxRuntime.jsx(
731
- ui.TableCell,
732
- {
733
- align: "center",
734
- children: /* @__PURE__ */ jsxRuntime.jsx(
735
- ui.Checkbox,
736
- {
737
- disabled: isAdmin || defaultDelete || !editable,
738
- checked: (isAdmin || defaultDelete || formex.getIn(values, `collectionPermissions.${col.id}.delete`)) ?? false,
739
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.id}.delete`, checked)
740
- }
741
- )
742
- }
743
- ),
744
- /* @__PURE__ */ jsxRuntime.jsx(
745
- ui.TableCell,
746
- {
747
- align: "center",
748
- children: /* @__PURE__ */ jsxRuntime.jsx(
749
- ui.Tooltip,
750
- {
751
- title: "Allow all permissions in this collections",
752
- children: /* @__PURE__ */ jsxRuntime.jsx(
753
- ui.Button,
754
- {
755
- className: "color-inherit",
756
- onClick: () => {
757
- setFieldValue(`collectionPermissions.${col.id}.create`, true);
758
- setFieldValue(`collectionPermissions.${col.id}.read`, true);
759
- setFieldValue(`collectionPermissions.${col.id}.edit`, true);
760
- setFieldValue(`collectionPermissions.${col.id}.delete`, true);
761
- },
762
- disabled: isAdmin || !editable,
763
- variant: "text",
764
- children: "All"
765
- }
766
- )
767
- }
768
- )
769
- }
770
- )
771
- ] }, col.name))
772
- ] })
773
- ] }) }),
774
- /* @__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" })
775
- ] }),
776
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
777
- /* @__PURE__ */ jsxRuntime.jsxs(
778
- ui.Select,
779
- {
780
- error: touched.config && Boolean(errors.config),
781
- id: "createCollections",
782
- name: "createCollections",
783
- label: "Create collections",
784
- position: "item-aligned",
785
- disabled: isAdmin || !editable,
786
- onChange: (event) => setFieldValue("config.createCollections", event.target.value === "true"),
787
- value: isAdmin || values.config?.createCollections ? "true" : "false",
788
- renderValue: (value) => value === "true" ? "Yes" : "No",
789
- children: [
790
- /* @__PURE__ */ jsxRuntime.jsx(
791
- ui.SelectItem,
792
- {
793
- value: "true",
794
- children: " Yes "
795
- }
796
- ),
797
- /* @__PURE__ */ jsxRuntime.jsx(
798
- ui.SelectItem,
799
- {
800
- value: "false",
801
- children: " No "
802
- }
803
- )
804
- ]
805
- }
806
- ),
807
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user create collections" })
808
- ] }),
809
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
810
- /* @__PURE__ */ jsxRuntime.jsxs(
811
- ui.Select,
812
- {
813
- error: touched.config && Boolean(errors.config),
814
- id: "editCollections",
815
- name: "editCollections",
816
- label: "Edit collections",
817
- disabled: isAdmin || !editable,
818
- position: "item-aligned",
819
- onChange: (event) => setFieldValue("config.editCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
820
- value: isAdmin ? "true" : values.config?.editCollections === "own" ? "own" : values.config?.editCollections ? "true" : "false",
821
- renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
822
- children: [
823
- /* @__PURE__ */ jsxRuntime.jsx(
824
- ui.SelectItem,
825
- {
826
- value: "true",
827
- children: " Yes "
828
- }
829
- ),
830
- /* @__PURE__ */ jsxRuntime.jsx(
831
- ui.SelectItem,
832
- {
833
- value: "false",
834
- children: " No "
835
- }
836
- ),
837
- /* @__PURE__ */ jsxRuntime.jsx(
838
- ui.SelectItem,
839
- {
840
- value: "own",
841
- children: " Only his/her own "
842
- }
843
- )
844
- ]
845
- }
846
- ),
847
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user edit collections" })
848
- ] }),
849
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12 md:col-span-4", children: [
850
- /* @__PURE__ */ jsxRuntime.jsxs(
851
- ui.Select,
852
- {
853
- error: touched.config && Boolean(errors.config),
854
- id: "deleteCollections",
855
- name: "deleteCollections",
856
- label: "Delete collections",
857
- disabled: isAdmin || !editable,
858
- position: "item-aligned",
859
- onChange: (event) => setFieldValue("config.deleteCollections", event.target.value === "own" ? "own" : event.target.value === "true"),
860
- value: isAdmin ? "true" : values.config?.deleteCollections === "own" ? "own" : values.config?.deleteCollections ? "true" : "false",
861
- renderValue: (value) => value === "own" ? "Own" : value === "true" ? "Yes" : "No",
862
- children: [
863
- /* @__PURE__ */ jsxRuntime.jsx(
864
- ui.SelectItem,
865
- {
866
- value: "true",
867
- children: " Yes "
868
- }
869
- ),
870
- /* @__PURE__ */ jsxRuntime.jsx(
871
- ui.SelectItem,
872
- {
873
- value: "false",
874
- children: " No "
875
- }
876
- ),
877
- /* @__PURE__ */ jsxRuntime.jsx(
878
- ui.SelectItem,
879
- {
880
- value: "own",
881
- children: " Only his/her own "
882
- }
883
- )
884
- ]
885
- }
886
- ),
887
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: touched.config && Boolean(errors.config) ? errors.config : "Can the user delete collections" })
888
- ] })
889
- ] })
890
- ] }),
891
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { position: "sticky", children: [
892
- savingError && /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { className: "text-red-500 dark:text-red-500", children: savingError.message ?? "There was an error saving this role" }),
893
- /* @__PURE__ */ jsxRuntime.jsx(
894
- ui.Button,
895
- {
896
- variant: "text",
897
- onClick: () => {
898
- handleClose();
899
- },
900
- children: "Cancel"
901
- }
902
- ),
903
- /* @__PURE__ */ jsxRuntime.jsx(
904
- ui.LoadingButton,
905
- {
906
- variant: "filled",
907
- color: "primary",
908
- type: "submit",
909
- disabled: !dirty,
910
- loading: isSubmitting,
911
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
912
- children: isNewRole ? "Create role" : "Update"
913
- }
914
- )
915
- ] })
916
- ]
917
- }
918
- ) })
919
- }
920
- );
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.CheckIcon, {});
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;
921
1162
  }
922
- const DEFAULT_ROLES = [
923
- {
924
- id: "admin",
925
- name: "Admin",
926
- isAdmin: true
927
- },
928
- {
929
- id: "editor",
930
- name: "Editor",
931
- isAdmin: false,
932
- defaultPermissions: {
933
- read: true,
934
- create: true,
935
- edit: true,
936
- delete: true
937
- },
938
- config: {
939
- createCollections: true,
940
- editCollections: "own",
941
- deleteCollections: "own"
942
- }
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
943
1200
  },
944
- {
945
- id: "viewer",
946
- name: "Viewer",
947
- isAdmin: false,
948
- defaultPermissions: {
949
- read: true,
950
- create: false,
951
- edit: false,
952
- delete: false
953
- }
1201
+ config: {
1202
+ createCollections: true,
1203
+ editCollections: "own",
1204
+ deleteCollections: "own"
954
1205
  }
955
- ];
956
- function RolesTable({
957
- onRoleClicked,
958
- editable
959
- }) {
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;
960
1223
  const {
961
1224
  roles,
962
1225
  saveRole,
@@ -965,166 +1228,258 @@
965
1228
  } = useUserManagement();
966
1229
  const [roleToBeDeleted, setRoleToBeDeleted] = React.useState(void 0);
967
1230
  const [deleteInProgress, setDeleteInProgress] = React.useState(false);
968
- return /* @__PURE__ */ jsxRuntime.jsxs(
969
- "div",
970
- {
971
- className: "w-full overflow-auto",
972
- children: [
973
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
974
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
975
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "w-16" }),
976
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Role" }),
977
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, className: "items-center", children: "Is Admin" }),
978
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { header: true, children: "Default permissions" })
979
- ] }),
980
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
981
- roles && roles.map((role) => {
982
- const canCreateAll = role.isAdmin || role.defaultPermissions?.create;
983
- const canReadAll = role.isAdmin || role.defaultPermissions?.read;
984
- const canUpdateAll = role.isAdmin || role.defaultPermissions?.edit;
985
- const canDeleteAll = role.isAdmin || role.defaultPermissions?.delete;
986
- return /* @__PURE__ */ jsxRuntime.jsxs(
987
- ui.TableRow,
988
- {
989
- onClick: () => {
990
- onRoleClicked(role);
991
- },
992
- children: [
993
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { style: { width: "64px" }, children: !role.isAdmin && /* @__PURE__ */ jsxRuntime.jsx(
994
- ui.Tooltip,
995
- {
996
- asChild: true,
997
- title: "Delete this role",
998
- children: /* @__PURE__ */ jsxRuntime.jsx(
999
- ui.IconButton,
1000
- {
1001
- size: "small",
1002
- disabled: !editable,
1003
- onClick: (event) => {
1004
- event.stopPropagation();
1005
- return setRoleToBeDeleted(role);
1006
- },
1007
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
1008
- }
1009
- )
1010
- }
1011
- ) }),
1012
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role }) }),
1013
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "items-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { checked: role.isAdmin ?? false }) }),
1014
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsxs("ul", { children: [
1015
- canCreateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Create" }),
1016
- canReadAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Read" }),
1017
- canUpdateAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Update" }),
1018
- canDeleteAll && /* @__PURE__ */ jsxRuntime.jsx("li", { children: "Delete" })
1019
- ] }) })
1020
- ]
1021
- },
1022
- role.name
1023
- );
1024
- }),
1025
- (!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: [
1026
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "You don't have any roles yet." }),
1027
- allowDefaultRolesCreation && /* @__PURE__ */ jsxRuntime.jsx(
1028
- ui.Button,
1029
- {
1030
- variant: "outlined",
1031
- onClick: () => {
1032
- DEFAULT_ROLES.forEach((role) => {
1033
- saveRole(role);
1034
- });
1035
- },
1036
- children: "Create default roles"
1037
- }
1038
- )
1039
- ] }) }) })
1040
- ] })
1041
- ] }),
1042
- /* @__PURE__ */ jsxRuntime.jsx(
1043
- core.ConfirmationDialog,
1044
- {
1045
- open: Boolean(roleToBeDeleted),
1046
- loading: deleteInProgress,
1047
- onAccept: () => {
1048
- if (roleToBeDeleted) {
1049
- setDeleteInProgress(true);
1050
- deleteRole(roleToBeDeleted).then(() => {
1051
- setRoleToBeDeleted(void 0);
1052
- }).finally(() => {
1053
- setDeleteInProgress(false);
1054
- });
1055
- }
1056
- },
1057
- onCancel: () => {
1058
- setRoleToBeDeleted(void 0);
1059
- },
1060
- title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1061
- body: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Are you sure you want to delete this role?" })
1062
- }
1063
- )
1064
- ]
1065
- }
1066
- );
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;
1067
1367
  }
1068
- const RolesView = React.memo(
1069
- function RolesView2({ children }) {
1070
- const { collections } = core.useNavigationController();
1071
- const [dialogOpen, setDialogOpen] = React.useState(false);
1072
- const [selectedRole, setSelectedRole] = React.useState();
1073
- const { canEditRoles } = useUserManagement();
1074
- 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) => {
1075
1384
  setDialogOpen(true);
1076
1385
  setSelectedRole(user);
1077
- }, []);
1078
- 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 = () => {
1079
1395
  setSelectedRole(void 0);
1080
1396
  setDialogOpen(false);
1081
1397
  };
1082
- 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: [
1083
1468
  children,
1084
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center mt-12", children: [
1085
- /* @__PURE__ */ jsxRuntime.jsx(
1086
- ui.Typography,
1087
- {
1088
- gutterBottom: true,
1089
- variant: "h4",
1090
- className: "flex-grow",
1091
- component: "h4",
1092
- children: "Roles"
1093
- }
1094
- ),
1095
- /* @__PURE__ */ jsxRuntime.jsx(
1096
- ui.Tooltip,
1097
- {
1098
- asChild: true,
1099
- title: !canEditRoles ? "Update plans to customise roles" : void 0,
1100
- children: /* @__PURE__ */ jsxRuntime.jsx(
1101
- ui.Button,
1102
- {
1103
- size: "large",
1104
- disabled: !canEditRoles,
1105
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1106
- onClick: () => setDialogOpen(true),
1107
- children: "Add role"
1108
- }
1109
- )
1110
- }
1111
- )
1112
- ] }),
1113
- /* @__PURE__ */ jsxRuntime.jsx(RolesTable, { onRoleClicked, editable: Boolean(canEditRoles) }),
1114
- /* @__PURE__ */ jsxRuntime.jsx(
1115
- RolesDetailsForm,
1116
- {
1117
- open: dialogOpen,
1118
- role: selectedRole,
1119
- editable: canEditRoles,
1120
- collections,
1121
- handleClose
1122
- },
1123
- selectedRole?.id ?? "new"
1124
- )
1469
+ t9,
1470
+ t11,
1471
+ t13
1125
1472
  ] });
1473
+ $[18] = children;
1474
+ $[19] = t11;
1475
+ $[20] = t13;
1476
+ $[21] = t9;
1477
+ $[22] = t14;
1478
+ } else {
1479
+ t14 = $[22];
1126
1480
  }
1127
- );
1481
+ return t14;
1482
+ });
1128
1483
  const UserYupSchema = Yup__namespace.object().shape({
1129
1484
  displayName: Yup__namespace.string().required("Required"),
1130
1485
  email: Yup__namespace.string().email().required("Required"),
@@ -1143,11 +1498,13 @@
1143
1498
  }
1144
1499
  return true;
1145
1500
  }
1146
- function UserDetailsForm({
1147
- open,
1148
- user: userProp,
1149
- handleClose
1150
- }) {
1501
+ function UserDetailsForm(t0) {
1502
+ const $ = reactCompilerRuntime.c(74);
1503
+ const {
1504
+ open,
1505
+ user: userProp,
1506
+ handleClose
1507
+ } = t0;
1151
1508
  const snackbarController = core.useSnackbarController();
1152
1509
  const {
1153
1510
  user: loggedInUser
@@ -1158,173 +1515,331 @@
1158
1515
  roles
1159
1516
  } = useUserManagement();
1160
1517
  const isNewUser = !userProp;
1161
- const onUserUpdated = React.useCallback((savedUser) => {
1162
- if (!loggedInUser) {
1163
- throw new Error("Logged user not found");
1164
- }
1165
- try {
1166
- canUserBeEdited(loggedInUser, savedUser, users, roles, userProp);
1167
- return saveUser(savedUser);
1168
- } catch (e) {
1169
- return Promise.reject(e);
1170
- }
1171
- }, [roles, saveUser, userProp, users, loggedInUser]);
1172
- const formex$1 = formex.useCreateFormex({
1173
- 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 ?? {
1174
1545
  displayName: "",
1175
1546
  email: "",
1176
- roles: roles.filter((r) => r.id === "editor")
1177
- },
1178
- validation: (values2) => {
1179
- return UserYupSchema.validate(values2, { abortEarly: false }).then(() => {
1180
- return {};
1181
- }).catch((e) => {
1182
- return e.inner.reduce((acc, error) => {
1183
- acc[error.path] = error.message;
1184
- return acc;
1185
- }, {});
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
1186
1561
  });
1187
- },
1188
- onSubmit: (user, formexController) => {
1189
- return onUserUpdated(user).then(() => {
1190
- handleClose();
1191
- formexController.resetForm({
1192
- values: user
1193
- });
1194
- }).catch((e) => {
1195
- snackbarController.open({
1196
- type: "error",
1197
- message: e.message
1198
- });
1562
+ }).catch((e_1) => {
1563
+ snackbarController.open({
1564
+ type: "error",
1565
+ message: e_1.message
1199
1566
  });
1200
- }
1201
- });
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);
1202
1589
  const {
1203
1590
  isSubmitting,
1204
- touched,
1205
1591
  handleChange,
1206
- values,
1592
+ values: values_0,
1207
1593
  errors,
1208
1594
  setFieldValue,
1209
1595
  dirty,
1210
1596
  handleSubmit,
1211
1597
  submitCount
1212
1598
  } = formex$1;
1213
- return /* @__PURE__ */ jsxRuntime.jsx(
1214
- ui.Dialog,
1215
- {
1216
- open,
1217
- onOpenChange: (open2) => !open2 ? handleClose() : void 0,
1218
- maxWidth: "4xl",
1219
- children: /* @__PURE__ */ jsxRuntime.jsx(formex.Formex, { value: formex$1, children: /* @__PURE__ */ jsxRuntime.jsxs(
1220
- "form",
1221
- {
1222
- onSubmit: handleSubmit,
1223
- autoComplete: "off",
1224
- noValidate: true,
1225
- style: {
1226
- display: "flex",
1227
- flexDirection: "column",
1228
- position: "relative",
1229
- height: "100%"
1230
- },
1231
- children: [
1232
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogContent, { className: "h-full flex-grow", children: [
1233
- /* @__PURE__ */ jsxRuntime.jsx(
1234
- "div",
1235
- {
1236
- className: "flex flex-row pt-4 pb-4",
1237
- children: /* @__PURE__ */ jsxRuntime.jsx(
1238
- ui.Typography,
1239
- {
1240
- variant: "h4",
1241
- className: "flex-grow",
1242
- children: "User"
1243
- }
1244
- )
1245
- }
1246
- ),
1247
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-12 gap-8", children: [
1248
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1249
- /* @__PURE__ */ jsxRuntime.jsx(
1250
- ui.TextField,
1251
- {
1252
- name: "displayName",
1253
- required: true,
1254
- error: submitCount > 0 && Boolean(errors.displayName),
1255
- value: values.displayName ?? "",
1256
- onChange: handleChange,
1257
- "aria-describedby": "name-helper-text",
1258
- label: "Name"
1259
- }
1260
- ),
1261
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.displayName) ? errors.displayName : "Name of this user" })
1262
- ] }),
1263
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "col-span-12", children: [
1264
- /* @__PURE__ */ jsxRuntime.jsx(
1265
- ui.TextField,
1266
- {
1267
- required: true,
1268
- error: submitCount > 0 && Boolean(errors.email),
1269
- name: "email",
1270
- value: values.email ?? "",
1271
- onChange: handleChange,
1272
- "aria-describedby": "email-helper-text",
1273
- label: "Email"
1274
- }
1275
- ),
1276
- /* @__PURE__ */ jsxRuntime.jsx(core.FieldCaption, { children: submitCount > 0 && Boolean(errors.email) ? errors.email : "Email of this user" })
1277
- ] }),
1278
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "col-span-12", children: /* @__PURE__ */ jsxRuntime.jsx(
1279
- ui.MultiSelect,
1280
- {
1281
- className: "w-full",
1282
- label: "Roles",
1283
- value: values.roles?.map((r) => r.id) ?? [],
1284
- onValueChange: (value) => setFieldValue("roles", value.map((id) => roles.find((r) => r.id === id))),
1285
- children: roles.map((userRole) => /* @__PURE__ */ jsxRuntime.jsx(
1286
- ui.MultiSelectItem,
1287
- {
1288
- value: userRole.id,
1289
- children: /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1290
- },
1291
- userRole.id
1292
- ))
1293
- }
1294
- ) })
1295
- ] })
1296
- ] }),
1297
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DialogActions, { children: [
1298
- /* @__PURE__ */ jsxRuntime.jsx(
1299
- ui.Button,
1300
- {
1301
- variant: "text",
1302
- onClick: () => {
1303
- handleClose();
1304
- },
1305
- children: "Cancel"
1306
- }
1307
- ),
1308
- /* @__PURE__ */ jsxRuntime.jsx(
1309
- ui.LoadingButton,
1310
- {
1311
- variant: "filled",
1312
- color: "primary",
1313
- type: "submit",
1314
- disabled: !dirty,
1315
- loading: isSubmitting,
1316
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.DoneIcon, {}),
1317
- children: isNewUser ? "Create user" : "Update"
1318
- }
1319
- )
1320
- ] })
1321
- ]
1322
- }
1323
- ) })
1324
- }
1325
- );
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.CheckIcon, {});
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;
1326
1819
  }
1327
- function UsersTable({ onUserClicked }) {
1820
+ function _temp5(values) {
1821
+ return UserYupSchema.validate(values, {
1822
+ abortEarly: false
1823
+ }).then(_temp2).catch(_temp4);
1824
+ }
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;
1328
1843
  const {
1329
1844
  users,
1330
1845
  saveUser,
@@ -1337,275 +1852,438 @@
1337
1852
  const dateFormat = customizationController?.dateTimeFormat ?? core.defaultDateFormat;
1338
1853
  const [userToBeDeleted, setUserToBeDeleted] = React.useState(void 0);
1339
1854
  const [deleteInProgress, setDeleteInProgress] = React.useState(false);
1340
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "overflow-auto", children: [
1341
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { className: "w-full", children: [
1342
- /* @__PURE__ */ jsxRuntime.jsxs(ui.TableHeader, { children: [
1343
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "truncate w-16" }),
1344
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "ID" }),
1345
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Email" }),
1346
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Name" }),
1347
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Roles" }),
1348
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: "Created on" })
1349
- ] }),
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,
1350
1941
  /* @__PURE__ */ jsxRuntime.jsxs(ui.TableBody, { children: [
1351
- users && users.map((user) => {
1352
- const userRoles = user.roles;
1353
- const formattedDate = user.created_on ? dateFns.format(user.created_on, dateFormat, { locale: dateUtilsLocale }) : "";
1354
- return /* @__PURE__ */ jsxRuntime.jsxs(
1355
- ui.TableRow,
1356
- {
1357
- onClick: () => {
1358
- onUserClicked(user);
1359
- },
1360
- children: [
1361
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "w-10", children: /* @__PURE__ */ jsxRuntime.jsx(
1362
- ui.Tooltip,
1363
- {
1364
- asChild: true,
1365
- title: "Delete this user",
1366
- children: /* @__PURE__ */ jsxRuntime.jsx(
1367
- ui.IconButton,
1368
- {
1369
- size: "small",
1370
- onClick: (event) => {
1371
- event.stopPropagation();
1372
- return setUserToBeDeleted(user);
1373
- },
1374
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.DeleteIcon, {})
1375
- }
1376
- )
1377
- }
1378
- ) }),
1379
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.uid }),
1380
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: user.email }),
1381
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "font-medium align-left", children: user.displayName }),
1382
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { className: "align-left", children: userRoles ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: userRoles.map(
1383
- (userRole) => /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id)
1384
- ) }) : null }),
1385
- /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: formattedDate })
1386
- ]
1387
- },
1388
- "row_" + user.uid
1389
- );
1390
- }),
1391
- (!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: [
1392
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "label", children: "There are no users yet" }),
1393
- /* @__PURE__ */ jsxRuntime.jsx(
1394
- ui.Button,
1395
- {
1396
- variant: "outlined",
1397
- onClick: () => {
1398
- if (!authController.user?.uid) {
1399
- throw Error("UsersTable, authController misconfiguration");
1400
- }
1401
- saveUser({
1402
- uid: authController.user?.uid,
1403
- email: authController.user?.email,
1404
- displayName: authController.user?.displayName,
1405
- photoURL: authController.user?.photoURL,
1406
- providerId: authController.user?.providerId,
1407
- isAnonymous: authController.user?.isAnonymous,
1408
- roles: [{ id: "admin", name: "Admin" }],
1409
- created_on: /* @__PURE__ */ new Date()
1410
- }).then(() => {
1411
- snackbarController.open({
1412
- type: "success",
1413
- message: "User added successfully"
1414
- });
1415
- }).catch((error) => {
1416
- snackbarController.open({
1417
- type: "error",
1418
- message: "Error adding user: " + error.message
1419
- });
1420
- });
1421
- },
1422
- children: "Add the logged user as an admin"
1423
- }
1424
- )
1425
- ] }) }) })
1942
+ t2,
1943
+ t3
1426
1944
  ] })
1427
- ] }),
1428
- /* @__PURE__ */ jsxRuntime.jsx(
1429
- core.ConfirmationDialog,
1430
- {
1431
- open: Boolean(userToBeDeleted),
1432
- loading: deleteInProgress,
1433
- onAccept: () => {
1434
- if (userToBeDeleted) {
1435
- setDeleteInProgress(true);
1436
- deleteUser(userToBeDeleted).then(() => {
1437
- setUserToBeDeleted(void 0);
1438
- }).catch((error) => {
1439
- snackbarController.open({
1440
- type: "error",
1441
- message: "Error deleting user: " + error.message
1442
- });
1443
- }).finally(() => {
1444
- setDeleteInProgress(false);
1445
- });
1446
- }
1447
- },
1448
- 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(() => {
1449
1959
  setUserToBeDeleted(void 0);
1450
- },
1451
- title: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Delete?" }),
1452
- 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
+ });
1453
1968
  }
1454
- )
1455
- ] });
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;
2017
+ }
2018
+ function _temp(userRole) {
2019
+ return /* @__PURE__ */ jsxRuntime.jsx(RoleChip, { role: userRole }, userRole?.id);
1456
2020
  }
1457
- const UsersView = function UsersView2({ children }) {
2021
+ const UsersView = function UsersView2(t0) {
2022
+ const $ = reactCompilerRuntime.c(16);
2023
+ const {
2024
+ children
2025
+ } = t0;
1458
2026
  const [dialogOpen, setDialogOpen] = React.useState();
1459
2027
  const [selectedUser, setSelectedUser] = React.useState();
1460
- const { users, usersLimit } = useUserManagement();
1461
- const reachedUsersLimit = usersLimit !== void 0 && (users && users.length >= usersLimit);
1462
- const onUserClicked = React.useCallback((user) => {
1463
- setSelectedUser(user);
1464
- setDialogOpen(true);
1465
- }, []);
1466
- const handleClose = React.useCallback(() => {
1467
- setDialogOpen(false);
1468
- setSelectedUser(void 0);
1469
- }, []);
1470
- return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
1471
- children,
1472
- /* @__PURE__ */ jsxRuntime.jsxs(
1473
- "div",
1474
- {
1475
- className: "flex items-center mt-12",
1476
- children: [
1477
- /* @__PURE__ */ jsxRuntime.jsx(
1478
- ui.Typography,
1479
- {
1480
- gutterBottom: true,
1481
- variant: "h4",
1482
- className: "flex-grow",
1483
- component: "h4",
1484
- children: "Users"
1485
- }
1486
- ),
1487
- /* @__PURE__ */ jsxRuntime.jsx(
1488
- ui.Button,
1489
- {
1490
- size: "large",
1491
- disabled: reachedUsersLimit,
1492
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1493
- onClick: () => setDialogOpen(true),
1494
- children: "Add user"
1495
- }
1496
- )
1497
- ]
1498
- }
1499
- ),
1500
- /* @__PURE__ */ jsxRuntime.jsx(UsersTable, { onUserClicked }),
1501
- /* @__PURE__ */ jsxRuntime.jsx(
1502
- UserDetailsForm,
1503
- {
1504
- open: dialogOpen ?? false,
1505
- user: selectedUser,
1506
- handleClose
1507
- },
1508
- selectedUser?.uid ?? "new"
1509
- )
1510
- ] });
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;
1511
2119
  };
1512
- function useUserManagementPlugin({ userManagement }) {
2120
+ function useUserManagementPlugin(t0) {
2121
+ const $ = reactCompilerRuntime.c(12);
2122
+ const {
2123
+ userManagement
2124
+ } = t0;
1513
2125
  const noUsers = userManagement.users.length === 0;
1514
2126
  const noRoles = userManagement.roles.length === 0;
1515
- return {
1516
- key: "user_management",
1517
- loading: userManagement.loading,
1518
- homePage: {
1519
- additionalChildrenStart: noUsers || noRoles ? /* @__PURE__ */ jsxRuntime.jsx(
1520
- IntroWidget,
1521
- {
1522
- noUsers,
1523
- noRoles,
1524
- userManagement
1525
- }
1526
- ) : void 0
1527
- },
1528
- 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 = {
1529
2150
  Component: UserManagementProvider,
1530
2151
  props: {
1531
2152
  userManagement
1532
2153
  }
1533
- }
1534
- };
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;
1535
2176
  }
1536
- function IntroWidget({
1537
- noUsers,
1538
- noRoles,
1539
- userManagement
1540
- }) {
2177
+ function IntroWidget(t0) {
2178
+ const $ = reactCompilerRuntime.c(17);
2179
+ const {
2180
+ noUsers,
2181
+ noRoles,
2182
+ userManagement
2183
+ } = t0;
1541
2184
  const authController = core.useAuthController();
1542
2185
  const snackbarController = core.useSnackbarController();
1543
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;
1544
- return /* @__PURE__ */ jsxRuntime.jsxs(
1545
- ui.Paper,
1546
- {
1547
- className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-slate-800 gap-2",
1548
- children: [
1549
- /* @__PURE__ */ jsxRuntime.jsx(ui.Typography, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" }),
1550
- /* @__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." }),
1551
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { onClick: () => {
1552
- if (!authController.user?.uid) {
1553
- throw Error("UsersTable, authController misconfiguration");
1554
- }
1555
- if (noUsers) {
1556
- userManagement.saveUser({
1557
- uid: authController.user?.uid,
1558
- email: authController.user?.email,
1559
- displayName: authController.user?.displayName,
1560
- photoURL: authController.user?.photoURL,
1561
- providerId: authController.user?.providerId,
1562
- isAnonymous: authController.user?.isAnonymous,
1563
- roles: [{
1564
- id: "admin",
1565
- name: "Admin"
1566
- }],
1567
- created_on: /* @__PURE__ */ new Date()
1568
- }).then(() => {
1569
- snackbarController.open({
1570
- type: "success",
1571
- message: "User added successfully"
1572
- });
1573
- }).catch((error) => {
1574
- snackbarController.open({
1575
- type: "error",
1576
- message: "Error adding user: " + error.message
1577
- });
1578
- });
1579
- }
1580
- if (noRoles) {
1581
- DEFAULT_ROLES.forEach((role) => {
1582
- userManagement.saveRole(role);
1583
- });
1584
- }
1585
- }, children: [
1586
- /* @__PURE__ */ jsxRuntime.jsx(ui.AddIcon, {}),
1587
- buttonLabel
1588
- ] })
1589
- ]
1590
- }
1591
- );
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;
1592
2273
  }
1593
- const userManagementAdminViews = [
1594
- {
1595
- path: "users",
1596
- name: "CMS Users",
1597
- group: "Admin",
1598
- icon: "face",
1599
- view: /* @__PURE__ */ jsxRuntime.jsx(UsersView, {})
1600
- },
1601
- {
1602
- path: "roles",
1603
- name: "Roles",
1604
- group: "Admin",
1605
- icon: "gpp_good",
1606
- view: /* @__PURE__ */ jsxRuntime.jsx(RolesView, {})
1607
- }
1608
- ];
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
+ }];
1609
2287
  exports2.IntroWidget = IntroWidget;
1610
2288
  exports2.RESERVED_GROUPS = RESERVED_GROUPS;
1611
2289
  exports2.RoleChip = RoleChip;