@firecms/user_management 3.0.0-canary.113 → 3.0.0-canary.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useCallback, useContext, useState } from "react";
2
2
  import equal from "react-fast-compare";
3
3
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
4
- import { getColorSchemeForSeed, Chip, Dialog, DialogContent, Typography, TextField, Paper, Table, TableHeader, TableCell, TableBody, TableRow, Tooltip, Checkbox, Select, SelectItem, DialogActions, Button, LoadingButton, DoneIcon, IconButton, DeleteIcon, CenteredView, Container, AddIcon, MultiSelect, MultiSelectItem } from "@firecms/ui";
4
+ import { getColorSchemeForSeed, Chip, Dialog, DialogContent, Typography, TextField, Paper, Table, TableHeader, TableCell, TableBody, TableRow, Tooltip, Checkbox, Button, Select, SelectItem, DialogActions, LoadingButton, DoneIcon, IconButton, DeleteIcon, CenteredView, Container, AddIcon, MultiSelect, MultiSelectItem } from "@firecms/ui";
5
5
  import * as Yup from "yup";
6
6
  import { toSnakeCase, FieldCaption, DeleteConfirmationDialog, useNavigationController, useSnackbarController, useAuthController, useCustomizationController, defaultDateFormat } from "@firecms/core";
7
7
  import { useCreateFormex, getIn, Formex } from "@firecms/formex";
@@ -217,28 +217,18 @@ function useBuildUserManagement({
217
217
  if (!usersPath) throw Error("useBuildUserManagement Firestore not initialised");
218
218
  console.debug("Persisting user", user);
219
219
  const roleIds = user.roles?.map((r) => r.id);
220
- const {
221
- uid,
222
- ...userData
223
- } = user;
220
+ const email = user.email?.toLowerCase().trim();
221
+ if (!email) throw Error("Email is required");
224
222
  const data = {
225
- ...userData,
223
+ ...user,
226
224
  roles: roleIds
227
225
  };
228
- if (uid) {
229
- return dataSourceDelegate.saveEntity({
230
- status: "existing",
231
- path: usersPath,
232
- entityId: uid,
233
- values: data
234
- }).then(() => user);
235
- } else {
236
- return dataSourceDelegate.saveEntity({
237
- status: "new",
238
- path: usersPath,
239
- values: data
240
- }).then(() => user);
241
- }
226
+ return dataSourceDelegate.saveEntity({
227
+ status: "existing",
228
+ path: usersPath,
229
+ entityId: email,
230
+ values: data
231
+ }).then(() => user);
242
232
  }, [usersPath, dataSourceDelegate?.initialised]);
243
233
  const saveRole = useCallback((role) => {
244
234
  if (!dataSourceDelegate) throw Error("useBuildUserManagement Firebase not initialised");
@@ -506,201 +496,234 @@ function RolesDetailsForm({
506
496
  /* @__PURE__ */ jsx(FieldCaption, { children: touched.id && Boolean(errors.id) ? errors.id : "ID of this role" })
507
497
  ] }),
508
498
  /* @__PURE__ */ jsxs("div", { className: "col-span-12", children: [
509
- /* @__PURE__ */ jsx(
510
- Paper,
511
- {
512
- className: "bg-inherit",
513
- children: /* @__PURE__ */ jsxs(Table, { children: [
514
- /* @__PURE__ */ jsxs(TableHeader, { children: [
515
- /* @__PURE__ */ jsx(TableCell, {}),
516
- /* @__PURE__ */ jsx(
517
- TableCell,
518
- {
519
- align: "center",
520
- children: "Create entities"
521
- }
522
- ),
523
- /* @__PURE__ */ jsx(
524
- TableCell,
525
- {
526
- align: "center",
527
- children: "Read entities"
528
- }
529
- ),
530
- /* @__PURE__ */ jsx(
531
- TableCell,
532
- {
533
- align: "center",
534
- children: "Update entities"
535
- }
536
- ),
537
- /* @__PURE__ */ jsx(
538
- TableCell,
539
- {
540
- align: "center",
541
- children: "Delete entities"
542
- }
543
- )
544
- ] }),
545
- /* @__PURE__ */ jsxs(TableBody, { children: [
546
- /* @__PURE__ */ jsxs(TableRow, { children: [
547
- /* @__PURE__ */ jsx(
548
- TableCell,
549
- {
550
- scope: "row",
551
- children: /* @__PURE__ */ jsx("strong", { children: "All collections" })
552
- }
553
- ),
554
- /* @__PURE__ */ jsx(
555
- TableCell,
499
+ /* @__PURE__ */ jsx(Paper, { className: "bg-inherit overflow-hidden", children: /* @__PURE__ */ jsxs(Table, { className: "w-full rounded-md", children: [
500
+ /* @__PURE__ */ jsxs(TableHeader, { className: "rounded-md", children: [
501
+ /* @__PURE__ */ jsx(TableCell, {}),
502
+ /* @__PURE__ */ jsx(
503
+ TableCell,
504
+ {
505
+ align: "center",
506
+ children: "Create entities"
507
+ }
508
+ ),
509
+ /* @__PURE__ */ jsx(
510
+ TableCell,
511
+ {
512
+ align: "center",
513
+ children: "Read entities"
514
+ }
515
+ ),
516
+ /* @__PURE__ */ jsx(
517
+ TableCell,
518
+ {
519
+ align: "center",
520
+ children: "Update entities"
521
+ }
522
+ ),
523
+ /* @__PURE__ */ jsx(
524
+ TableCell,
525
+ {
526
+ align: "center",
527
+ children: "Delete entities"
528
+ }
529
+ ),
530
+ /* @__PURE__ */ jsx(
531
+ TableCell,
532
+ {
533
+ align: "center"
534
+ }
535
+ )
536
+ ] }),
537
+ /* @__PURE__ */ jsxs(TableBody, { children: [
538
+ /* @__PURE__ */ jsxs(TableRow, { children: [
539
+ /* @__PURE__ */ jsx(
540
+ TableCell,
541
+ {
542
+ scope: "row",
543
+ children: /* @__PURE__ */ jsx("strong", { children: "All collections" })
544
+ }
545
+ ),
546
+ /* @__PURE__ */ jsx(
547
+ TableCell,
548
+ {
549
+ align: "center",
550
+ children: /* @__PURE__ */ jsx(
551
+ Tooltip,
556
552
  {
557
- align: "center",
553
+ title: "Create entities in collections",
558
554
  children: /* @__PURE__ */ jsx(
559
- Tooltip,
555
+ Checkbox,
560
556
  {
561
- title: "Create entities in collections",
562
- children: /* @__PURE__ */ jsx(
563
- Checkbox,
564
- {
565
- disabled: isAdmin || !editable,
566
- checked: (isAdmin || defaultCreate) ?? false,
567
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.create", checked)
568
- }
569
- )
557
+ disabled: isAdmin || !editable,
558
+ checked: (isAdmin || defaultCreate) ?? false,
559
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.create", checked)
570
560
  }
571
561
  )
572
562
  }
573
- ),
574
- /* @__PURE__ */ jsx(
575
- TableCell,
563
+ )
564
+ }
565
+ ),
566
+ /* @__PURE__ */ jsx(
567
+ TableCell,
568
+ {
569
+ align: "center",
570
+ children: /* @__PURE__ */ jsx(
571
+ Tooltip,
576
572
  {
577
- align: "center",
573
+ title: "Access all data in every collection",
578
574
  children: /* @__PURE__ */ jsx(
579
- Tooltip,
575
+ Checkbox,
580
576
  {
581
- title: "Access all data in every collection",
582
- children: /* @__PURE__ */ jsx(
583
- Checkbox,
584
- {
585
- disabled: isAdmin || !editable,
586
- checked: (isAdmin || defaultRead) ?? false,
587
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.read", checked)
588
- }
589
- )
577
+ disabled: isAdmin || !editable,
578
+ checked: (isAdmin || defaultRead) ?? false,
579
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.read", checked)
590
580
  }
591
581
  )
592
582
  }
593
- ),
594
- /* @__PURE__ */ jsx(
595
- TableCell,
583
+ )
584
+ }
585
+ ),
586
+ /* @__PURE__ */ jsx(
587
+ TableCell,
588
+ {
589
+ align: "center",
590
+ children: /* @__PURE__ */ jsx(
591
+ Tooltip,
596
592
  {
597
- align: "center",
593
+ title: "Update data in any collection",
598
594
  children: /* @__PURE__ */ jsx(
599
- Tooltip,
595
+ Checkbox,
600
596
  {
601
- title: "Update data in any collection",
602
- children: /* @__PURE__ */ jsx(
603
- Checkbox,
604
- {
605
- disabled: isAdmin || !editable,
606
- checked: (isAdmin || defaultEdit) ?? false,
607
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.edit", checked)
608
- }
609
- )
597
+ disabled: isAdmin || !editable,
598
+ checked: (isAdmin || defaultEdit) ?? false,
599
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.edit", checked)
610
600
  }
611
601
  )
612
602
  }
613
- ),
614
- /* @__PURE__ */ jsx(
615
- TableCell,
603
+ )
604
+ }
605
+ ),
606
+ /* @__PURE__ */ jsx(
607
+ TableCell,
608
+ {
609
+ align: "center",
610
+ children: /* @__PURE__ */ jsx(
611
+ Tooltip,
616
612
  {
617
- align: "center",
613
+ title: "Delete data in any collection",
618
614
  children: /* @__PURE__ */ jsx(
619
- Tooltip,
615
+ Checkbox,
620
616
  {
621
- title: "Delete data in any collection",
622
- children: /* @__PURE__ */ jsx(
623
- Checkbox,
624
- {
625
- disabled: isAdmin || !editable,
626
- checked: (isAdmin || defaultDelete) ?? false,
627
- onCheckedChange: (checked) => setFieldValue("defaultPermissions.delete", checked)
628
- }
629
- )
617
+ disabled: isAdmin || !editable,
618
+ checked: (isAdmin || defaultDelete) ?? false,
619
+ onCheckedChange: (checked) => setFieldValue("defaultPermissions.delete", checked)
630
620
  }
631
621
  )
632
622
  }
633
623
  )
634
- ] }),
635
- collections && collections.map((col) => /* @__PURE__ */ jsxs(TableRow, { children: [
636
- /* @__PURE__ */ jsx(
637
- TableCell,
624
+ }
625
+ ),
626
+ /* @__PURE__ */ jsx(
627
+ TableCell,
628
+ {
629
+ align: "center"
630
+ }
631
+ )
632
+ ] }),
633
+ collections && collections.map((col) => /* @__PURE__ */ jsxs(TableRow, { children: [
634
+ /* @__PURE__ */ jsx(
635
+ TableCell,
636
+ {
637
+ scope: "row",
638
+ children: col.name
639
+ }
640
+ ),
641
+ /* @__PURE__ */ jsx(
642
+ TableCell,
643
+ {
644
+ align: "center",
645
+ children: /* @__PURE__ */ jsx(
646
+ Checkbox,
638
647
  {
639
- scope: "row",
640
- children: col.name
648
+ disabled: isAdmin || defaultCreate || !editable,
649
+ checked: (isAdmin || defaultCreate || getIn(values, `collectionPermissions.${col.path}.create`)) ?? false,
650
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.create`, checked)
641
651
  }
642
- ),
643
- /* @__PURE__ */ jsx(
644
- TableCell,
652
+ )
653
+ }
654
+ ),
655
+ /* @__PURE__ */ jsx(
656
+ TableCell,
657
+ {
658
+ align: "center",
659
+ children: /* @__PURE__ */ jsx(
660
+ Checkbox,
645
661
  {
646
- align: "center",
647
- children: /* @__PURE__ */ jsx(
648
- Checkbox,
649
- {
650
- disabled: isAdmin || defaultCreate || !editable,
651
- checked: (isAdmin || defaultCreate || getIn(values, `collectionPermissions.${col.path}.create`)) ?? false,
652
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.create`, checked)
653
- }
654
- )
662
+ disabled: isAdmin || defaultRead || !editable,
663
+ checked: (isAdmin || defaultRead || getIn(values, `collectionPermissions.${col.path}.read`)) ?? false,
664
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.read`, checked)
655
665
  }
656
- ),
657
- /* @__PURE__ */ jsx(
658
- TableCell,
666
+ )
667
+ }
668
+ ),
669
+ /* @__PURE__ */ jsx(
670
+ TableCell,
671
+ {
672
+ align: "center",
673
+ children: /* @__PURE__ */ jsx(
674
+ Checkbox,
659
675
  {
660
- align: "center",
661
- children: /* @__PURE__ */ jsx(
662
- Checkbox,
663
- {
664
- disabled: isAdmin || defaultRead || !editable,
665
- checked: (isAdmin || defaultRead || getIn(values, `collectionPermissions.${col.path}.read`)) ?? false,
666
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.read`, checked)
667
- }
668
- )
676
+ disabled: isAdmin || defaultEdit || !editable,
677
+ checked: (isAdmin || defaultEdit || getIn(values, `collectionPermissions.${col.path}.edit`)) ?? false,
678
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.edit`, checked)
669
679
  }
670
- ),
671
- /* @__PURE__ */ jsx(
672
- TableCell,
680
+ )
681
+ }
682
+ ),
683
+ /* @__PURE__ */ jsx(
684
+ TableCell,
685
+ {
686
+ align: "center",
687
+ children: /* @__PURE__ */ jsx(
688
+ Checkbox,
673
689
  {
674
- align: "center",
675
- children: /* @__PURE__ */ jsx(
676
- Checkbox,
677
- {
678
- disabled: isAdmin || defaultEdit || !editable,
679
- checked: (isAdmin || defaultEdit || getIn(values, `collectionPermissions.${col.path}.edit`)) ?? false,
680
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.edit`, checked)
681
- }
682
- )
690
+ disabled: isAdmin || defaultDelete || !editable,
691
+ checked: (isAdmin || defaultDelete || getIn(values, `collectionPermissions.${col.path}.delete`)) ?? false,
692
+ onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.delete`, checked)
683
693
  }
684
- ),
685
- /* @__PURE__ */ jsx(
686
- TableCell,
694
+ )
695
+ }
696
+ ),
697
+ /* @__PURE__ */ jsx(
698
+ TableCell,
699
+ {
700
+ align: "center",
701
+ children: /* @__PURE__ */ jsx(
702
+ Tooltip,
687
703
  {
688
- align: "center",
704
+ title: "Allow all permissions in this collections",
689
705
  children: /* @__PURE__ */ jsx(
690
- Checkbox,
706
+ Button,
691
707
  {
692
- disabled: isAdmin || defaultDelete || !editable,
693
- checked: (isAdmin || defaultDelete || getIn(values, `collectionPermissions.${col.path}.delete`)) ?? false,
694
- onCheckedChange: (checked) => setFieldValue(`collectionPermissions.${col.path}.delete`, checked)
708
+ className: "color-inherit",
709
+ onClick: () => {
710
+ setFieldValue(`collectionPermissions.${col.path}.create`, true);
711
+ setFieldValue(`collectionPermissions.${col.path}.read`, true);
712
+ setFieldValue(`collectionPermissions.${col.path}.edit`, true);
713
+ setFieldValue(`collectionPermissions.${col.path}.delete`, true);
714
+ },
715
+ disabled: isAdmin || !editable,
716
+ variant: "text",
717
+ children: "All"
695
718
  }
696
719
  )
697
720
  }
698
721
  )
699
- ] }, col.name))
700
- ] })
701
- ] })
702
- }
703
- ),
722
+ }
723
+ )
724
+ ] }, col.name))
725
+ ] })
726
+ ] }) }),
704
727
  /* @__PURE__ */ jsx(FieldCaption, { children: "You can customise the permissions that the users related to this role can perform in the entities of each collection" })
705
728
  ] }),
706
729
  /* @__PURE__ */ jsxs("div", { className: "col-span-12 md:col-span-4", children: [