@strapi/plugin-users-permissions 4.12.5 → 4.12.6

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 (32) hide show
  1. package/admin/src/components/Permissions/index.js +2 -4
  2. package/admin/src/index.js +7 -8
  3. package/admin/src/pages/AdvancedSettings/index.js +41 -24
  4. package/admin/src/pages/EmailTemplates/index.js +62 -47
  5. package/admin/src/pages/Providers/index.js +64 -58
  6. package/admin/src/{hooks → pages/Roles/hooks}/usePlugins.js +15 -8
  7. package/admin/src/pages/Roles/index.js +10 -7
  8. package/admin/src/pages/Roles/pages/CreatePage.js +190 -0
  9. package/admin/src/pages/Roles/pages/EditPage.js +211 -0
  10. package/admin/src/pages/Roles/{ListPage → pages/ListPage}/components/TableBody.js +41 -11
  11. package/admin/src/pages/Roles/{ListPage → pages/ListPage}/index.js +19 -15
  12. package/jest.config.front.js +1 -1
  13. package/package.json +4 -4
  14. package/admin/src/hooks/index.js +0 -5
  15. package/admin/src/hooks/useFetchRole/index.js +0 -67
  16. package/admin/src/hooks/useFetchRole/reducer.js +0 -31
  17. package/admin/src/hooks/useForm/index.js +0 -68
  18. package/admin/src/hooks/useForm/reducer.js +0 -40
  19. package/admin/src/hooks/useRolesList/index.js +0 -65
  20. package/admin/src/hooks/useRolesList/init.js +0 -5
  21. package/admin/src/hooks/useRolesList/reducer.js +0 -31
  22. package/admin/src/pages/AdvancedSettings/utils/api.js +0 -16
  23. package/admin/src/pages/EmailTemplates/utils/api.js +0 -16
  24. package/admin/src/pages/Providers/reducer.js +0 -54
  25. package/admin/src/pages/Providers/utils/api.js +0 -24
  26. package/admin/src/pages/Providers/utils/createProvidersArray.js +0 -21
  27. package/admin/src/pages/Roles/CreatePage.js +0 -185
  28. package/admin/src/pages/Roles/EditPage.js +0 -197
  29. package/admin/src/pages/Roles/ProtectedCreatePage.js +0 -15
  30. package/admin/src/pages/Roles/ProtectedEditPage.js +0 -15
  31. package/admin/src/pages/Roles/ProtectedListPage.js +0 -17
  32. /package/admin/src/pages/Roles/{ListPage → pages/ListPage}/utils/api.js +0 -0
@@ -1,197 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
-
3
- import {
4
- ContentLayout,
5
- HeaderLayout,
6
- Main,
7
- Button,
8
- Flex,
9
- Box,
10
- TextInput,
11
- Textarea,
12
- Typography,
13
- GridItem,
14
- Grid,
15
- } from '@strapi/design-system';
16
- import {
17
- useFetchClient,
18
- useOverlayBlocker,
19
- SettingsPageTitle,
20
- LoadingIndicatorPage,
21
- Form,
22
- useNotification,
23
- Link,
24
- } from '@strapi/helper-plugin';
25
- import { ArrowLeft, Check } from '@strapi/icons';
26
- import { Formik } from 'formik';
27
- import { useIntl } from 'react-intl';
28
- import { useRouteMatch } from 'react-router-dom';
29
-
30
- import UsersPermissions from '../../components/UsersPermissions';
31
- import { usePlugins, useFetchRole } from '../../hooks';
32
- import pluginId from '../../pluginId';
33
- import getTrad from '../../utils/getTrad';
34
-
35
- import { createRoleSchema } from './constants';
36
-
37
- const EditPage = () => {
38
- const { formatMessage } = useIntl();
39
- const [isSubmitting, setIsSubmitting] = useState(false);
40
- const toggleNotification = useNotification();
41
- const { lockApp, unlockApp } = useOverlayBlocker();
42
- const {
43
- params: { id },
44
- } = useRouteMatch(`/settings/${pluginId}/roles/:id`);
45
- const { isLoading: isLoadingPlugins, routes } = usePlugins();
46
- const { role, onSubmitSucceeded, isLoading: isLoadingRole } = useFetchRole(id);
47
- const permissionsRef = useRef();
48
- const { put } = useFetchClient();
49
-
50
- const handleEditRoleSubmit = async (data) => {
51
- // Set loading state
52
- lockApp();
53
- setIsSubmitting(true);
54
- try {
55
- const permissions = permissionsRef.current.getPermissions();
56
- // Update role in Strapi
57
- await put(`/${pluginId}/roles/${id}`, { ...data, ...permissions, users: [] });
58
- // Notify success
59
- onSubmitSucceeded({ name: data.name, description: data.description });
60
- toggleNotification({
61
- type: 'success',
62
- message: {
63
- id: getTrad('Settings.roles.edited'),
64
- defaultMessage: 'Role edited',
65
- },
66
- });
67
- } catch (err) {
68
- console.error(err);
69
- toggleNotification({
70
- type: 'warning',
71
- message: {
72
- id: 'notification.error',
73
- defaultMessage: 'An error occurred',
74
- },
75
- });
76
- }
77
- // Unset loading state
78
- setIsSubmitting(false);
79
- unlockApp();
80
- };
81
-
82
- if (isLoadingRole) {
83
- return <LoadingIndicatorPage />;
84
- }
85
-
86
- return (
87
- <Main>
88
- <SettingsPageTitle name="Roles" />
89
- <Formik
90
- enableReinitialize
91
- initialValues={{ name: role.name, description: role.description }}
92
- onSubmit={handleEditRoleSubmit}
93
- validationSchema={createRoleSchema}
94
- >
95
- {({ handleSubmit, values, handleChange, errors }) => (
96
- <Form noValidate onSubmit={handleSubmit}>
97
- <HeaderLayout
98
- primaryAction={
99
- !isLoadingPlugins && (
100
- <Button
101
- disabled={role.code === 'strapi-super-admin'}
102
- type="submit"
103
- loading={isSubmitting}
104
- startIcon={<Check />}
105
- >
106
- {formatMessage({
107
- id: 'global.save',
108
- defaultMessage: 'Save',
109
- })}
110
- </Button>
111
- )
112
- }
113
- title={role.name}
114
- subtitle={role.description}
115
- navigationAction={
116
- <Link startIcon={<ArrowLeft />} to="/settings/users-permissions/roles">
117
- {formatMessage({
118
- id: 'global.back',
119
- defaultMessage: 'Back',
120
- })}
121
- </Link>
122
- }
123
- />
124
- <ContentLayout>
125
- <Flex direction="column" alignItems="stretch" gap={7}>
126
- <Box
127
- background="neutral0"
128
- hasRadius
129
- shadow="filterShadow"
130
- paddingTop={6}
131
- paddingBottom={6}
132
- paddingLeft={7}
133
- paddingRight={7}
134
- >
135
- <Flex direction="column" alignItems="stretch" gap={4}>
136
- <Typography variant="delta" as="h2">
137
- {formatMessage({
138
- id: getTrad('EditPage.form.roles'),
139
- defaultMessage: 'Role details',
140
- })}
141
- </Typography>
142
- <Grid gap={4}>
143
- <GridItem col={6}>
144
- <TextInput
145
- name="name"
146
- value={values.name || ''}
147
- onChange={handleChange}
148
- label={formatMessage({
149
- id: 'global.name',
150
- defaultMessage: 'Name',
151
- })}
152
- error={
153
- errors.name
154
- ? formatMessage({ id: errors.name, defaultMessage: 'Invalid value' })
155
- : null
156
- }
157
- />
158
- </GridItem>
159
- <GridItem col={6}>
160
- <Textarea
161
- id="description"
162
- value={values.description || ''}
163
- onChange={handleChange}
164
- label={formatMessage({
165
- id: 'global.description',
166
- defaultMessage: 'Description',
167
- })}
168
- error={
169
- errors.description
170
- ? formatMessage({
171
- id: errors.description,
172
- defaultMessage: 'Invalid value',
173
- })
174
- : null
175
- }
176
- />
177
- </GridItem>
178
- </Grid>
179
- </Flex>
180
- </Box>
181
- {!isLoadingPlugins && (
182
- <UsersPermissions
183
- ref={permissionsRef}
184
- permissions={role.permissions}
185
- routes={routes}
186
- />
187
- )}
188
- </Flex>
189
- </ContentLayout>
190
- </Form>
191
- )}
192
- </Formik>
193
- </Main>
194
- );
195
- };
196
-
197
- export default EditPage;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesCreatePage from './CreatePage';
8
-
9
- const ProtectedRolesCreatePage = () => (
10
- <CheckPagePermissions permissions={PERMISSIONS.createRole}>
11
- <RolesCreatePage />
12
- </CheckPagePermissions>
13
- );
14
-
15
- export default ProtectedRolesCreatePage;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesEditPage from './EditPage';
8
-
9
- const ProtectedRolesEditPage = () => (
10
- <CheckPagePermissions permissions={PERMISSIONS.updateRole}>
11
- <RolesEditPage />
12
- </CheckPagePermissions>
13
- );
14
-
15
- export default ProtectedRolesEditPage;
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
-
3
- import { CheckPagePermissions } from '@strapi/helper-plugin';
4
-
5
- import { PERMISSIONS } from '../../constants';
6
-
7
- import RolesListPage from './ListPage';
8
-
9
- const ProtectedRolesListPage = () => {
10
- return (
11
- <CheckPagePermissions permissions={PERMISSIONS.accessRoles}>
12
- <RolesListPage />
13
- </CheckPagePermissions>
14
- );
15
- };
16
-
17
- export default ProtectedRolesListPage;