@strapi/plugin-documentation 4.12.0-beta.3 → 4.12.0-beta.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.
@@ -1,6 +1,5 @@
1
1
  import React, { useState } from 'react';
2
2
 
3
- // Strapi Parts
4
3
  import {
5
4
  Box,
6
5
  Button,
@@ -13,32 +12,42 @@ import {
13
12
  TextInput,
14
13
  ToggleInput,
15
14
  Typography,
15
+ FieldAction,
16
16
  } from '@strapi/design-system';
17
17
  import {
18
- CheckPermissions,
19
18
  Form,
20
19
  LoadingIndicatorPage,
21
20
  useFocusWhenNavigate,
21
+ translatedErrors,
22
+ useRBAC,
22
23
  } from '@strapi/helper-plugin';
23
24
  // Strapi Icons
24
25
  import { Check, Eye as Show, EyeStriked as Hide } from '@strapi/icons';
25
26
  import { Formik } from 'formik';
26
27
  import { useIntl } from 'react-intl';
28
+ import styled from 'styled-components';
29
+ import * as yup from 'yup';
27
30
 
28
- import FieldActionWrapper from '../../components/FieldActionWrapper';
29
31
  import { PERMISSIONS } from '../../constants';
32
+ import { useDocumentation } from '../../hooks/useDocumentation';
30
33
  import { getTrad } from '../../utils';
31
- import schema from '../utils/schema';
32
- import useReactQuery from '../utils/useReactQuery';
34
+
35
+ const schema = yup.object().shape({
36
+ restrictedAccess: yup.boolean(),
37
+ password: yup.string().when('restrictedAccess', (value, initSchema) => {
38
+ return value ? initSchema.required(translatedErrors.required) : initSchema;
39
+ }),
40
+ });
33
41
 
34
42
  const SettingsPage = () => {
35
43
  useFocusWhenNavigate();
36
44
  const { formatMessage } = useIntl();
37
- const { submitMutation, data, isLoading } = useReactQuery();
45
+ const { submit, data, isLoading } = useDocumentation();
38
46
  const [passwordShown, setPasswordShown] = useState(false);
47
+ const { allowedActions } = useRBAC(PERMISSIONS);
39
48
 
40
49
  const handleUpdateSettingsSubmit = (body) => {
41
- submitMutation.mutate({
50
+ submit.mutate({
42
51
  prefix: data?.prefix,
43
52
  body,
44
53
  });
@@ -78,14 +87,16 @@ const SettingsPage = () => {
78
87
  defaultMessage: 'Configure the documentation plugin',
79
88
  })}
80
89
  primaryAction={
81
- <CheckPermissions permissions={PERMISSIONS.update}>
82
- <Button type="submit" startIcon={<Check />} disabled={!dirty}>
83
- {formatMessage({
84
- id: getTrad('pages.SettingsPage.Button.save'),
85
- defaultMessage: 'Save',
86
- })}
87
- </Button>
88
- </CheckPermissions>
90
+ <Button
91
+ type="submit"
92
+ startIcon={<Check />}
93
+ disabled={!dirty && allowedActions.canUpdate}
94
+ >
95
+ {formatMessage({
96
+ id: getTrad('pages.SettingsPage.Button.save'),
97
+ defaultMessage: 'Save',
98
+ })}
99
+ </Button>
89
100
  }
90
101
  />
91
102
  <ContentLayout>
@@ -187,4 +198,14 @@ const SettingsPage = () => {
187
198
  );
188
199
  };
189
200
 
201
+ const FieldActionWrapper = styled(FieldAction)`
202
+ svg {
203
+ height: 1rem;
204
+ width: 1rem;
205
+ path {
206
+ fill: ${({ theme }) => theme.colors.neutral600};
207
+ }
208
+ }
209
+ `;
210
+
190
211
  export default SettingsPage;