@strapi/plugin-users-permissions 4.12.6 → 4.12.7

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