@strapi/admin 4.12.1 → 4.12.4

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 (66) hide show
  1. package/admin/src/content-manager/pages/EditSettingsView/index.js +1 -1
  2. package/admin/src/content-manager/pages/ListView/components/BulkActionButtons/SelectedEntriesModal/index.js +7 -2
  3. package/admin/src/content-manager/pages/ListView/index.js +7 -1
  4. package/admin/src/hooks/index.js +0 -3
  5. package/admin/src/hooks/useAdminRolePermissions/__mocks__/index.js +5 -0
  6. package/admin/src/hooks/useAdminRolePermissions/index.js +34 -0
  7. package/admin/src/hooks/useAdminRoles/__mocks__/index.js +5 -0
  8. package/admin/src/hooks/useAdminRoles/index.js +40 -0
  9. package/admin/src/pages/InstalledPluginsPage/Plugins.js +2 -2
  10. package/admin/src/pages/InstalledPluginsPage/hooks/usePlugins/index.js +29 -0
  11. package/admin/src/pages/MarketplacePage/hooks/useFetchMarketplacePlugins/index.js +44 -0
  12. package/admin/src/pages/MarketplacePage/hooks/useFetchMarketplaceProviders/index.js +44 -0
  13. package/admin/src/pages/MarketplacePage/utils/useMarketplaceData.js +2 -2
  14. package/admin/src/pages/SettingsPage/pages/Roles/CreatePage/index.js +24 -9
  15. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/components/RoleForm/index.js +1 -0
  16. package/admin/src/pages/SettingsPage/pages/Roles/EditPage/index.js +34 -20
  17. package/admin/src/pages/SettingsPage/pages/Roles/ListPage/index.js +31 -84
  18. package/admin/src/pages/SettingsPage/pages/Roles/hooks/useAdminRolePermissionLayout/index.js +23 -0
  19. package/admin/src/translations/en.json +1 -1
  20. package/build/1049.f76cb14b.chunk.js +1 -0
  21. package/build/{2225.0e4f8c77.chunk.js → 2225.c6244756.chunk.js} +1 -1
  22. package/build/{Admin-authenticatedApp.8dfbc48d.chunk.js → Admin-authenticatedApp.f5ece8ff.chunk.js} +2 -2
  23. package/build/{Admin_marketplace.f0b87fce.chunk.js → Admin_marketplace.dde9c148.chunk.js} +6 -6
  24. package/build/Admin_pluginsPage.bbe79434.chunk.js +6 -0
  25. package/build/{Admin_profilePage.ca82c67b.chunk.js → Admin_profilePage.192edc52.chunk.js} +1 -1
  26. package/build/{Admin_settingsPage.50c867bf.chunk.js → Admin_settingsPage.97cb9d41.chunk.js} +1 -1
  27. package/build/admin-app.91898385.chunk.js +36 -0
  28. package/build/admin-edit-roles-page.6d567273.chunk.js +267 -0
  29. package/build/admin-roles-list.23ddff26.chunk.js +22 -0
  30. package/build/content-manager.2af15f57.chunk.js +1099 -0
  31. package/build/content-type-builder.40534de5.chunk.js +170 -0
  32. package/build/{en-json.01456e61.chunk.js → en-json.08c05fcf.chunk.js} +1 -1
  33. package/build/index.html +1 -1
  34. package/build/{main.1f8cc299.js → main.f13fc96c.js} +204 -204
  35. package/build/{runtime~main.80a43c16.js → runtime~main.bb4efc54.js} +1 -1
  36. package/build/sso-settings-page.12b6d8ae.chunk.js +1 -0
  37. package/build/transfer-tokens-list-page.22147d2c.chunk.js +16 -0
  38. package/build/{upload.77d8a64c.chunk.js → upload.37488080.chunk.js} +3 -3
  39. package/ee/admin/pages/SettingsPage/pages/SingleSignOn/index.js +15 -24
  40. package/index.js +2 -0
  41. package/package.json +8 -8
  42. package/scripts/build.js +1 -0
  43. package/server/controllers/role.js +9 -1
  44. package/server/services/role.js +3 -2
  45. package/webpack.config.js +2 -1
  46. package/admin/src/hooks/marketplace/useFetchMarketplacePlugins/index.js +0 -44
  47. package/admin/src/hooks/marketplace/useFetchMarketplaceProviders/index.js +0 -44
  48. package/admin/src/hooks/useFetchEnabledPlugins/index.js +0 -24
  49. package/admin/src/hooks/useFetchEnabledPlugins/utils/api.js +0 -10
  50. package/admin/src/hooks/useFetchPermissionsLayout/index.js +0 -42
  51. package/admin/src/hooks/useFetchPermissionsLayout/reducer.js +0 -35
  52. package/admin/src/hooks/useFetchRole/index.js +0 -68
  53. package/admin/src/hooks/useFetchRole/reducer.js +0 -33
  54. package/admin/src/hooks/useRolesList/index.js +0 -58
  55. package/admin/src/hooks/useRolesList/init.js +0 -5
  56. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  57. package/build/1049.c3d082e9.chunk.js +0 -1
  58. package/build/Admin_pluginsPage.8728ff6e.chunk.js +0 -6
  59. package/build/admin-app.041dcd81.chunk.js +0 -36
  60. package/build/admin-edit-roles-page.a49b9f4f.chunk.js +0 -267
  61. package/build/admin-roles-list.0c129e98.chunk.js +0 -23
  62. package/build/content-manager.098eb004.chunk.js +0 -1099
  63. package/build/content-type-builder.64f4d6ac.chunk.js +0 -170
  64. package/build/sso-settings-page.81152e62.chunk.js +0 -1
  65. package/build/transfer-tokens-list-page.692eee77.chunk.js +0 -16
  66. /package/admin/src/{hooks/marketplace → pages/MarketplacePage}/constants.js +0 -0
@@ -133,7 +133,7 @@ const EditSettingsView = ({ mainLayout, components, isContentTypeView, slug, upd
133
133
  return put(
134
134
  isContentTypeView
135
135
  ? `/content-manager/content-types/${slug}/configuration`
136
- : `components/${slug}/configuration`,
136
+ : `/content-manager/components/${slug}/configuration`,
137
137
  body
138
138
  );
139
139
  },
@@ -261,7 +261,11 @@ const SelectedEntriesModalContent = ({
261
261
  const selectedEntriesWithErrorsCount = rowsToDisplay.filter(
262
262
  ({ id }) => selectedEntries.includes(id) && validationErrors[id]
263
263
  ).length;
264
- const selectedEntriesWithNoErrorsCount = selectedEntries.length - selectedEntriesWithErrorsCount;
264
+ const selectedEntriesPublished = rowsToDisplay.filter(
265
+ ({ id, publishedAt }) => selectedEntries.includes(id) && publishedAt
266
+ ).length;
267
+ const selectedEntriesWithNoErrorsCount =
268
+ selectedEntries.length - selectedEntriesWithErrorsCount - selectedEntriesPublished;
265
269
 
266
270
  const bulkPublishMutation = useMutation(
267
271
  (data) =>
@@ -331,11 +335,12 @@ const SelectedEntriesModalContent = ({
331
335
  {
332
336
  id: getTrad('containers.ListPage.selectedEntriesModal.selectedCount'),
333
337
  defaultMessage:
334
- '<b>{readyToPublishCount}</b> {readyToPublishCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action.',
338
+ '<b>{alreadyPublishedCount}</b> {alreadyPublishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{readyToPublishCount}</b> {readyToPublishCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action.',
335
339
  },
336
340
  {
337
341
  readyToPublishCount: selectedEntriesWithNoErrorsCount,
338
342
  withErrorsCount: selectedEntriesWithErrorsCount,
343
+ alreadyPublishedCount: selectedEntriesPublished,
339
344
  b: BoldChunk,
340
345
  }
341
346
  );
@@ -575,7 +575,7 @@ function ListView({
575
575
  {/* Bulk action row checkbox */}
576
576
  <Body.CheckboxDataCell rowId={rowData.id} index={index} />
577
577
  {/* Field data */}
578
- {tableHeaders.map(({ key, name, ...rest }) => {
578
+ {tableHeaders.map(({ key, name, cellFormatter, ...rest }) => {
579
579
  if (hasDraftAndPublish && name === 'publishedAt') {
580
580
  return (
581
581
  <Td key={key}>
@@ -622,6 +622,12 @@ function ListView({
622
622
  );
623
623
  }
624
624
 
625
+ if (typeof cellFormatter === 'function') {
626
+ return (
627
+ <Td key={key}>{cellFormatter(rowData, { key, name, ...rest })}</Td>
628
+ );
629
+ }
630
+
625
631
  return (
626
632
  <Td key={key}>
627
633
  <CellContent
@@ -1,13 +1,10 @@
1
1
  export { default as useConfigurations } from './useConfigurations';
2
2
  export { useContentTypes } from './useContentTypes';
3
- export { default as useFetchPermissionsLayout } from './useFetchPermissionsLayout';
4
- export { default as useFetchRole } from './useFetchRole';
5
3
  export { default as useLicenseLimitNotification } from './useLicenseLimitNotification';
6
4
  export { default as useMenu } from './useMenu';
7
5
  export { default as usePermissionsDataManager } from './usePermissionsDataManager';
8
6
  export { default as useRegenerate } from './useRegenerate';
9
7
  export { default as useReleaseNotification } from './useReleaseNotification';
10
- export { default as useRolesList } from './useRolesList';
11
8
  export { default as useSettingsForm } from './useSettingsForm';
12
9
  export { default as useSettingsMenu } from './useSettingsMenu';
13
10
  export { default as useThemeToggle } from './useThemeToggle';
@@ -0,0 +1,5 @@
1
+ export const useAdminRolePermissions = jest.fn().mockReturnValue({
2
+ permissions: [],
3
+ isLoading: false,
4
+ isError: false,
5
+ });
@@ -0,0 +1,34 @@
1
+ import { useFetchClient } from '@strapi/helper-plugin';
2
+ import { useQuery } from 'react-query';
3
+
4
+ export const useAdminRolePermissions = (params = {}, queryOptions = {}) => {
5
+ const { id, ...queryParams } = params;
6
+
7
+ const { get } = useFetchClient();
8
+
9
+ if (!id && (queryOptions?.enabled === undefined || !!queryOptions?.enabled === true)) {
10
+ throw new Error('"id" is a required argument');
11
+ }
12
+
13
+ const {
14
+ data: permissions,
15
+ error,
16
+ isError,
17
+ isLoading,
18
+ refetch,
19
+ } = useQuery(
20
+ ['roles', id, 'permissions', queryParams],
21
+ async () => {
22
+ const {
23
+ data: { data },
24
+ } = await get(`/admin/roles/${id}/permissions`, {
25
+ params: queryParams,
26
+ });
27
+
28
+ return data;
29
+ },
30
+ queryOptions
31
+ );
32
+
33
+ return { permissions, error, isError, isLoading, refetch };
34
+ };
@@ -0,0 +1,5 @@
1
+ export const useAdminRoles = jest.fn().mockReturnValue({
2
+ roles: [],
3
+ isLoading: false,
4
+ isError: false,
5
+ });
@@ -0,0 +1,40 @@
1
+ import { useCollator, useFetchClient } from '@strapi/helper-plugin';
2
+ import { useIntl } from 'react-intl';
3
+ import { useQuery } from 'react-query';
4
+
5
+ export const useAdminRoles = (params = {}, queryOptions = {}) => {
6
+ const { id = '', ...queryParams } = params;
7
+
8
+ const { get } = useFetchClient();
9
+ const { locale } = useIntl();
10
+ const formatter = useCollator(locale, {
11
+ sensitivity: 'base',
12
+ });
13
+ const { data, error, isError, isLoading, refetch } = useQuery(
14
+ ['roles', id, queryParams],
15
+ async () => {
16
+ const { data } = await get(`/admin/roles/${id ?? ''}`, {
17
+ params: queryParams,
18
+ });
19
+
20
+ return data;
21
+ },
22
+ queryOptions
23
+ );
24
+
25
+ let roles = [];
26
+
27
+ if (id && data) {
28
+ roles = [data.data];
29
+ } else if (Array.isArray(data?.data)) {
30
+ roles = data.data;
31
+ }
32
+
33
+ return {
34
+ roles: roles.sort((a, b) => formatter.compare(a.name, b.name)),
35
+ error,
36
+ isError,
37
+ isLoading,
38
+ refetch,
39
+ };
40
+ };
@@ -17,7 +17,7 @@ import {
17
17
  import { LoadingIndicatorPage, useFocusWhenNavigate } from '@strapi/helper-plugin';
18
18
  import { useIntl } from 'react-intl';
19
19
 
20
- import useFetchEnabledPlugins from '../../hooks/useFetchEnabledPlugins';
20
+ import { usePlugins } from './hooks/usePlugins';
21
21
 
22
22
  const Plugins = () => {
23
23
  const { formatMessage } = useIntl();
@@ -41,7 +41,7 @@ const Plugins = () => {
41
41
  );
42
42
  };
43
43
 
44
- const { status, data } = useFetchEnabledPlugins(notifyPluginPageLoad);
44
+ const { status, data } = usePlugins(notifyPluginPageLoad);
45
45
 
46
46
  const isLoading = status !== 'success' && status !== 'error';
47
47
 
@@ -0,0 +1,29 @@
1
+ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
2
+ import { useQuery } from 'react-query';
3
+
4
+ export const usePlugins = (notifyLoad) => {
5
+ const toggleNotification = useNotification();
6
+ const { get } = useFetchClient();
7
+
8
+ return useQuery(
9
+ ['plugins'],
10
+ async () => {
11
+ const { data } = await get('/admin/plugins');
12
+
13
+ return data;
14
+ },
15
+ {
16
+ onSuccess() {
17
+ if (notifyLoad) {
18
+ notifyLoad();
19
+ }
20
+ },
21
+ onError() {
22
+ toggleNotification({
23
+ type: 'warning',
24
+ message: { id: 'notification.error', defaultMessage: 'An error occured' },
25
+ });
26
+ },
27
+ }
28
+ );
29
+ };
@@ -0,0 +1,44 @@
1
+ import { useNotification } from '@strapi/helper-plugin';
2
+ import qs from 'qs';
3
+ import { useQuery } from 'react-query';
4
+
5
+ import { MARKETPLACE_API_URL } from '../../constants';
6
+
7
+ export const useFetchMarketplacePlugins = (notifyLoad, params = {}) => {
8
+ const toggleNotification = useNotification();
9
+
10
+ return useQuery(
11
+ ['marketplace', 'plugins', params],
12
+ async () => {
13
+ try {
14
+ const queryString = qs.stringify(qs.parse(params));
15
+ const res = await fetch(`${MARKETPLACE_API_URL}/plugins?${queryString}`);
16
+
17
+ if (!res.ok) {
18
+ throw new Error('Failed to fetch marketplace plugins.');
19
+ }
20
+
21
+ const data = await res.json();
22
+
23
+ return data;
24
+ } catch (error) {
25
+ // silence
26
+ }
27
+
28
+ return null;
29
+ },
30
+ {
31
+ onSuccess() {
32
+ if (notifyLoad) {
33
+ notifyLoad();
34
+ }
35
+ },
36
+ onError() {
37
+ toggleNotification({
38
+ type: 'warning',
39
+ message: { id: 'notification.error', defaultMessage: 'An error occured' },
40
+ });
41
+ },
42
+ }
43
+ );
44
+ };
@@ -0,0 +1,44 @@
1
+ import { useNotification } from '@strapi/helper-plugin';
2
+ import qs from 'qs';
3
+ import { useQuery } from 'react-query';
4
+
5
+ import { MARKETPLACE_API_URL } from '../../constants';
6
+
7
+ export const useFetchMarketplaceProviders = (notifyLoad, params = {}) => {
8
+ const toggleNotification = useNotification();
9
+
10
+ return useQuery(
11
+ ['marketplace', 'providers', params],
12
+ async () => {
13
+ try {
14
+ const queryString = qs.stringify(qs.parse(params));
15
+ const res = await fetch(`${MARKETPLACE_API_URL}/providers?${queryString}`);
16
+
17
+ if (!res.ok) {
18
+ throw new Error('Failed to fetch marketplace providers.');
19
+ }
20
+
21
+ const data = await res.json();
22
+
23
+ return data;
24
+ } catch (error) {
25
+ // silence
26
+ }
27
+
28
+ return null;
29
+ },
30
+ {
31
+ onSuccess() {
32
+ if (notifyLoad) {
33
+ notifyLoad();
34
+ }
35
+ },
36
+ onError() {
37
+ toggleNotification({
38
+ type: 'warning',
39
+ message: { id: 'notification.error', defaultMessage: 'An error occured' },
40
+ });
41
+ },
42
+ }
43
+ );
44
+ };
@@ -3,8 +3,8 @@ import { useEffect, useState } from 'react';
3
3
  import { useNotifyAT } from '@strapi/design-system';
4
4
  import { useIntl } from 'react-intl';
5
5
 
6
- import useFetchMarketplacePlugins from '../../../hooks/marketplace/useFetchMarketplacePlugins';
7
- import useFetchMarketplaceProviders from '../../../hooks/marketplace/useFetchMarketplaceProviders';
6
+ import { useFetchMarketplacePlugins } from '../hooks/useFetchMarketplacePlugins';
7
+ import { useFetchMarketplaceProviders } from '../hooks/useFetchMarketplaceProviders';
8
8
 
9
9
  function useMarketplaceData({ npmPackageType, debouncedSearch, query, tabQuery }) {
10
10
  const { notifyStatus } = useNotifyAT();
@@ -27,16 +27,16 @@ import {
27
27
  import { ArrowLeft } from '@strapi/icons';
28
28
  import { format } from 'date-fns';
29
29
  import { Formik } from 'formik';
30
- import get from 'lodash/get';
31
30
  import isEmpty from 'lodash/isEmpty';
32
31
  import { useIntl } from 'react-intl';
33
32
  import { useSelector } from 'react-redux';
34
33
  import { useHistory, useRouteMatch } from 'react-router-dom';
35
34
  import styled from 'styled-components';
36
35
 
37
- import { useFetchPermissionsLayout, useFetchRole } from '../../../../../hooks';
36
+ import { useAdminRolePermissions } from '../../../../../hooks/useAdminRolePermissions';
38
37
  import { selectAdminPermissions } from '../../../../App/selectors';
39
38
  import Permissions from '../EditPage/components/Permissions';
39
+ import { useAdminRolePermissionLayout } from '../hooks/useAdminRolePermissionLayout';
40
40
 
41
41
  import schema from './utils/schema';
42
42
 
@@ -51,6 +51,7 @@ const UsersRoleNumber = styled.div`
51
51
  `;
52
52
 
53
53
  const CreatePage = () => {
54
+ const route = useRouteMatch('/settings/roles/duplicate/:id');
54
55
  const toggleNotification = useNotification();
55
56
  const { lockApp, unlockApp } = useOverlayBlocker();
56
57
  const { formatMessage } = useIntl();
@@ -58,17 +59,30 @@ const CreatePage = () => {
58
59
  const { replace } = useHistory();
59
60
  const permissionsRef = useRef();
60
61
  const { trackUsage } = useTracking();
61
- const params = useRouteMatch('/settings/roles/duplicate/:id');
62
- const id = get(params, 'params.id', null);
63
- const { isLoading: isLayoutLoading, data: permissionsLayout } = useFetchPermissionsLayout();
64
- const { permissions: rolePermissions, isLoading: isRoleLoading } = useFetchRole(id);
65
62
  const { post, put } = useFetchClient();
66
63
 
64
+ const { params } = route ?? {};
65
+
66
+ const { isLoading: isLoadingPermissionsLayout, data: permissionsLayout } =
67
+ useAdminRolePermissionLayout(params?.id, {
68
+ cacheTime: 0,
69
+ });
70
+
71
+ const { permissions: rolePermissions, isLoading: isLoadingRole } = useAdminRolePermissions(
72
+ { id: params?.id },
73
+ {
74
+ cacheTime: 0,
75
+
76
+ // only fetch permissions if a role is cloned
77
+ enabled: !!params?.id,
78
+ }
79
+ );
80
+
67
81
  const handleCreateRoleSubmit = (data) => {
68
82
  lockApp();
69
83
  setIsSubmiting(true);
70
84
 
71
- if (id) {
85
+ if (params?.id) {
72
86
  trackUsage('willDuplicateRole');
73
87
  } else {
74
88
  trackUsage('willCreateNewRole');
@@ -78,7 +92,7 @@ const CreatePage = () => {
78
92
  .then(async ({ data: res }) => {
79
93
  const { permissionsToSend } = permissionsRef.current.getPermissions();
80
94
 
81
- if (id) {
95
+ if (params?.id) {
82
96
  trackUsage('didDuplicateRole');
83
97
  } else {
84
98
  trackUsage('didCreateNewRole');
@@ -213,6 +227,7 @@ const CreatePage = () => {
213
227
  defaultMessage: 'Name',
214
228
  })}
215
229
  onChange={handleChange}
230
+ required
216
231
  value={values.name}
217
232
  />
218
233
  </GridItem>
@@ -232,7 +247,7 @@ const CreatePage = () => {
232
247
  </Grid>
233
248
  </Flex>
234
249
  </Box>
235
- {!isLayoutLoading && !isRoleLoading ? (
250
+ {!isLoadingPermissionsLayout && !isLoadingRole ? (
236
251
  <Box shadow="filterShadow" hasRadius>
237
252
  <Permissions
238
253
  isFormDisabled={false}
@@ -65,6 +65,7 @@ const RoleForm = ({ disabled, role, values, errors, onChange, onBlur }) => {
65
65
  })}
66
66
  onChange={onChange}
67
67
  onBlur={onBlur}
68
+ required
68
69
  value={values.name || ''}
69
70
  />
70
71
  </GridItem>
@@ -5,6 +5,7 @@ import {
5
5
  Link,
6
6
  LoadingIndicatorPage,
7
7
  SettingsPageTitle,
8
+ useAPIErrorHandler,
8
9
  useFetchClient,
9
10
  useNotification,
10
11
  useOverlayBlocker,
@@ -12,11 +13,12 @@ import {
12
13
  } from '@strapi/helper-plugin';
13
14
  import { ArrowLeft } from '@strapi/icons';
14
15
  import { Formik } from 'formik';
15
- import get from 'lodash/get';
16
16
  import { useIntl } from 'react-intl';
17
17
  import { useRouteMatch } from 'react-router-dom';
18
18
 
19
- import { useFetchPermissionsLayout, useFetchRole } from '../../../../../hooks';
19
+ import { useAdminRolePermissions } from '../../../../../hooks/useAdminRolePermissions';
20
+ import { useAdminRoles } from '../../../../../hooks/useAdminRoles';
21
+ import { useAdminRolePermissionLayout } from '../hooks/useAdminRolePermissionLayout';
20
22
 
21
23
  import { Permissions, RoleForm } from './components';
22
24
  import schema from './utils/schema';
@@ -27,21 +29,37 @@ const EditPage = () => {
27
29
  const {
28
30
  params: { id },
29
31
  } = useRouteMatch('/settings/roles/:id');
32
+ const { put } = useFetchClient();
30
33
  const [isSubmitting, setIsSubmiting] = useState(false);
31
34
  const permissionsRef = useRef();
32
35
  const { lockApp, unlockApp } = useOverlayBlocker();
33
36
  const { trackUsage } = useTracking();
37
+ const { formatAPIError } = useAPIErrorHandler();
38
+
39
+ const { isLoading: isLoadingPermissionsLayout, data: permissionsLayout } =
40
+ useAdminRolePermissionLayout(id, {
41
+ cacheTime: 0,
42
+ });
34
43
 
35
- const { isLoading: isLayoutLoading, data: permissionsLayout } = useFetchPermissionsLayout(id);
36
44
  const {
37
- role,
38
- permissions: rolePermissions,
45
+ roles: [role = {}],
39
46
  isLoading: isRoleLoading,
40
- onSubmitSucceeded,
41
- } = useFetchRole(id);
47
+ refetch: refetchRole,
48
+ } = useAdminRoles(
49
+ { id },
50
+ {
51
+ cacheTime: 0,
52
+ }
53
+ );
42
54
 
43
- const { put } = useFetchClient();
55
+ const { permissions, isLoading: isLoadingPermissions } = useAdminRolePermissions(
56
+ { id },
57
+ {
58
+ cacheTime: 0,
59
+ }
60
+ );
44
61
 
62
+ // TODO: this should use a react-query mutation
45
63
  const handleEditRoleSubmit = async (data) => {
46
64
  try {
47
65
  lockApp();
@@ -62,21 +80,17 @@ const EditPage = () => {
62
80
  }
63
81
 
64
82
  permissionsRef.current.setFormAfterSubmit();
65
- onSubmitSucceeded({ name: data.name, description: data.description });
83
+
84
+ await refetchRole();
66
85
 
67
86
  toggleNotification({
68
87
  type: 'success',
69
88
  message: { id: 'notification.success.saved' },
70
89
  });
71
- } catch (err) {
72
- console.error(err.response);
73
-
74
- const errorMessage = get(err, 'response.payload.message', 'An error occured');
75
- const message = get(err, 'response.payload.data.permissions[0]', errorMessage);
76
-
90
+ } catch (error) {
77
91
  toggleNotification({
78
92
  type: 'warning',
79
- message,
93
+ message: formatAPIError(error),
80
94
  });
81
95
  } finally {
82
96
  setIsSubmiting(false);
@@ -84,7 +98,7 @@ const EditPage = () => {
84
98
  }
85
99
  };
86
100
 
87
- const isFormDisabled = role.code === 'strapi-super-admin';
101
+ const isFormDisabled = !isRoleLoading && role.code === 'strapi-super-admin';
88
102
 
89
103
  return (
90
104
  <Main>
@@ -137,7 +151,7 @@ const EditPage = () => {
137
151
  <ContentLayout>
138
152
  <Flex direction="column" alignItems="stretch" gap={6}>
139
153
  <RoleForm
140
- isLoading={isRoleLoading}
154
+ isLoading={isRoleLoading || isLoadingPermissions}
141
155
  disabled={isFormDisabled}
142
156
  errors={errors}
143
157
  values={values}
@@ -145,11 +159,11 @@ const EditPage = () => {
145
159
  onBlur={handleBlur}
146
160
  role={role}
147
161
  />
148
- {!isLayoutLoading && !isRoleLoading ? (
162
+ {!isLoadingPermissionsLayout && !isRoleLoading && !isLoadingPermissions ? (
149
163
  <Box shadow="filterShadow" hasRadius>
150
164
  <Permissions
151
165
  isFormDisabled={isFormDisabled}
152
- permissions={rolePermissions}
166
+ permissions={permissions}
153
167
  ref={permissionsRef}
154
168
  layout={permissionsLayout}
155
169
  />