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

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