diff --git a/packages/plugins/users-permissions/admin/src/index.js b/packages/plugins/users-permissions/admin/src/index.js index c2b62a2786..be4c3ff22a 100644 --- a/packages/plugins/users-permissions/admin/src/index.js +++ b/packages/plugins/users-permissions/admin/src/index.js @@ -27,22 +27,22 @@ export default { }, }, [ - // { - // intlLabel: { - // id: getTrad('HeaderNav.link.roles'), - // defaultMessage: 'Roles', - // }, - // id: 'roles', - // to: `/settings/${pluginId}/roles`, - // Component: async () => { - // const component = await import( - // /* webpackChunkName: "users-roles-settings-page" */ './pages/Roles' - // ); + { + intlLabel: { + id: getTrad('HeaderNav.link.roles'), + defaultMessage: 'Roles', + }, + id: 'roles', + to: `/settings/${pluginId}/roles`, + Component: async () => { + const component = await import( + /* webpackChunkName: "users-roles-settings-page" */ './pages/Roles' + ); - // return component; - // }, - // permissions: pluginPermissions.accessRoles, - // }, + return component; + }, + permissions: pluginPermissions.accessRoles, + }, { intlLabel: { id: getTrad('HeaderNav.link.providers'), diff --git a/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/index.js b/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/index.js index 4b010081c0..68b0329801 100644 --- a/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/index.js +++ b/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/index.js @@ -1,68 +1,36 @@ import React, { useState, useRef } from 'react'; -import { Header } from '@buffetjs/custom'; -import { Padded } from '@buffetjs/core'; +import { Main, HeaderLayout, Button } from '@strapi/parts'; import { Formik } from 'formik'; import { useIntl } from 'react-intl'; import { useRouteMatch } from 'react-router-dom'; -import { request, useNotification, useOverlayBlocker } from '@strapi/helper-plugin'; +import { + request, + useNotification, + useOverlayBlocker, + SettingsPageTitle, +} from '@strapi/helper-plugin'; -import BaselineAlignement from '../../../components/BaselineAlignement'; -import ContainerFluid from '../../../components/ContainerFluid'; -import FormCard from '../../../components/FormBloc'; -import SizedInput from '../../../components/SizedInput'; import getTrad from '../../../utils/getTrad'; import pluginId from '../../../pluginId'; -import UsersPermissions from '../../../components/UsersPermissions'; import { usePlugins, useFetchRole } from '../../../hooks'; import schema from './utils/schema'; const EditPage = () => { const { formatMessage } = useIntl(); - const [isSubmiting, setIsSubmiting] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); const toggleNotification = useNotification(); const { lockApp, unlockApp } = useOverlayBlocker(); const { params: { id }, } = useRouteMatch(`/settings/${pluginId}/roles/:id`); - const { routes, policies, isLoading } = usePlugins(); - const { role, isLoading: isRoleLoading, onSubmitSucceeded } = useFetchRole(id); + const { isLoading } = usePlugins(); + const { role, onSubmitSucceeded } = useFetchRole(id); const permissionsRef = useRef(); - const headerActions = (handleSubmit, handleReset) => { - if (isLoading) { - return []; - } - - return [ - { - label: formatMessage({ - id: 'app.components.Button.reset', - defaultMessage: 'Reset', - }), - onClick: () => { - handleReset(); - permissionsRef.current.resetForm(); - }, - color: 'cancel', - type: 'button', - }, - { - label: formatMessage({ - id: 'app.components.Button.save', - defaultMessage: 'Save', - }), - onClick: handleSubmit, - color: 'success', - type: 'submit', - isLoading: isSubmiting, - }, - ]; - }; - const handleCreateRoleSubmit = data => { lockApp(); - setIsSubmiting(true); + setIsSubmitting(true); const permissions = permissionsRef.current.getPermissions(); @@ -88,74 +56,45 @@ const EditPage = () => { }); }) .finally(() => { - setIsSubmiting(false); + setIsSubmitting(false); unlockApp(); }); }; return ( - - {({ handleSubmit, values, errors, handleReset, handleChange, handleBlur }) => ( -
- -
+ + + {({ handleSubmit }) => ( + + + {formatMessage({ + id: 'app.components.Button.save', + defaultMessage: 'Save', + })} + + ) + } + title={role.name} + subtitle={role.description} /> - - - - - - -
- {!isLoading && !isRoleLoading && ( - - )} - - - )} - + + )} + + ); }; diff --git a/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/tests/index.test.js b/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/tests/index.test.js new file mode 100644 index 0000000000..74230e7122 --- /dev/null +++ b/packages/plugins/users-permissions/admin/src/pages/Roles/EditPage/tests/index.test.js @@ -0,0 +1,156 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import { ThemeProvider, lightTheme } from '@strapi/parts'; +import { Router, Switch, Route } from 'react-router-dom'; +import { IntlProvider } from 'react-intl'; +import { createMemoryHistory } from 'history'; + +import pluginId from '../../../../pluginId'; +import RolesEditPage from '..'; + +jest.mock('@strapi/helper-plugin', () => ({ + ...jest.requireActual('@strapi/helper-plugin'), + useNotification: jest.fn(() => jest.fn()), + useOverlayBlocker: jest.fn(() => ({ lockApp: jest.fn(), unlockApp: jest.fn() })), +})); + +jest.mock('../../../../hooks', () => { + const originalModule = jest.requireActual('../../../../hooks'); + + return { + ...originalModule, + useFetchRole: id => { + const role = { + id, + name: 'Authenticated', + description: 'Default role given to authenticated user.', + type: 'authenticated', + }; + const onSubmitSucceed = jest.fn(); + + return { role, onSubmitSucceed }; + }, + }; +}); + +it('renders users-permissions edit role and matches snapshot', () => { + const history = createMemoryHistory(); + + const app = ( + + + + + + + + + + ); + + const { container } = render(app); + history.push(`/settings/${pluginId}/roles/1`); + + expect(container.firstChild).toMatchInlineSnapshot(` + .c4 { + font-weight: 600; + font-size: 2rem; + line-height: 1.25; + color: #32324d; + } + + .c5 { + font-weight: 400; + font-size: 0.875rem; + line-height: 1.43; + color: #666687; + } + + .c6 { + font-size: 1rem; + line-height: 1.5; + } + + .c1 { + background: #f6f6f9; + padding-top: 56px; + padding-right: 56px; + padding-bottom: 56px; + padding-left: 56px; + } + + .c2 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + } + + .c3 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + } + + .c0 { + outline: none; + } + +
+
+
+
+
+
+

+ Authenticated +

+
+
+

+ Default role given to authenticated user. +

+
+
+
+
+ `); +});