@strapi/admin 4.4.0-beta.3 → 4.4.0-rc.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 (92) hide show
  1. package/admin/src/StrapiApp.js +2 -0
  2. package/admin/src/components/AuthenticatedApp/index.js +2 -2
  3. package/admin/src/components/LanguageProvider/index.js +1 -0
  4. package/admin/src/components/ThemeToggleProvider/index.js +21 -10
  5. package/admin/src/content-manager/components/DynamicTable/index.js +2 -2
  6. package/admin/src/content-manager/components/InputJSON/index.js +2 -0
  7. package/admin/src/contexts/ApiTokenPermissions/index.js +24 -0
  8. package/admin/src/hooks/index.js +1 -0
  9. package/admin/src/hooks/useRegenerate/index.js +34 -0
  10. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ActionBoundRoutes/index.js +56 -0
  11. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/getMethodColor.js +41 -0
  12. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/BoundRoute/index.js +72 -0
  13. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/CheckBoxWrapper.js +30 -0
  14. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/CollapsableContentType/index.js +150 -0
  15. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/ContenTypesSection/index.js +37 -0
  16. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormApiTokenContainer/index.js +254 -0
  17. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormBody/index.js +77 -0
  18. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/FormHead/index.js +85 -0
  19. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Permissions/index.js +40 -0
  20. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/components/Regenerate/index.js +68 -0
  21. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/index.js +215 -197
  22. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/init.js +13 -0
  23. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/reducer.js +72 -0
  24. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/getDateOfExpiration.js +16 -0
  25. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/index.js +5 -0
  26. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/schema.js +2 -1
  27. package/admin/src/pages/SettingsPage/pages/ApiTokens/EditView/utils/transformPermissionsData.js +36 -0
  28. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DefaultButton/index.js +63 -0
  29. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/DeleteButton/index.js +1 -0
  30. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/ReadButton/index.js +19 -0
  31. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/UpdateButton/index.js +3 -36
  32. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/DynamicTable/index.js +13 -11
  33. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/index.js +3 -2
  34. package/admin/src/pages/SettingsPage/pages/ApiTokens/ListView/utils/tableHeaders.js +8 -8
  35. package/admin/src/pages/SettingsPage/pages/ApiTokens/ProtectedEditView/index.js +1 -1
  36. package/admin/src/permissions/defaultPermissions.js +2 -6
  37. package/admin/src/translations/en.json +17 -0
  38. package/admin/src/translations/zh-Hans.json +0 -1
  39. package/build/2077.c935ee42.chunk.js +205 -0
  40. package/build/4318.7d167b58.chunk.js +30 -0
  41. package/build/{4715.3f6cac0a.chunk.js → 4715.58cd558f.chunk.js} +32 -31
  42. package/build/4982.05eda880.chunk.js +324 -0
  43. package/build/7379.d246dd38.chunk.js +1 -0
  44. package/build/{7866.c793a31d.chunk.js → 7866.1201afbd.chunk.js} +2 -2
  45. package/build/{8773.eccaa5f3.chunk.js → 8773.c06c24c0.chunk.js} +2 -2
  46. package/build/{Admin-authenticatedApp.50e41ff2.chunk.js → Admin-authenticatedApp.9dec5230.chunk.js} +6 -6
  47. package/build/{Admin_homePage.118926e0.chunk.js → Admin_homePage.6d5e3236.chunk.js} +1 -1
  48. package/build/{Admin_profilePage.9d50ac44.chunk.js → Admin_profilePage.da32abbc.chunk.js} +1 -1
  49. package/build/{Admin_settingsPage.98a711e5.chunk.js → Admin_settingsPage.98e2a62b.chunk.js} +16 -16
  50. package/build/admin-app.a61d5c2e.chunk.js +112 -0
  51. package/build/admin-edit-roles-page.4dd6bcb9.chunk.js +1 -0
  52. package/build/api-tokens-create-page.93dd0689.chunk.js +1 -0
  53. package/build/api-tokens-edit-page.b0adac81.chunk.js +1 -0
  54. package/build/api-tokens-list-page.bb36535f.chunk.js +16 -0
  55. package/build/{content-manager.2a6f876d.chunk.js → content-manager.feb0d540.chunk.js} +2 -2
  56. package/build/{content-type-builder.d4610e20.chunk.js → content-type-builder.a684b2e8.chunk.js} +11 -11
  57. package/build/en-json.a9918c93.chunk.js +1 -0
  58. package/build/index.html +1 -1
  59. package/build/{main.fdc482f3.js → main.e4065f58.js} +1304 -1288
  60. package/build/{runtime~main.29105d25.js → runtime~main.4204f341.js} +2 -2
  61. package/build/sso-settings-page.9ceb0140.chunk.js +1 -0
  62. package/build/{webhook-edit-page.d2ea3351.chunk.js → webhook-edit-page.9e46fc3f.chunk.js} +1 -1
  63. package/build/{zh-Hans-json.77a42bc5.chunk.js → zh-Hans-json.9c99f8d4.chunk.js} +1 -1
  64. package/package.json +10 -9
  65. package/server/bootstrap.js +19 -1
  66. package/server/config/admin-actions.js +20 -0
  67. package/server/content-types/api-token-permission.js +36 -0
  68. package/server/content-types/api-token.js +25 -1
  69. package/server/content-types/index.js +1 -0
  70. package/server/controllers/api-token.js +24 -1
  71. package/server/controllers/content-api.js +15 -0
  72. package/server/controllers/index.js +1 -0
  73. package/server/routes/api-tokens.js +11 -0
  74. package/server/routes/content-api.js +20 -0
  75. package/server/routes/index.js +2 -0
  76. package/server/services/api-token.js +310 -29
  77. package/server/services/constants.js +10 -0
  78. package/server/services/permission/engine.js +36 -226
  79. package/server/services/permission.js +4 -1
  80. package/server/strategies/admin.js +7 -1
  81. package/server/strategies/api-token.js +71 -11
  82. package/server/validation/api-tokens.js +12 -2
  83. package/build/2077.61cebc93.chunk.js +0 -195
  84. package/build/4982.c6f88c5d.chunk.js +0 -314
  85. package/build/admin-app.8bc3e80f.chunk.js +0 -112
  86. package/build/admin-edit-roles-page.554ba3fa.chunk.js +0 -1
  87. package/build/api-tokens-create-page.4c262d6e.chunk.js +0 -1
  88. package/build/api-tokens-edit-page.10a9d368.chunk.js +0 -1
  89. package/build/api-tokens-list-page.442c9f3c.chunk.js +0 -15
  90. package/build/en-json.12bc5a14.chunk.js +0 -1
  91. package/build/sso-settings-page.445184e0.chunk.js +0 -1
  92. package/server/services/permission/engine-hooks.js +0 -82
@@ -0,0 +1,254 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { usePersistentState } from '@strapi/helper-plugin';
4
+ import PropTypes from 'prop-types';
5
+ import { Box } from '@strapi/design-system/Box';
6
+ import { Grid, GridItem } from '@strapi/design-system/Grid';
7
+ import { Select, Option } from '@strapi/design-system/Select';
8
+ import { Stack } from '@strapi/design-system/Stack';
9
+ import { Textarea } from '@strapi/design-system/Textarea';
10
+ import { TextInput } from '@strapi/design-system/TextInput';
11
+ import { Typography } from '@strapi/design-system/Typography';
12
+ import { getDateOfExpiration } from '../../utils';
13
+
14
+ const FormApiTokenContainer = ({
15
+ errors,
16
+ onChange,
17
+ canEditInputs,
18
+ isCreating,
19
+ values,
20
+ apiToken,
21
+ onDispatch,
22
+ setHasChangedPermissions,
23
+ }) => {
24
+ const { formatMessage } = useIntl();
25
+ const [lang] = usePersistentState('strapi-admin-language', 'en');
26
+
27
+ const handleChangeSelectApiTokenType = ({ target: { value } }) => {
28
+ setHasChangedPermissions(false);
29
+
30
+ if (value === 'full-access') {
31
+ onDispatch({
32
+ type: 'SELECT_ALL_ACTIONS',
33
+ });
34
+ }
35
+ if (value === 'read-only') {
36
+ onDispatch({
37
+ type: 'ON_CHANGE_READ_ONLY',
38
+ });
39
+ }
40
+ };
41
+
42
+ return (
43
+ <Box
44
+ background="neutral0"
45
+ hasRadius
46
+ shadow="filterShadow"
47
+ paddingTop={6}
48
+ paddingBottom={6}
49
+ paddingLeft={7}
50
+ paddingRight={7}
51
+ >
52
+ <Stack spacing={4}>
53
+ <Typography variant="delta" as="h2">
54
+ {formatMessage({
55
+ id: 'global.details',
56
+ defaultMessage: 'Details',
57
+ })}
58
+ </Typography>
59
+ <Grid gap={5}>
60
+ <GridItem key="name" col={6} xs={12}>
61
+ <TextInput
62
+ name="name"
63
+ error={
64
+ errors.name
65
+ ? formatMessage(
66
+ errors.name?.id
67
+ ? errors.name
68
+ : { id: errors.name, defaultMessage: errors.name }
69
+ )
70
+ : null
71
+ }
72
+ label={formatMessage({
73
+ id: 'Settings.apiTokens.form.name',
74
+ defaultMessage: 'Name',
75
+ })}
76
+ onChange={onChange}
77
+ value={values.name}
78
+ disabled={!canEditInputs}
79
+ required
80
+ />
81
+ </GridItem>
82
+ <GridItem key="description" col={6} xs={12}>
83
+ <Textarea
84
+ label={formatMessage({
85
+ id: 'Settings.apiTokens.form.description',
86
+ defaultMessage: 'Description',
87
+ })}
88
+ name="description"
89
+ error={
90
+ errors.description
91
+ ? formatMessage(
92
+ errors.description?.id
93
+ ? errors.description
94
+ : {
95
+ id: errors.description,
96
+ defaultMessage: errors.description,
97
+ }
98
+ )
99
+ : null
100
+ }
101
+ onChange={onChange}
102
+ disabled={!canEditInputs}
103
+ >
104
+ {values.description}
105
+ </Textarea>
106
+ </GridItem>
107
+ <GridItem key="lifespan" col={6} xs={12}>
108
+ <Select
109
+ name="lifespan"
110
+ label={formatMessage({
111
+ id: 'Settings.apiTokens.form.duration',
112
+ defaultMessage: 'Token duration',
113
+ })}
114
+ value={values.lifespan}
115
+ error={
116
+ errors.lifespan
117
+ ? formatMessage(
118
+ errors.lifespan?.id
119
+ ? errors.lifespan
120
+ : { id: errors.lifespan, defaultMessage: errors.lifespan }
121
+ )
122
+ : null
123
+ }
124
+ onChange={(value) => {
125
+ onChange({ target: { name: 'lifespan', value } });
126
+ }}
127
+ required
128
+ disabled={!isCreating}
129
+ placeholder="Select"
130
+ >
131
+ <Option value="604800000">
132
+ {formatMessage({
133
+ id: 'Settings.apiTokens.duration.7-days',
134
+ defaultMessage: '7 days',
135
+ })}
136
+ </Option>
137
+ <Option value="2592000000">
138
+ {formatMessage({
139
+ id: 'Settings.apiTokens.duration.30-days',
140
+ defaultMessage: '30 days',
141
+ })}
142
+ </Option>
143
+ <Option value="7776000000">
144
+ {formatMessage({
145
+ id: 'Settings.apiTokens.duration.90-days',
146
+ defaultMessage: '90 days',
147
+ })}
148
+ </Option>
149
+ <Option value={null}>
150
+ {formatMessage({
151
+ id: 'Settings.apiTokens.duration.unlimited',
152
+ defaultMessage: 'Unlimited',
153
+ })}
154
+ </Option>
155
+ </Select>
156
+ <Typography variant="pi" textColor="neutral600">
157
+ {!isCreating &&
158
+ `${formatMessage({
159
+ id: 'Settings.apiTokens.duration.expiration-date',
160
+ defaultMessage: 'Expiration date',
161
+ })}: ${getDateOfExpiration(
162
+ apiToken?.createdAt,
163
+ parseInt(values.lifespan, 10),
164
+ lang
165
+ )}`}
166
+ </Typography>
167
+ </GridItem>
168
+
169
+ <GridItem key="type" col={6} xs={12}>
170
+ <Select
171
+ name="type"
172
+ label={formatMessage({
173
+ id: 'Settings.apiTokens.form.type',
174
+ defaultMessage: 'Token type',
175
+ })}
176
+ value={values?.type}
177
+ error={
178
+ errors.type
179
+ ? formatMessage(
180
+ errors.type?.id
181
+ ? errors.type
182
+ : { id: errors.type, defaultMessage: errors.type }
183
+ )
184
+ : null
185
+ }
186
+ onChange={(value) => {
187
+ handleChangeSelectApiTokenType({ target: { value } });
188
+ onChange({ target: { name: 'type', value } });
189
+ }}
190
+ placeholder="Select"
191
+ required
192
+ disabled={!canEditInputs}
193
+ >
194
+ <Option value="read-only">
195
+ {formatMessage({
196
+ id: 'Settings.apiTokens.types.read-only',
197
+ defaultMessage: 'Read-only',
198
+ })}
199
+ </Option>
200
+ <Option value="full-access">
201
+ {formatMessage({
202
+ id: 'Settings.apiTokens.types.full-access',
203
+ defaultMessage: 'Full access',
204
+ })}
205
+ </Option>
206
+ <Option value="custom">
207
+ {formatMessage({
208
+ id: 'Settings.apiTokens.types.custom',
209
+ defaultMessage: 'Custom',
210
+ })}
211
+ </Option>
212
+ </Select>
213
+ </GridItem>
214
+ </Grid>
215
+ </Stack>
216
+ </Box>
217
+ );
218
+ };
219
+
220
+ FormApiTokenContainer.propTypes = {
221
+ errors: PropTypes.shape({
222
+ name: PropTypes.string,
223
+ description: PropTypes.string,
224
+ lifespan: PropTypes.string,
225
+ type: PropTypes.string,
226
+ }),
227
+ onChange: PropTypes.func.isRequired,
228
+ canEditInputs: PropTypes.bool.isRequired,
229
+ values: PropTypes.shape({
230
+ name: PropTypes.string,
231
+ description: PropTypes.string,
232
+ lifespan: PropTypes.string,
233
+ type: PropTypes.string,
234
+ }).isRequired,
235
+ isCreating: PropTypes.bool.isRequired,
236
+ apiToken: PropTypes.shape({
237
+ id: PropTypes.string,
238
+ type: PropTypes.string,
239
+ lifespan: PropTypes.number,
240
+ name: PropTypes.string,
241
+ accessKey: PropTypes.string,
242
+ permissions: PropTypes.array,
243
+ description: PropTypes.string,
244
+ createdAt: PropTypes.string,
245
+ }).isRequired,
246
+ onDispatch: PropTypes.func.isRequired,
247
+ setHasChangedPermissions: PropTypes.func.isRequired,
248
+ };
249
+
250
+ FormApiTokenContainer.defaultProps = {
251
+ errors: {},
252
+ };
253
+
254
+ export default FormApiTokenContainer;
@@ -0,0 +1,77 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { ContentLayout } from '@strapi/design-system/Layout';
4
+ import { Stack } from '@strapi/design-system/Stack';
5
+ import HeaderContentBox from '../ContentBox';
6
+ import FormApiTokenContainer from '../FormApiTokenContainer';
7
+ import Permissions from '../Permissions';
8
+
9
+ const FormBody = ({
10
+ apiToken,
11
+ errors,
12
+ onChange,
13
+ canEditInputs,
14
+ isCreating,
15
+ values,
16
+ onDispatch,
17
+ setHasChangedPermissions,
18
+ }) => {
19
+ return (
20
+ <ContentLayout>
21
+ <Stack spacing={6}>
22
+ {Boolean(apiToken?.name) && <HeaderContentBox apiToken={apiToken.accessKey} />}
23
+ <FormApiTokenContainer
24
+ errors={errors}
25
+ onChange={onChange}
26
+ canEditInputs={canEditInputs}
27
+ isCreating={isCreating}
28
+ values={values}
29
+ apiToken={apiToken}
30
+ onDispatch={onDispatch}
31
+ setHasChangedPermissions={setHasChangedPermissions}
32
+ />
33
+ <Permissions
34
+ disabled={
35
+ !canEditInputs || values?.type === 'read-only' || values?.type === 'full-access'
36
+ }
37
+ />
38
+ </Stack>
39
+ </ContentLayout>
40
+ );
41
+ };
42
+
43
+ FormBody.propTypes = {
44
+ errors: PropTypes.shape({
45
+ name: PropTypes.string,
46
+ description: PropTypes.string,
47
+ lifespan: PropTypes.string,
48
+ type: PropTypes.string,
49
+ }),
50
+ apiToken: PropTypes.shape({
51
+ id: PropTypes.string,
52
+ type: PropTypes.string,
53
+ lifespan: PropTypes.number,
54
+ name: PropTypes.string,
55
+ accessKey: PropTypes.string,
56
+ permissions: PropTypes.array,
57
+ description: PropTypes.string,
58
+ createdAt: PropTypes.string,
59
+ }).isRequired,
60
+ onChange: PropTypes.func.isRequired,
61
+ canEditInputs: PropTypes.bool.isRequired,
62
+ isCreating: PropTypes.bool.isRequired,
63
+ values: PropTypes.shape({
64
+ name: PropTypes.string,
65
+ description: PropTypes.string,
66
+ lifespan: PropTypes.string,
67
+ type: PropTypes.string,
68
+ }).isRequired,
69
+ onDispatch: PropTypes.func.isRequired,
70
+ setHasChangedPermissions: PropTypes.func.isRequired,
71
+ };
72
+
73
+ FormBody.defaultProps = {
74
+ errors: {},
75
+ };
76
+
77
+ export default FormBody;
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { Link } from '@strapi/helper-plugin';
4
+ import PropTypes from 'prop-types';
5
+ import ArrowLeft from '@strapi/icons/ArrowLeft';
6
+ import Check from '@strapi/icons/Check';
7
+ import { Button } from '@strapi/design-system/Button';
8
+ import { HeaderLayout } from '@strapi/design-system/Layout';
9
+ import { Stack } from '@strapi/design-system/Stack';
10
+ import Regenerate from '../Regenerate';
11
+
12
+ const FormHead = ({ apiToken, setApiToken, canEditInputs, canRegenerate, isSubmitting }) => {
13
+ const { formatMessage } = useIntl();
14
+ const handleRegenerate = (newKey) => {
15
+ setApiToken({
16
+ ...apiToken,
17
+ accessKey: newKey,
18
+ });
19
+ };
20
+
21
+ return (
22
+ <HeaderLayout
23
+ title={
24
+ apiToken?.name ||
25
+ formatMessage({
26
+ id: 'Settings.apiTokens.createPage.title',
27
+ defaultMessage: 'Create API Token',
28
+ })
29
+ }
30
+ primaryAction={
31
+ canEditInputs ? (
32
+ <Stack horizontal spacing={2}>
33
+ {canRegenerate && apiToken?.id && (
34
+ <Regenerate onRegenerate={handleRegenerate} idToRegenerate={apiToken?.id} />
35
+ )}
36
+ <Button
37
+ disabled={isSubmitting}
38
+ loading={isSubmitting}
39
+ startIcon={<Check />}
40
+ type="submit"
41
+ size="S"
42
+ >
43
+ {formatMessage({
44
+ id: 'global.save',
45
+ defaultMessage: 'Save',
46
+ })}
47
+ </Button>
48
+ </Stack>
49
+ ) : (
50
+ canRegenerate &&
51
+ apiToken?.id && (
52
+ <Regenerate onRegenerate={handleRegenerate} idToRegenerate={apiToken?.id} />
53
+ )
54
+ )
55
+ }
56
+ navigationAction={
57
+ <Link startIcon={<ArrowLeft />} to="/settings/api-tokens">
58
+ {formatMessage({
59
+ id: 'global.back',
60
+ defaultMessage: 'Back',
61
+ })}
62
+ </Link>
63
+ }
64
+ />
65
+ );
66
+ };
67
+
68
+ FormHead.propTypes = {
69
+ apiToken: PropTypes.shape({
70
+ id: PropTypes.string,
71
+ type: PropTypes.string,
72
+ lifespan: PropTypes.number,
73
+ name: PropTypes.string,
74
+ accessKey: PropTypes.string,
75
+ permissions: PropTypes.array,
76
+ description: PropTypes.string,
77
+ createdAt: PropTypes.string,
78
+ }).isRequired,
79
+ canEditInputs: PropTypes.bool.isRequired,
80
+ canRegenerate: PropTypes.bool.isRequired,
81
+ setApiToken: PropTypes.func.isRequired,
82
+ isSubmitting: PropTypes.bool.isRequired,
83
+ };
84
+
85
+ export default FormHead;
@@ -0,0 +1,40 @@
1
+ import React, { memo } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { Typography } from '@strapi/design-system/Typography';
4
+ import { Stack } from '@strapi/design-system/Stack';
5
+ import { Grid, GridItem } from '@strapi/design-system/Grid';
6
+ import ContentTypesSection from '../ContenTypesSection';
7
+ import ActionBoundRoutes from '../ActionBoundRoutes';
8
+ import { useApiTokenPermissionsContext } from '../../../../../../../contexts/ApiTokenPermissions';
9
+
10
+ const Permissions = ({ ...props }) => {
11
+ const {
12
+ value: { data },
13
+ } = useApiTokenPermissionsContext();
14
+ const { formatMessage } = useIntl();
15
+
16
+ return (
17
+ <Grid gap={0} shadow="filterShadow" hasRadius background="neutral0">
18
+ <GridItem col={7} paddingTop={6} paddingBottom={6} paddingLeft={7} paddingRight={7}>
19
+ <Stack spacing={2}>
20
+ <Typography variant="delta" as="h2">
21
+ {formatMessage({
22
+ id: 'Settings.apiTokens.createPage.permissions.title',
23
+ defaultMessage: 'Permissions',
24
+ })}
25
+ </Typography>
26
+ <Typography as="p" textColor="neutral600">
27
+ {formatMessage({
28
+ id: 'Settings.apiTokens.createPage.permissions.description',
29
+ defaultMessage: 'Only actions bound by a route are listed below.',
30
+ })}
31
+ </Typography>
32
+ </Stack>
33
+ {data?.permissions && <ContentTypesSection section={data?.permissions} {...props} />}
34
+ </GridItem>
35
+ <ActionBoundRoutes />
36
+ </Grid>
37
+ );
38
+ };
39
+
40
+ export default memo(Permissions);
@@ -0,0 +1,68 @@
1
+ import React, { useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useIntl } from 'react-intl';
4
+ import { Button } from '@strapi/design-system/Button';
5
+ import Refresh from '@strapi/icons/Refresh';
6
+ import { ConfirmDialog } from '@strapi/helper-plugin';
7
+ import { useRegenerate } from '../../../../../../../hooks';
8
+
9
+ export const Regenerate = ({ onRegenerate, idToRegenerate }) => {
10
+ const { formatMessage } = useIntl();
11
+ const [showConfirmDialog, setShowConfirmDialog] = useState(false);
12
+ const { regenerateData, isLoadingConfirmation } = useRegenerate(idToRegenerate, onRegenerate);
13
+ const handleConfirmRegeneration = async () => {
14
+ regenerateData();
15
+ setShowConfirmDialog(false);
16
+ };
17
+
18
+ return (
19
+ <>
20
+ <Button
21
+ startIcon={<Refresh />}
22
+ type="button"
23
+ size="S"
24
+ variant="tertiary"
25
+ onClick={() => setShowConfirmDialog(true)}
26
+ name="regenerate"
27
+ >
28
+ {formatMessage({
29
+ id: 'Settings.apiTokens.regenerate',
30
+ defaultMessage: 'Regenerate',
31
+ })}
32
+ </Button>
33
+
34
+ <ConfirmDialog
35
+ bodyText={{
36
+ id: 'Settings.apiTokens.popUpWarning.message',
37
+ defaultMessage: 'Are you sure you want to regenerate this token?',
38
+ }}
39
+ iconRightButton={<Refresh />}
40
+ isConfirmButtonLoading={isLoadingConfirmation}
41
+ isOpen={showConfirmDialog}
42
+ onToggleDialog={() => setShowConfirmDialog(false)}
43
+ onConfirm={handleConfirmRegeneration}
44
+ leftButtonText={{
45
+ id: 'Settings.apiTokens.Button.cancel',
46
+ defaultMessage: 'Cancel',
47
+ }}
48
+ rightButtonText={{
49
+ id: 'Settings.apiTokens.Button.regenerate',
50
+ defaultMessage: 'Regenerate',
51
+ }}
52
+ title={{
53
+ id: 'Settings.apiTokens.RegenerateDialog.title',
54
+ defaultMessage: 'Regenerate token',
55
+ }}
56
+ />
57
+ </>
58
+ );
59
+ };
60
+
61
+ Regenerate.defaultProps = { onRegenerate() {} };
62
+
63
+ Regenerate.propTypes = {
64
+ onRegenerate: PropTypes.func,
65
+ idToRegenerate: PropTypes.string.isRequired,
66
+ };
67
+
68
+ export default Regenerate;