@strapi/plugin-users-permissions 4.20.5 → 5.0.0-alpha.1

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.
Files changed (112) hide show
  1. package/admin/src/components/FormModal/index.jsx +1 -2
  2. package/admin/src/components/Permissions/reducer.js +1 -1
  3. package/admin/src/components/UsersPermissions/reducer.js +1 -1
  4. package/admin/src/index.js +15 -32
  5. package/admin/src/pages/AdvancedSettings/index.jsx +72 -112
  6. package/admin/src/pages/AdvancedSettings/utils/layout.js +20 -35
  7. package/admin/src/pages/AdvancedSettings/utils/schema.js +5 -2
  8. package/admin/src/pages/EmailTemplates/components/EmailForm.jsx +47 -74
  9. package/admin/src/pages/EmailTemplates/components/EmailTable.jsx +4 -5
  10. package/admin/src/pages/EmailTemplates/index.jsx +25 -55
  11. package/admin/src/pages/EmailTemplates/utils/schema.js +18 -6
  12. package/admin/src/pages/Providers/index.jsx +91 -108
  13. package/admin/src/pages/Providers/utils/forms.js +11 -11
  14. package/admin/src/pages/Roles/constants.js +3 -3
  15. package/admin/src/pages/Roles/hooks/usePlugins.js +4 -4
  16. package/admin/src/pages/Roles/index.jsx +9 -18
  17. package/admin/src/pages/Roles/pages/CreatePage.jsx +20 -28
  18. package/admin/src/pages/Roles/pages/EditPage.jsx +25 -37
  19. package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +23 -28
  20. package/admin/src/pages/Roles/pages/ListPage/index.jsx +73 -42
  21. package/admin/src/translations/en.json +1 -1
  22. package/admin/src/utils/prefixPluginTranslations.js +13 -0
  23. package/dist/_chunks/EditViewPage-kgrZ8rEg-6k5dfk_x.js +84412 -0
  24. package/dist/_chunks/EditViewPage-kgrZ8rEg-6k5dfk_x.js.map +1 -0
  25. package/dist/_chunks/EditViewPage-kgrZ8rEg-GlayP0Uq.mjs +84382 -0
  26. package/dist/_chunks/EditViewPage-kgrZ8rEg-GlayP0Uq.mjs.map +1 -0
  27. package/dist/_chunks/Helmet-d9JljxUo.js +1010 -0
  28. package/dist/_chunks/Helmet-d9JljxUo.js.map +1 -0
  29. package/dist/_chunks/Helmet-kyJ1Zklj.mjs +1008 -0
  30. package/dist/_chunks/Helmet-kyJ1Zklj.mjs.map +1 -0
  31. package/dist/_chunks/ListViewPage-BNB0ptO7-TUQO_9Hj.js +1617 -0
  32. package/dist/_chunks/ListViewPage-BNB0ptO7-TUQO_9Hj.js.map +1 -0
  33. package/dist/_chunks/ListViewPage-BNB0ptO7-t1ra9JlI.mjs +1594 -0
  34. package/dist/_chunks/ListViewPage-BNB0ptO7-t1ra9JlI.mjs.map +1 -0
  35. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-3Dq1lGu9.js +33 -0
  36. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-3Dq1lGu9.js.map +1 -0
  37. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-mpkuW-HV.mjs +33 -0
  38. package/dist/_chunks/ReviewWorkflowsColumn-56Z6l-FH-mpkuW-HV.mjs.map +1 -0
  39. package/dist/_chunks/constants-evLWZCaJ-0QLv9QPI.mjs +190 -0
  40. package/dist/_chunks/constants-evLWZCaJ-0QLv9QPI.mjs.map +1 -0
  41. package/dist/_chunks/constants-evLWZCaJ-dGs71EWl.js +209 -0
  42. package/dist/_chunks/constants-evLWZCaJ-dGs71EWl.js.map +1 -0
  43. package/dist/_chunks/{en-m608rMZx.js → en-TaNIVnDO.js} +2 -2
  44. package/dist/_chunks/en-TaNIVnDO.js.map +1 -0
  45. package/dist/_chunks/{en-CE3wEy_c.mjs → en-jvJ-d-Qq.mjs} +2 -2
  46. package/dist/_chunks/en-jvJ-d-Qq.mjs.map +1 -0
  47. package/dist/_chunks/{index-XqdaO5WZ.js → index-6E51D69B.js} +149 -149
  48. package/dist/_chunks/index-6E51D69B.js.map +1 -0
  49. package/dist/_chunks/index-BGIcvvEB.mjs +260 -0
  50. package/dist/_chunks/index-BGIcvvEB.mjs.map +1 -0
  51. package/dist/_chunks/{index-6Kdo3KXv.js → index-Bg2Rf_5y.js} +112 -154
  52. package/dist/_chunks/index-Bg2Rf_5y.js.map +1 -0
  53. package/dist/_chunks/index-LpFmy25n.js +279 -0
  54. package/dist/_chunks/index-LpFmy25n.js.map +1 -0
  55. package/dist/_chunks/{index-a9oKDd3C.mjs → index-R05CeNXG.mjs} +106 -148
  56. package/dist/_chunks/index-R05CeNXG.mjs.map +1 -0
  57. package/dist/_chunks/index-YFPS5vYF-ZGkR3L1g.js +16558 -0
  58. package/dist/_chunks/index-YFPS5vYF-ZGkR3L1g.js.map +1 -0
  59. package/dist/_chunks/index-YFPS5vYF-cugkJcLS.mjs +16533 -0
  60. package/dist/_chunks/index-YFPS5vYF-cugkJcLS.mjs.map +1 -0
  61. package/dist/_chunks/{index-ethhTEkj.mjs → index-aEKi1Qb9.mjs} +39 -36
  62. package/dist/_chunks/index-aEKi1Qb9.mjs.map +1 -0
  63. package/dist/_chunks/{index-rryiT0-Z.mjs → index-hG66XSuA.mjs} +131 -130
  64. package/dist/_chunks/index-hG66XSuA.mjs.map +1 -0
  65. package/dist/_chunks/{index-iNtwnT3f.mjs → index-xt3l4qU9.mjs} +35 -35
  66. package/dist/_chunks/index-xt3l4qU9.mjs.map +1 -0
  67. package/dist/_chunks/{index-O9AAUvyy.js → index-yKMi8hKt.js} +36 -36
  68. package/dist/_chunks/index-yKMi8hKt.js.map +1 -0
  69. package/dist/_chunks/{index-1uupZmu0.js → index-ylhaoJtw.js} +43 -40
  70. package/dist/_chunks/index-ylhaoJtw.js.map +1 -0
  71. package/dist/_chunks/useSyncRbac-83vFRiaG-YY4KQcAU.js +57 -0
  72. package/dist/_chunks/useSyncRbac-83vFRiaG-YY4KQcAU.js.map +1 -0
  73. package/dist/_chunks/useSyncRbac-83vFRiaG-ov11t-T1.mjs +39 -0
  74. package/dist/_chunks/useSyncRbac-83vFRiaG-ov11t-T1.mjs.map +1 -0
  75. package/dist/admin/index.js +1 -2
  76. package/dist/admin/index.js.map +1 -1
  77. package/dist/admin/index.mjs +1 -2
  78. package/dist/admin/index.mjs.map +1 -1
  79. package/dist/style.css +84 -0
  80. package/package.json +13 -13
  81. package/server/bootstrap/grant-config.js +9 -0
  82. package/server/bootstrap/index.js +2 -39
  83. package/server/content-types/user/index.js +0 -1
  84. package/server/controllers/auth.js +24 -53
  85. package/server/controllers/content-manager-user.js +24 -28
  86. package/server/controllers/role.js +1 -1
  87. package/server/controllers/user.js +5 -5
  88. package/server/middlewares/rateLimit.js +1 -1
  89. package/server/register.js +1 -1
  90. package/server/services/jwt.js +3 -3
  91. package/server/services/permission.js +3 -7
  92. package/server/services/providers-registry.js +15 -0
  93. package/server/services/providers.js +10 -5
  94. package/server/services/role.js +15 -13
  95. package/server/services/user.js +28 -14
  96. package/server/services/users-permissions.js +12 -10
  97. package/server/utils/sanitize/sanitizers.js +2 -2
  98. package/admin/src/pages/Roles/pages/ListPage/utils/api.js +0 -30
  99. package/dist/_chunks/en-CE3wEy_c.mjs.map +0 -1
  100. package/dist/_chunks/en-m608rMZx.js.map +0 -1
  101. package/dist/_chunks/index-1uupZmu0.js.map +0 -1
  102. package/dist/_chunks/index-6Kdo3KXv.js.map +0 -1
  103. package/dist/_chunks/index-O9AAUvyy.js.map +0 -1
  104. package/dist/_chunks/index-Un-J-cxQ.js +0 -320
  105. package/dist/_chunks/index-Un-J-cxQ.js.map +0 -1
  106. package/dist/_chunks/index-X0yw_GgN.mjs +0 -301
  107. package/dist/_chunks/index-X0yw_GgN.mjs.map +0 -1
  108. package/dist/_chunks/index-XqdaO5WZ.js.map +0 -1
  109. package/dist/_chunks/index-a9oKDd3C.mjs.map +0 -1
  110. package/dist/_chunks/index-ethhTEkj.mjs.map +0 -1
  111. package/dist/_chunks/index-iNtwnT3f.mjs.map +0 -1
  112. package/dist/_chunks/index-rryiT0-Z.mjs.map +0 -1
@@ -1,12 +1,13 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { createContext, useContext, useMemo, useCallback, useReducer, forwardRef, useImperativeHandle, memo, useEffect, useState } from "react";
4
- import { translatedErrors, useNotification, useFetchClient, useAPIErrorHandler, CheckPagePermissions, useOverlayBlocker, useTracking, SettingsPageTitle, Form, LoadingIndicatorPage, Link, pxToRem, onRowClick, stopPropagation, CheckPermissions, getFetchClient, useQueryParams, useFocusWhenNavigate, useRBAC, useFilter, useCollator, LinkButton, SearchURLQuery, NoPermissions, EmptyStateLayout, ConfirmDialog, AnErrorOccurred } from "@strapi/helper-plugin";
5
- import { useHistory, useRouteMatch, Switch, Route } from "react-router-dom";
6
- import { g as getTrad, P as PERMISSIONS } from "./index-iNtwnT3f.mjs";
7
- import { Box, Flex, Typography, Checkbox, Grid, GridItem, VisuallyHidden, Accordion, AccordionToggle, AccordionContent, Main, HeaderLayout, Button, ContentLayout, TextInput, Textarea, Link as Link$1, Tbody, Tr, Td, IconButton, useNotifyAT, Layout, ActionLayout, Table, Thead, Th } from "@strapi/design-system";
8
- import { Cog, Check, ArrowLeft, Pencil, Trash, Plus } from "@strapi/icons";
9
- import { Formik } from "formik";
4
+ import { translatedErrors, useNotification, useFetchClient, useAPIErrorHandler, Page, useTracking, BackButton, useQueryParams, SearchInput, ConfirmDialog } from "@strapi/strapi/admin";
5
+ import { useNavigate, useMatch, NavLink, Routes, Route } from "react-router-dom";
6
+ import { g as getTrad, P as PERMISSIONS } from "./index-xt3l4qU9.mjs";
7
+ import { Box, Flex, Typography, Checkbox, Grid, GridItem, VisuallyHidden, Accordion, AccordionToggle, AccordionContent, Main, HeaderLayout, Button, ContentLayout, TextInput, Textarea, Link, Tbody, Tr, Td, IconButton, useNotifyAT, useFilter, useCollator, Layout, ActionLayout, Table, Thead, Th, EmptyStateLayout } from "@strapi/design-system";
8
+ import { Cog, Check, Pencil, Trash, Plus } from "@strapi/icons";
9
+ import { Formik, Form } from "formik";
10
+ import { H as HelmetExport } from "./Helmet-kyJ1Zklj.mjs";
10
11
  import { useIntl } from "react-intl";
11
12
  import { useQueries, useMutation, useQuery } from "react-query";
12
13
  import PropTypes from "prop-types";
@@ -14,7 +15,7 @@ import upperFirst from "lodash/upperFirst";
14
15
  import sortBy from "lodash/sortBy";
15
16
  import get from "lodash/get";
16
17
  import styled, { css } from "styled-components";
17
- import produce from "immer";
18
+ import { produce } from "immer";
18
19
  import isEmpty from "lodash/isEmpty";
19
20
  import without from "lodash/without";
20
21
  import map from "lodash/map";
@@ -22,6 +23,8 @@ import tail from "lodash/tail";
22
23
  import set from "lodash/set";
23
24
  import take from "lodash/take";
24
25
  import * as yup from "yup";
26
+ import { LinkButton } from "@strapi/design-system/v2";
27
+ import { useRBAC } from "@strapi/helper-plugin";
25
28
  const UsersPermissions$2 = createContext({});
26
29
  const UsersPermissionsProvider = ({ children, value }) => {
27
30
  return /* @__PURE__ */ jsx(UsersPermissions$2.Provider, { value, children });
@@ -495,8 +498,8 @@ UsersPermissions.propTypes = {
495
498
  };
496
499
  const UsersPermissions$1 = memo(UsersPermissions);
497
500
  const createRoleSchema = yup.object().shape({
498
- name: yup.string().required(translatedErrors.required),
499
- description: yup.string().required(translatedErrors.required)
501
+ name: yup.string().required(translatedErrors.required.id),
502
+ description: yup.string().required(translatedErrors.required.id)
500
503
  });
501
504
  const cleanPermissions = (permissions) => Object.keys(permissions).reduce((acc, current) => {
502
505
  const currentPermission = permissions[current].controllers;
@@ -514,7 +517,7 @@ const cleanPermissions = (permissions) => Object.keys(permissions).reduce((acc,
514
517
  return acc;
515
518
  }, {});
516
519
  const usePlugins = () => {
517
- const toggleNotification = useNotification();
520
+ const { toggleNotification } = useNotification();
518
521
  const { get: get2 } = useFetchClient();
519
522
  const { formatAPIError } = useAPIErrorHandler(getTrad);
520
523
  const [
@@ -551,7 +554,7 @@ const usePlugins = () => {
551
554
  useEffect(() => {
552
555
  if (permissionsError) {
553
556
  toggleNotification({
554
- type: "warning",
557
+ type: "danger",
555
558
  message: formatAPIError(permissionsError)
556
559
  });
557
560
  }
@@ -559,7 +562,7 @@ const usePlugins = () => {
559
562
  useEffect(() => {
560
563
  if (routesError) {
561
564
  toggleNotification({
562
- type: "warning",
565
+ type: "danger",
563
566
  message: formatAPIError(routesError)
564
567
  });
565
568
  }
@@ -577,9 +580,8 @@ const usePlugins = () => {
577
580
  };
578
581
  const CreatePage = () => {
579
582
  const { formatMessage } = useIntl();
580
- const toggleNotification = useNotification();
581
- const { goBack } = useHistory();
582
- const { lockApp, unlockApp } = useOverlayBlocker();
583
+ const { toggleNotification } = useNotification();
584
+ const navigate = useNavigate();
583
585
  const { isLoading: isLoadingPlugins, permissions, routes } = usePlugins();
584
586
  const { trackUsage } = useTracking();
585
587
  const permissionsRef = React.useRef();
@@ -587,33 +589,39 @@ const CreatePage = () => {
587
589
  const mutation = useMutation((body) => post(`/users-permissions/roles`, body), {
588
590
  onError() {
589
591
  toggleNotification({
590
- type: "warning",
591
- message: {
592
+ type: "danger",
593
+ message: formatMessage({
592
594
  id: "notification.error",
593
595
  defaultMessage: "An error occurred"
594
- }
596
+ })
595
597
  });
596
598
  },
597
599
  onSuccess() {
598
600
  trackUsage("didCreateRole");
599
601
  toggleNotification({
600
602
  type: "success",
601
- message: {
603
+ message: formatMessage({
602
604
  id: getTrad("Settings.roles.created"),
603
605
  defaultMessage: "Role created"
604
- }
606
+ })
605
607
  });
606
- goBack();
608
+ navigate(-1);
607
609
  }
608
610
  });
609
611
  const handleCreateRoleSubmit = async (data) => {
610
- lockApp();
611
612
  const permissions2 = permissionsRef.current.getPermissions();
612
613
  await mutation.mutate({ ...data, ...permissions2, users: [] });
613
- unlockApp();
614
614
  };
615
615
  return /* @__PURE__ */ jsxs(Main, { children: [
616
- /* @__PURE__ */ jsx(SettingsPageTitle, { name: "Roles" }),
616
+ /* @__PURE__ */ jsx(
617
+ HelmetExport,
618
+ {
619
+ title: formatMessage(
620
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
621
+ { name: "Roles" }
622
+ )
623
+ }
624
+ ),
617
625
  /* @__PURE__ */ jsx(
618
626
  Formik,
619
627
  {
@@ -708,14 +716,13 @@ const CreatePage = () => {
708
716
  )
709
717
  ] });
710
718
  };
711
- const ProtectedRolesCreatePage = () => /* @__PURE__ */ jsx(CheckPagePermissions, { permissions: PERMISSIONS.createRole, children: /* @__PURE__ */ jsx(CreatePage, {}) });
719
+ const ProtectedRolesCreatePage = () => /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.createRole, children: /* @__PURE__ */ jsx(CreatePage, {}) });
712
720
  const EditPage = () => {
713
721
  const { formatMessage } = useIntl();
714
- const toggleNotification = useNotification();
715
- const { lockApp, unlockApp } = useOverlayBlocker();
722
+ const { toggleNotification } = useNotification();
716
723
  const {
717
724
  params: { id }
718
- } = useRouteMatch(`/settings/users-permissions/roles/:id`);
725
+ } = useMatch(`/settings/users-permissions/roles/:id`);
719
726
  const { get: get2 } = useFetchClient();
720
727
  const { isLoading: isLoadingPlugins, routes } = usePlugins();
721
728
  const {
@@ -734,32 +741,38 @@ const EditPage = () => {
734
741
  const mutation = useMutation((body) => put(`/users-permissions/roles/${id}`, body), {
735
742
  onError(error) {
736
743
  toggleNotification({
737
- type: "warning",
744
+ type: "danger",
738
745
  message: formatAPIError(error)
739
746
  });
740
747
  },
741
748
  async onSuccess() {
742
749
  toggleNotification({
743
750
  type: "success",
744
- message: {
751
+ message: formatMessage({
745
752
  id: getTrad("Settings.roles.created"),
746
753
  defaultMessage: "Role edited"
747
- }
754
+ })
748
755
  });
749
756
  await refetchRole();
750
757
  }
751
758
  });
752
759
  const handleEditRoleSubmit = async (data) => {
753
- lockApp();
754
760
  const permissions = permissionsRef.current.getPermissions();
755
761
  await mutation.mutate({ ...data, ...permissions, users: [] });
756
- unlockApp();
757
762
  };
758
763
  if (isLoadingRole) {
759
- return /* @__PURE__ */ jsx(LoadingIndicatorPage, {});
764
+ return /* @__PURE__ */ jsx(Page.Loading, {});
760
765
  }
761
766
  return /* @__PURE__ */ jsxs(Main, { children: [
762
- /* @__PURE__ */ jsx(SettingsPageTitle, { name: "Roles" }),
767
+ /* @__PURE__ */ jsx(
768
+ HelmetExport,
769
+ {
770
+ title: formatMessage(
771
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
772
+ { name: "Roles" }
773
+ )
774
+ }
775
+ ),
763
776
  /* @__PURE__ */ jsx(
764
777
  Formik,
765
778
  {
@@ -771,7 +784,7 @@ const EditPage = () => {
771
784
  /* @__PURE__ */ jsx(
772
785
  HeaderLayout,
773
786
  {
774
- primaryAction: !isLoadingPlugins && /* @__PURE__ */ jsx(
787
+ primaryAction: !isLoadingPlugins ? /* @__PURE__ */ jsx(
775
788
  Button,
776
789
  {
777
790
  disabled: role.code === "strapi-super-admin",
@@ -783,13 +796,10 @@ const EditPage = () => {
783
796
  defaultMessage: "Save"
784
797
  })
785
798
  }
786
- ),
799
+ ) : null,
787
800
  title: role.name,
788
801
  subtitle: role.description,
789
- navigationAction: /* @__PURE__ */ jsx(Link, { startIcon: /* @__PURE__ */ jsx(ArrowLeft, {}), to: "/settings/users-permissions/roles", children: formatMessage({
790
- id: "global.back",
791
- defaultMessage: "Back"
792
- }) })
802
+ navigationAction: /* @__PURE__ */ jsx(BackButton, {})
793
803
  }
794
804
  ),
795
805
  /* @__PURE__ */ jsx(ContentLayout, { children: /* @__PURE__ */ jsxs(
@@ -861,18 +871,18 @@ const EditPage = () => {
861
871
  )
862
872
  ] });
863
873
  };
864
- const ProtectedRolesEditPage = () => /* @__PURE__ */ jsx(CheckPagePermissions, { permissions: PERMISSIONS.updateRole, children: /* @__PURE__ */ jsx(EditPage, {}) });
865
- const EditLink = styled(Link$1)`
874
+ const ProtectedRolesEditPage = () => /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.updateRole, children: /* @__PURE__ */ jsx(EditPage, {}) });
875
+ const EditLink = styled(Link)`
866
876
  align-items: center;
867
- height: ${pxToRem(32)};
877
+ height: ${32 / 16}rem;
868
878
  display: flex;
869
879
  justify-content: center;
870
880
  padding: ${({ theme }) => `${theme.spaces[2]}}`};
871
- width: ${pxToRem(32)};
881
+ width: ${32 / 16}rem;
872
882
 
873
883
  svg {
874
- height: ${pxToRem(12)};
875
- width: ${pxToRem(12)};
884
+ height: ${12 / 16}rem;
885
+ width: ${12 / 16}rem;
876
886
 
877
887
  path {
878
888
  fill: ${({ theme }) => theme.colors.neutral500};
@@ -888,19 +898,16 @@ const EditLink = styled(Link$1)`
888
898
  }
889
899
  }
890
900
  `;
891
- const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDelete }) => {
901
+ const TableBody = ({ sortedRoles, canDelete, canUpdate, setRoleToDelete, onDelete }) => {
892
902
  const { formatMessage } = useIntl();
893
- const { push } = useHistory();
903
+ const navigate = useNavigate();
894
904
  const [showConfirmDelete, setShowConfirmDelete] = onDelete;
895
905
  const checkCanDeleteRole = (role) => canDelete && !["public", "authenticated"].includes(role.type);
896
906
  const handleClickDelete = (id) => {
897
907
  setRoleToDelete(id);
898
908
  setShowConfirmDelete(!showConfirmDelete);
899
909
  };
900
- const handleClickEdit = (id) => {
901
- push(`/settings/users-permissions/roles/${id}`);
902
- };
903
- return /* @__PURE__ */ jsx(Tbody, { children: sortedRoles?.map((role) => /* @__PURE__ */ jsxs(Tr, { ...onRowClick({ fn: () => handleClickEdit(role.id) }), children: [
910
+ return /* @__PURE__ */ jsx(Tbody, { children: sortedRoles?.map((role) => /* @__PURE__ */ jsxs(Tr, { onClick: () => navigate(role.id.toString()), children: [
904
911
  /* @__PURE__ */ jsx(Td, { width: "20%", children: /* @__PURE__ */ jsx(Typography, { children: role.name }) }),
905
912
  /* @__PURE__ */ jsx(Td, { width: "50%", children: /* @__PURE__ */ jsx(Typography, { children: role.description }) }),
906
913
  /* @__PURE__ */ jsx(Td, { width: "30%", children: /* @__PURE__ */ jsx(Typography, { children: formatMessage(
@@ -910,22 +917,22 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
910
917
  },
911
918
  { number: role.nb_users }
912
919
  ) }) }),
913
- /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "end", ...stopPropagation, children: [
914
- /* @__PURE__ */ jsx(CheckPermissions, { permissions: permissions.updateRole, children: /* @__PURE__ */ jsx(
920
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "end", onClick: (e) => e.stopPropagation(), children: [
921
+ canUpdate ? /* @__PURE__ */ jsx(
915
922
  EditLink,
916
923
  {
917
- to: `/settings/users-permissions/roles/${role.id}`,
924
+ to: role.id.toString(),
918
925
  "aria-label": formatMessage(
919
926
  { id: "app.component.table.edit", defaultMessage: "Edit {target}" },
920
927
  { target: `${role.name}` }
921
928
  ),
922
929
  children: /* @__PURE__ */ jsx(Pencil, {})
923
930
  }
924
- ) }),
925
- checkCanDeleteRole(role) && /* @__PURE__ */ jsx(CheckPermissions, { permissions: permissions.deleteRole, children: /* @__PURE__ */ jsx(
931
+ ) : null,
932
+ checkCanDeleteRole(role) && /* @__PURE__ */ jsx(
926
933
  IconButton,
927
934
  {
928
- onClick: () => handleClickDelete(role.id),
935
+ onClick: () => handleClickDelete(role.id.toString()),
929
936
  noBorder: true,
930
937
  icon: /* @__PURE__ */ jsx(Trash, {}),
931
938
  label: formatMessage(
@@ -933,59 +940,35 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
933
940
  { target: `${role.name}` }
934
941
  )
935
942
  }
936
- ) })
943
+ )
937
944
  ] }) })
938
945
  ] }, role.name)) });
939
946
  };
940
947
  TableBody.defaultProps = {
941
- canDelete: false
948
+ canDelete: false,
949
+ canUpdate: false
942
950
  };
943
951
  TableBody.propTypes = {
944
952
  onDelete: PropTypes.array.isRequired,
945
953
  permissions: PropTypes.object.isRequired,
946
954
  setRoleToDelete: PropTypes.func.isRequired,
947
955
  sortedRoles: PropTypes.array.isRequired,
948
- canDelete: PropTypes.bool
949
- };
950
- const fetchData = async (toggleNotification, notifyStatus) => {
951
- try {
952
- const { get: get2 } = getFetchClient();
953
- const { data } = await get2("/users-permissions/roles");
954
- notifyStatus("The roles have loaded successfully");
955
- return data;
956
- } catch (err) {
957
- toggleNotification({
958
- type: "warning",
959
- message: { id: "notification.error" }
960
- });
961
- throw new Error(err);
962
- }
963
- };
964
- const deleteData = async (id, toggleNotification) => {
965
- try {
966
- const { del } = getFetchClient();
967
- await del(`/users-permissions/roles/${id}`);
968
- } catch (error) {
969
- toggleNotification({
970
- type: "warning",
971
- message: { id: "notification.error", defaultMessage: "An error occured" }
972
- });
973
- }
956
+ canDelete: PropTypes.bool,
957
+ canUpdate: PropTypes.bool
974
958
  };
975
959
  const RolesListPage = () => {
976
960
  const { trackUsage } = useTracking();
977
961
  const { formatMessage, locale } = useIntl();
978
- const toggleNotification = useNotification();
962
+ const { toggleNotification } = useNotification();
979
963
  const { notifyStatus } = useNotifyAT();
980
964
  const [{ query }] = useQueryParams();
981
965
  const _q = query?._q || "";
982
966
  const [showConfirmDelete, setShowConfirmDelete] = useState(false);
983
- const [isConfirmButtonLoading, setIsConfirmButtonLoading] = useState(false);
984
967
  const [roleToDelete, setRoleToDelete] = useState();
985
- useFocusWhenNavigate();
968
+ const { del, get: get2 } = useFetchClient();
986
969
  const {
987
970
  isLoading: isLoadingForPermissions,
988
- allowedActions: { canRead, canDelete }
971
+ allowedActions: { canRead, canDelete, canCreate, canUpdate }
989
972
  } = useRBAC({
990
973
  create: PERMISSIONS.createRole,
991
974
  read: PERMISSIONS.readRoles,
@@ -997,20 +980,43 @@ const RolesListPage = () => {
997
980
  data: { roles },
998
981
  isFetching,
999
982
  refetch
1000
- } = useQuery("get-roles", () => fetchData(toggleNotification, notifyStatus), {
983
+ } = useQuery("get-roles", () => fetchData(toggleNotification, formatMessage, notifyStatus), {
1001
984
  initialData: {},
1002
985
  enabled: canRead
1003
986
  });
1004
- const { includes } = useFilter(locale, {
987
+ const { contains } = useFilter(locale, {
1005
988
  sensitivity: "base"
1006
989
  });
1007
990
  const formatter = useCollator(locale, {
1008
991
  sensitivity: "base"
1009
992
  });
1010
- const isLoading = isLoadingForData || isFetching;
993
+ const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;
1011
994
  const handleShowConfirmDelete = () => {
1012
995
  setShowConfirmDelete(!showConfirmDelete);
1013
996
  };
997
+ const deleteData = async (id, formatMessage2, toggleNotification2) => {
998
+ try {
999
+ await del(`/users-permissions/roles/${id}`);
1000
+ } catch (error) {
1001
+ toggleNotification2({
1002
+ type: "danger",
1003
+ message: formatMessage2({ id: "notification.error", defaultMessage: "An error occured" })
1004
+ });
1005
+ }
1006
+ };
1007
+ const fetchData = async (toggleNotification2, formatMessage2, notifyStatus2) => {
1008
+ try {
1009
+ const { data } = await get2("/users-permissions/roles");
1010
+ notifyStatus2("The roles have loaded successfully");
1011
+ return data;
1012
+ } catch (err) {
1013
+ toggleNotification2({
1014
+ type: "danger",
1015
+ message: formatMessage2({ id: "notification.error" })
1016
+ });
1017
+ throw new Error(err);
1018
+ }
1019
+ };
1014
1020
  const emptyLayout = {
1015
1021
  roles: {
1016
1022
  id: getTrad("Roles.empty"),
@@ -1025,26 +1031,35 @@ const RolesListPage = () => {
1025
1031
  id: "global.roles",
1026
1032
  defaultMessage: "Roles"
1027
1033
  });
1028
- const deleteMutation = useMutation((id) => deleteData(id, toggleNotification), {
1034
+ const deleteMutation = useMutation((id) => deleteData(id, formatMessage, toggleNotification), {
1029
1035
  async onSuccess() {
1030
1036
  await refetch();
1031
1037
  }
1032
1038
  });
1033
1039
  const handleConfirmDelete = async () => {
1034
- setIsConfirmButtonLoading(true);
1035
1040
  await deleteMutation.mutateAsync(roleToDelete);
1036
1041
  setShowConfirmDelete(!showConfirmDelete);
1037
- setIsConfirmButtonLoading(false);
1038
1042
  };
1039
- const sortedRoles = (roles || []).filter((role) => includes(role.name, _q) || includes(role.description, _q)).sort(
1043
+ const sortedRoles = (roles || []).filter((role) => contains(role.name, _q) || contains(role.description, _q)).sort(
1040
1044
  (a, b) => formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description)
1041
1045
  );
1042
1046
  const emptyContent = _q && !sortedRoles.length ? "search" : "roles";
1043
1047
  const colCount = 4;
1044
1048
  const rowCount = (roles?.length || 0) + 1;
1049
+ if (isLoading) {
1050
+ return /* @__PURE__ */ jsx(Page.Loading, {});
1051
+ }
1045
1052
  return /* @__PURE__ */ jsxs(Layout, { children: [
1046
- /* @__PURE__ */ jsx(SettingsPageTitle, { name: pageTitle }),
1047
- /* @__PURE__ */ jsxs(Main, { "aria-busy": isLoading, children: [
1053
+ /* @__PURE__ */ jsx(
1054
+ HelmetExport,
1055
+ {
1056
+ title: formatMessage(
1057
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
1058
+ { name: pageTitle }
1059
+ )
1060
+ }
1061
+ ),
1062
+ /* @__PURE__ */ jsxs(Page.Main, { children: [
1048
1063
  /* @__PURE__ */ jsx(
1049
1064
  HeaderLayout,
1050
1065
  {
@@ -1056,10 +1071,11 @@ const RolesListPage = () => {
1056
1071
  id: "Settings.roles.list.description",
1057
1072
  defaultMessage: "List of roles"
1058
1073
  }),
1059
- primaryAction: /* @__PURE__ */ jsx(CheckPermissions, { permissions: PERMISSIONS.createRole, children: /* @__PURE__ */ jsx(
1074
+ primaryAction: canCreate ? /* @__PURE__ */ jsx(
1060
1075
  LinkButton,
1061
1076
  {
1062
- to: "/settings/users-permissions/roles/new",
1077
+ to: "new",
1078
+ as: NavLink,
1063
1079
  onClick: () => trackUsage("willCreateRole"),
1064
1080
  startIcon: /* @__PURE__ */ jsx(Plus, {}),
1065
1081
  size: "S",
@@ -1068,14 +1084,15 @@ const RolesListPage = () => {
1068
1084
  defaultMessage: "Add new role"
1069
1085
  })
1070
1086
  }
1071
- ) })
1087
+ ) : null,
1088
+ navigationAction: /* @__PURE__ */ jsx(BackButton, {})
1072
1089
  }
1073
1090
  ),
1074
1091
  /* @__PURE__ */ jsx(
1075
1092
  ActionLayout,
1076
1093
  {
1077
1094
  startActions: /* @__PURE__ */ jsx(
1078
- SearchURLQuery,
1095
+ SearchInput,
1079
1096
  {
1080
1097
  label: formatMessage({
1081
1098
  id: "app.component.search.label",
@@ -1086,8 +1103,7 @@ const RolesListPage = () => {
1086
1103
  }
1087
1104
  ),
1088
1105
  /* @__PURE__ */ jsxs(ContentLayout, { children: [
1089
- !canRead && /* @__PURE__ */ jsx(NoPermissions, {}),
1090
- (isLoading || isLoadingForPermissions) && /* @__PURE__ */ jsx(LoadingIndicatorPage, {}),
1106
+ !canRead && /* @__PURE__ */ jsx(Page.NoPermissions, {}),
1091
1107
  canRead && sortedRoles && sortedRoles?.length ? /* @__PURE__ */ jsxs(Table, { colCount, rowCount, children: [
1092
1108
  /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
1093
1109
  /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({ id: "global.name", defaultMessage: "Name" }) }) }),
@@ -1109,19 +1125,19 @@ const RolesListPage = () => {
1109
1125
  {
1110
1126
  sortedRoles,
1111
1127
  canDelete,
1128
+ canUpdate,
1112
1129
  permissions: PERMISSIONS,
1113
1130
  setRoleToDelete,
1114
1131
  onDelete: [showConfirmDelete, setShowConfirmDelete]
1115
1132
  }
1116
1133
  )
1117
- ] }) : /* @__PURE__ */ jsx(EmptyStateLayout, { content: emptyLayout[emptyContent] })
1134
+ ] }) : /* @__PURE__ */ jsx(EmptyStateLayout, { content: formatMessage(emptyLayout[emptyContent]) })
1118
1135
  ] }),
1119
1136
  /* @__PURE__ */ jsx(
1120
1137
  ConfirmDialog,
1121
1138
  {
1122
- isConfirmButtonLoading,
1123
1139
  onConfirm: handleConfirmDelete,
1124
- onToggleDialog: handleShowConfirmDelete,
1140
+ onClose: handleShowConfirmDelete,
1125
1141
  isOpen: showConfirmDelete
1126
1142
  }
1127
1143
  )
@@ -1129,31 +1145,16 @@ const RolesListPage = () => {
1129
1145
  ] });
1130
1146
  };
1131
1147
  const ProtectedRolesListPage = () => {
1132
- return /* @__PURE__ */ jsx(CheckPagePermissions, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsx(RolesListPage, {}) });
1148
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsx(RolesListPage, {}) });
1133
1149
  };
1134
1150
  const Roles = () => {
1135
- return /* @__PURE__ */ jsx(CheckPagePermissions, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsxs(Switch, { children: [
1136
- /* @__PURE__ */ jsx(
1137
- Route,
1138
- {
1139
- path: "/settings/users-permissions/roles/new",
1140
- component: ProtectedRolesCreatePage,
1141
- exact: true
1142
- }
1143
- ),
1144
- /* @__PURE__ */ jsx(
1145
- Route,
1146
- {
1147
- path: "/settings/users-permissions/roles/:id",
1148
- component: ProtectedRolesEditPage,
1149
- exact: true
1150
- }
1151
- ),
1152
- /* @__PURE__ */ jsx(Route, { path: "/settings/users-permissions/roles", component: ProtectedRolesListPage, exact: true }),
1153
- /* @__PURE__ */ jsx(Route, { path: "", component: AnErrorOccurred })
1151
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsxs(Routes, { children: [
1152
+ /* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(ProtectedRolesListPage, {}) }),
1153
+ /* @__PURE__ */ jsx(Route, { path: "new", element: /* @__PURE__ */ jsx(ProtectedRolesCreatePage, {}) }),
1154
+ /* @__PURE__ */ jsx(Route, { path: ":id", element: /* @__PURE__ */ jsx(ProtectedRolesEditPage, {}) })
1154
1155
  ] }) });
1155
1156
  };
1156
1157
  export {
1157
1158
  Roles as default
1158
1159
  };
1159
- //# sourceMappingURL=index-rryiT0-Z.mjs.map
1160
+ //# sourceMappingURL=index-hG66XSuA.mjs.map