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

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 (108) 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 +14 -30
  5. package/admin/src/pages/AdvancedSettings/index.jsx +69 -107
  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/index.jsx +22 -50
  10. package/admin/src/pages/EmailTemplates/utils/schema.js +18 -6
  11. package/admin/src/pages/Providers/index.jsx +91 -96
  12. package/admin/src/pages/Providers/utils/forms.js +11 -11
  13. package/admin/src/pages/Roles/constants.js +3 -3
  14. package/admin/src/pages/Roles/hooks/usePlugins.js +5 -4
  15. package/admin/src/pages/Roles/index.jsx +9 -18
  16. package/admin/src/pages/Roles/pages/CreatePage.jsx +21 -28
  17. package/admin/src/pages/Roles/pages/EditPage.jsx +23 -40
  18. package/admin/src/pages/Roles/pages/ListPage/components/TableBody.jsx +23 -27
  19. package/admin/src/pages/Roles/pages/ListPage/index.jsx +42 -38
  20. package/admin/src/pages/Roles/pages/ListPage/utils/api.js +6 -6
  21. package/admin/src/translations/en.json +1 -1
  22. package/dist/_chunks/EditViewPage-xYzUSAwS-5mOQ_-nB.mjs +84370 -0
  23. package/dist/_chunks/EditViewPage-xYzUSAwS-5mOQ_-nB.mjs.map +1 -0
  24. package/dist/_chunks/EditViewPage-xYzUSAwS-wpHlxdkC.js +84398 -0
  25. package/dist/_chunks/EditViewPage-xYzUSAwS-wpHlxdkC.js.map +1 -0
  26. package/dist/_chunks/Helmet-d9JljxUo.js +1010 -0
  27. package/dist/_chunks/Helmet-d9JljxUo.js.map +1 -0
  28. package/dist/_chunks/Helmet-kyJ1Zklj.mjs +1008 -0
  29. package/dist/_chunks/Helmet-kyJ1Zklj.mjs.map +1 -0
  30. package/dist/_chunks/ListViewPage-xOVa04T_-elahT0e9.js +1618 -0
  31. package/dist/_chunks/ListViewPage-xOVa04T_-elahT0e9.js.map +1 -0
  32. package/dist/_chunks/ListViewPage-xOVa04T_-lbfb219V.mjs +1595 -0
  33. package/dist/_chunks/ListViewPage-xOVa04T_-lbfb219V.mjs.map +1 -0
  34. package/dist/_chunks/ReviewWorkflowsColumn-FDxVKdto-IWfB3WVH.mjs +33 -0
  35. package/dist/_chunks/ReviewWorkflowsColumn-FDxVKdto-IWfB3WVH.mjs.map +1 -0
  36. package/dist/_chunks/ReviewWorkflowsColumn-FDxVKdto-m8hslkeI.js +33 -0
  37. package/dist/_chunks/ReviewWorkflowsColumn-FDxVKdto-m8hslkeI.js.map +1 -0
  38. package/dist/_chunks/constants-WjN6I3sL-7e3gpx4b.mjs +190 -0
  39. package/dist/_chunks/constants-WjN6I3sL-7e3gpx4b.mjs.map +1 -0
  40. package/dist/_chunks/constants-WjN6I3sL-cDZPE6ED.js +209 -0
  41. package/dist/_chunks/constants-WjN6I3sL-cDZPE6ED.js.map +1 -0
  42. package/dist/_chunks/{en-m608rMZx.js → en-TaNIVnDO.js} +2 -2
  43. package/dist/_chunks/en-TaNIVnDO.js.map +1 -0
  44. package/dist/_chunks/{en-CE3wEy_c.mjs → en-jvJ-d-Qq.mjs} +2 -2
  45. package/dist/_chunks/en-jvJ-d-Qq.mjs.map +1 -0
  46. package/dist/_chunks/{index-iNtwnT3f.mjs → index-53jX2hhF.mjs} +26 -34
  47. package/dist/_chunks/index-53jX2hhF.mjs.map +1 -0
  48. package/dist/_chunks/index-5ZvCaCyY-06DLg5eU.mjs +16421 -0
  49. package/dist/_chunks/index-5ZvCaCyY-06DLg5eU.mjs.map +1 -0
  50. package/dist/_chunks/index-5ZvCaCyY-JgYo3Jws.js +16446 -0
  51. package/dist/_chunks/index-5ZvCaCyY-JgYo3Jws.js.map +1 -0
  52. package/dist/_chunks/{index-rryiT0-Z.mjs → index-A3oJlPcE.mjs} +111 -108
  53. package/dist/_chunks/index-A3oJlPcE.mjs.map +1 -0
  54. package/dist/_chunks/{index-XqdaO5WZ.js → index-MEUac_4V.js} +124 -122
  55. package/dist/_chunks/index-MEUac_4V.js.map +1 -0
  56. package/dist/_chunks/index-N-GcFWtg.mjs +261 -0
  57. package/dist/_chunks/index-N-GcFWtg.mjs.map +1 -0
  58. package/dist/_chunks/{index-O9AAUvyy.js → index-TJUxOCtJ.js} +26 -34
  59. package/dist/_chunks/index-TJUxOCtJ.js.map +1 -0
  60. package/dist/_chunks/{index-6Kdo3KXv.js → index-VgvlwVA7.js} +106 -147
  61. package/dist/_chunks/index-VgvlwVA7.js.map +1 -0
  62. package/dist/_chunks/{index-1uupZmu0.js → index-bRuKnVcH.js} +39 -32
  63. package/dist/_chunks/index-bRuKnVcH.js.map +1 -0
  64. package/dist/_chunks/{index-ethhTEkj.mjs → index-ee_14Ldw.mjs} +36 -29
  65. package/dist/_chunks/index-ee_14Ldw.mjs.map +1 -0
  66. package/dist/_chunks/index-mzJ2Vb5u.js +280 -0
  67. package/dist/_chunks/index-mzJ2Vb5u.js.map +1 -0
  68. package/dist/_chunks/{index-a9oKDd3C.mjs → index-vXywiVeM.mjs} +101 -142
  69. package/dist/_chunks/index-vXywiVeM.mjs.map +1 -0
  70. package/dist/_chunks/useSyncRbac-Kt8Li0Yf-Z54sMEPM.mjs +39 -0
  71. package/dist/_chunks/useSyncRbac-Kt8Li0Yf-Z54sMEPM.mjs.map +1 -0
  72. package/dist/_chunks/useSyncRbac-Kt8Li0Yf-h8HqtZ6y.js +57 -0
  73. package/dist/_chunks/useSyncRbac-Kt8Li0Yf-h8HqtZ6y.js.map +1 -0
  74. package/dist/admin/index.js +1 -1
  75. package/dist/admin/index.mjs +1 -1
  76. package/dist/style.css +84 -0
  77. package/package.json +13 -13
  78. package/server/bootstrap/grant-config.js +9 -0
  79. package/server/bootstrap/index.js +2 -39
  80. package/server/content-types/user/index.js +0 -1
  81. package/server/controllers/auth.js +24 -53
  82. package/server/controllers/content-manager-user.js +24 -28
  83. package/server/controllers/role.js +1 -1
  84. package/server/controllers/user.js +5 -5
  85. package/server/middlewares/rateLimit.js +1 -1
  86. package/server/register.js +1 -1
  87. package/server/services/jwt.js +3 -3
  88. package/server/services/permission.js +3 -7
  89. package/server/services/providers-registry.js +15 -0
  90. package/server/services/providers.js +10 -5
  91. package/server/services/role.js +15 -13
  92. package/server/services/user.js +28 -14
  93. package/server/services/users-permissions.js +12 -10
  94. package/server/utils/sanitize/sanitizers.js +2 -2
  95. package/dist/_chunks/en-CE3wEy_c.mjs.map +0 -1
  96. package/dist/_chunks/en-m608rMZx.js.map +0 -1
  97. package/dist/_chunks/index-1uupZmu0.js.map +0 -1
  98. package/dist/_chunks/index-6Kdo3KXv.js.map +0 -1
  99. package/dist/_chunks/index-O9AAUvyy.js.map +0 -1
  100. package/dist/_chunks/index-Un-J-cxQ.js +0 -320
  101. package/dist/_chunks/index-Un-J-cxQ.js.map +0 -1
  102. package/dist/_chunks/index-X0yw_GgN.mjs +0 -301
  103. package/dist/_chunks/index-X0yw_GgN.mjs.map +0 -1
  104. package/dist/_chunks/index-XqdaO5WZ.js.map +0 -1
  105. package/dist/_chunks/index-a9oKDd3C.mjs.map +0 -1
  106. package/dist/_chunks/index-ethhTEkj.mjs.map +0 -1
  107. package/dist/_chunks/index-iNtwnT3f.mjs.map +0 -1
  108. package/dist/_chunks/index-rryiT0-Z.mjs.map +0 -1
@@ -1,12 +1,14 @@
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, useAPIErrorHandler, Page, useTracking, BackButton, 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-53jX2hhF.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 { useFetchClient, onRowClick, stopPropagation, getFetchClient, useQueryParams, useFocusWhenNavigate, useRBAC } from "@strapi/helper-plugin";
9
+ import { Cog, Check, Pencil, Trash, Plus } from "@strapi/icons";
10
+ import { Formik, Form } from "formik";
11
+ import { H as HelmetExport } from "./Helmet-kyJ1Zklj.mjs";
10
12
  import { useIntl } from "react-intl";
11
13
  import { useQueries, useMutation, useQuery } from "react-query";
12
14
  import PropTypes from "prop-types";
@@ -14,7 +16,7 @@ import upperFirst from "lodash/upperFirst";
14
16
  import sortBy from "lodash/sortBy";
15
17
  import get from "lodash/get";
16
18
  import styled, { css } from "styled-components";
17
- import produce from "immer";
19
+ import { produce } from "immer";
18
20
  import isEmpty from "lodash/isEmpty";
19
21
  import without from "lodash/without";
20
22
  import map from "lodash/map";
@@ -22,6 +24,7 @@ import tail from "lodash/tail";
22
24
  import set from "lodash/set";
23
25
  import take from "lodash/take";
24
26
  import * as yup from "yup";
27
+ import { LinkButton } from "@strapi/design-system/v2";
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, { ...onRowClick({ fn: () => 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(
@@ -911,21 +918,21 @@ const TableBody = ({ sortedRoles, canDelete, permissions, setRoleToDelete, onDel
911
918
  { number: role.nb_users }
912
919
  ) }) }),
913
920
  /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "end", ...stopPropagation, children: [
914
- /* @__PURE__ */ jsx(CheckPermissions, { permissions: permissions.updateRole, children: /* @__PURE__ */ jsx(
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,21 +940,23 @@ 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
956
+ canDelete: PropTypes.bool,
957
+ canUpdate: PropTypes.bool
949
958
  };
950
- const fetchData = async (toggleNotification, notifyStatus) => {
959
+ const fetchData = async (toggleNotification, formatMessage, notifyStatus) => {
951
960
  try {
952
961
  const { get: get2 } = getFetchClient();
953
962
  const { data } = await get2("/users-permissions/roles");
@@ -955,37 +964,36 @@ const fetchData = async (toggleNotification, notifyStatus) => {
955
964
  return data;
956
965
  } catch (err) {
957
966
  toggleNotification({
958
- type: "warning",
959
- message: { id: "notification.error" }
967
+ type: "danger",
968
+ message: formatMessage({ id: "notification.error" })
960
969
  });
961
970
  throw new Error(err);
962
971
  }
963
972
  };
964
- const deleteData = async (id, toggleNotification) => {
973
+ const deleteData = async (id, formatMessage, toggleNotification) => {
965
974
  try {
966
975
  const { del } = getFetchClient();
967
976
  await del(`/users-permissions/roles/${id}`);
968
977
  } catch (error) {
969
978
  toggleNotification({
970
- type: "warning",
971
- message: { id: "notification.error", defaultMessage: "An error occured" }
979
+ type: "danger",
980
+ message: formatMessage({ id: "notification.error", defaultMessage: "An error occured" })
972
981
  });
973
982
  }
974
983
  };
975
984
  const RolesListPage = () => {
976
985
  const { trackUsage } = useTracking();
977
986
  const { formatMessage, locale } = useIntl();
978
- const toggleNotification = useNotification();
987
+ const { toggleNotification } = useNotification();
979
988
  const { notifyStatus } = useNotifyAT();
980
989
  const [{ query }] = useQueryParams();
981
990
  const _q = query?._q || "";
982
991
  const [showConfirmDelete, setShowConfirmDelete] = useState(false);
983
- const [isConfirmButtonLoading, setIsConfirmButtonLoading] = useState(false);
984
992
  const [roleToDelete, setRoleToDelete] = useState();
985
993
  useFocusWhenNavigate();
986
994
  const {
987
995
  isLoading: isLoadingForPermissions,
988
- allowedActions: { canRead, canDelete }
996
+ allowedActions: { canRead, canDelete, canCreate, canUpdate }
989
997
  } = useRBAC({
990
998
  create: PERMISSIONS.createRole,
991
999
  read: PERMISSIONS.readRoles,
@@ -997,17 +1005,17 @@ const RolesListPage = () => {
997
1005
  data: { roles },
998
1006
  isFetching,
999
1007
  refetch
1000
- } = useQuery("get-roles", () => fetchData(toggleNotification, notifyStatus), {
1008
+ } = useQuery("get-roles", () => fetchData(toggleNotification, formatMessage, notifyStatus), {
1001
1009
  initialData: {},
1002
1010
  enabled: canRead
1003
1011
  });
1004
- const { includes } = useFilter(locale, {
1012
+ const { contains } = useFilter(locale, {
1005
1013
  sensitivity: "base"
1006
1014
  });
1007
1015
  const formatter = useCollator(locale, {
1008
1016
  sensitivity: "base"
1009
1017
  });
1010
- const isLoading = isLoadingForData || isFetching;
1018
+ const isLoading = isLoadingForData || isFetching || isLoadingForPermissions;
1011
1019
  const handleShowConfirmDelete = () => {
1012
1020
  setShowConfirmDelete(!showConfirmDelete);
1013
1021
  };
@@ -1025,25 +1033,34 @@ const RolesListPage = () => {
1025
1033
  id: "global.roles",
1026
1034
  defaultMessage: "Roles"
1027
1035
  });
1028
- const deleteMutation = useMutation((id) => deleteData(id, toggleNotification), {
1036
+ const deleteMutation = useMutation((id) => deleteData(id, formatMessage, toggleNotification), {
1029
1037
  async onSuccess() {
1030
1038
  await refetch();
1031
1039
  }
1032
1040
  });
1033
1041
  const handleConfirmDelete = async () => {
1034
- setIsConfirmButtonLoading(true);
1035
1042
  await deleteMutation.mutateAsync(roleToDelete);
1036
1043
  setShowConfirmDelete(!showConfirmDelete);
1037
- setIsConfirmButtonLoading(false);
1038
1044
  };
1039
- const sortedRoles = (roles || []).filter((role) => includes(role.name, _q) || includes(role.description, _q)).sort(
1045
+ const sortedRoles = (roles || []).filter((role) => contains(role.name, _q) || contains(role.description, _q)).sort(
1040
1046
  (a, b) => formatter.compare(a.name, b.name) || formatter.compare(a.description, b.description)
1041
1047
  );
1042
1048
  const emptyContent = _q && !sortedRoles.length ? "search" : "roles";
1043
1049
  const colCount = 4;
1044
1050
  const rowCount = (roles?.length || 0) + 1;
1051
+ if (isLoading) {
1052
+ return /* @__PURE__ */ jsx(Page.Loading, {});
1053
+ }
1045
1054
  return /* @__PURE__ */ jsxs(Layout, { children: [
1046
- /* @__PURE__ */ jsx(SettingsPageTitle, { name: pageTitle }),
1055
+ /* @__PURE__ */ jsx(
1056
+ HelmetExport,
1057
+ {
1058
+ title: formatMessage(
1059
+ { id: "Settings.PageTitle", defaultMessage: "Settings - {name}" },
1060
+ { name: pageTitle }
1061
+ )
1062
+ }
1063
+ ),
1047
1064
  /* @__PURE__ */ jsxs(Main, { "aria-busy": isLoading, children: [
1048
1065
  /* @__PURE__ */ jsx(
1049
1066
  HeaderLayout,
@@ -1056,10 +1073,11 @@ const RolesListPage = () => {
1056
1073
  id: "Settings.roles.list.description",
1057
1074
  defaultMessage: "List of roles"
1058
1075
  }),
1059
- primaryAction: /* @__PURE__ */ jsx(CheckPermissions, { permissions: PERMISSIONS.createRole, children: /* @__PURE__ */ jsx(
1076
+ primaryAction: canCreate ? /* @__PURE__ */ jsx(
1060
1077
  LinkButton,
1061
1078
  {
1062
- to: "/settings/users-permissions/roles/new",
1079
+ to: "new",
1080
+ as: NavLink,
1063
1081
  onClick: () => trackUsage("willCreateRole"),
1064
1082
  startIcon: /* @__PURE__ */ jsx(Plus, {}),
1065
1083
  size: "S",
@@ -1068,14 +1086,15 @@ const RolesListPage = () => {
1068
1086
  defaultMessage: "Add new role"
1069
1087
  })
1070
1088
  }
1071
- ) })
1089
+ ) : null,
1090
+ navigationAction: /* @__PURE__ */ jsx(BackButton, {})
1072
1091
  }
1073
1092
  ),
1074
1093
  /* @__PURE__ */ jsx(
1075
1094
  ActionLayout,
1076
1095
  {
1077
1096
  startActions: /* @__PURE__ */ jsx(
1078
- SearchURLQuery,
1097
+ SearchInput,
1079
1098
  {
1080
1099
  label: formatMessage({
1081
1100
  id: "app.component.search.label",
@@ -1086,8 +1105,7 @@ const RolesListPage = () => {
1086
1105
  }
1087
1106
  ),
1088
1107
  /* @__PURE__ */ jsxs(ContentLayout, { children: [
1089
- !canRead && /* @__PURE__ */ jsx(NoPermissions, {}),
1090
- (isLoading || isLoadingForPermissions) && /* @__PURE__ */ jsx(LoadingIndicatorPage, {}),
1108
+ !canRead && /* @__PURE__ */ jsx(Page.NoPermissions, {}),
1091
1109
  canRead && sortedRoles && sortedRoles?.length ? /* @__PURE__ */ jsxs(Table, { colCount, rowCount, children: [
1092
1110
  /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
1093
1111
  /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({ id: "global.name", defaultMessage: "Name" }) }) }),
@@ -1109,19 +1127,19 @@ const RolesListPage = () => {
1109
1127
  {
1110
1128
  sortedRoles,
1111
1129
  canDelete,
1130
+ canUpdate,
1112
1131
  permissions: PERMISSIONS,
1113
1132
  setRoleToDelete,
1114
1133
  onDelete: [showConfirmDelete, setShowConfirmDelete]
1115
1134
  }
1116
1135
  )
1117
- ] }) : /* @__PURE__ */ jsx(EmptyStateLayout, { content: emptyLayout[emptyContent] })
1136
+ ] }) : /* @__PURE__ */ jsx(EmptyStateLayout, { content: formatMessage(emptyLayout[emptyContent]) })
1118
1137
  ] }),
1119
1138
  /* @__PURE__ */ jsx(
1120
1139
  ConfirmDialog,
1121
1140
  {
1122
- isConfirmButtonLoading,
1123
1141
  onConfirm: handleConfirmDelete,
1124
- onToggleDialog: handleShowConfirmDelete,
1142
+ onClose: handleShowConfirmDelete,
1125
1143
  isOpen: showConfirmDelete
1126
1144
  }
1127
1145
  )
@@ -1129,31 +1147,16 @@ const RolesListPage = () => {
1129
1147
  ] });
1130
1148
  };
1131
1149
  const ProtectedRolesListPage = () => {
1132
- return /* @__PURE__ */ jsx(CheckPagePermissions, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsx(RolesListPage, {}) });
1150
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsx(RolesListPage, {}) });
1133
1151
  };
1134
1152
  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 })
1153
+ return /* @__PURE__ */ jsx(Page.Protect, { permissions: PERMISSIONS.accessRoles, children: /* @__PURE__ */ jsxs(Routes, { children: [
1154
+ /* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(ProtectedRolesListPage, {}) }),
1155
+ /* @__PURE__ */ jsx(Route, { path: "new", element: /* @__PURE__ */ jsx(ProtectedRolesCreatePage, {}) }),
1156
+ /* @__PURE__ */ jsx(Route, { path: ":id", element: /* @__PURE__ */ jsx(ProtectedRolesEditPage, {}) })
1154
1157
  ] }) });
1155
1158
  };
1156
1159
  export {
1157
1160
  Roles as default
1158
1161
  };
1159
- //# sourceMappingURL=index-rryiT0-Z.mjs.map
1162
+ //# sourceMappingURL=index-A3oJlPcE.mjs.map