Fix feedback from create PR

Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
soupette 2021-09-03 12:41:18 +02:00
parent 46c1580038
commit a4c0bfd3fd
5 changed files with 32 additions and 16 deletions

View File

@ -29,7 +29,7 @@ import stepper from './utils/stepper';
const ModalForm = ({ queryName, onToggle }) => { const ModalForm = ({ queryName, onToggle }) => {
const [currentStep, setStep] = useState('create'); const [currentStep, setStep] = useState('create');
const [isSubmitting, setIsSubmiting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
const [registrationToken, setRegistrationToken] = useState(null); const [registrationToken, setRegistrationToken] = useState(null);
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
@ -40,10 +40,11 @@ const ModalForm = ({ queryName, onToggle }) => {
setRegistrationToken(data.data.registrationToken); setRegistrationToken(data.data.registrationToken);
await queryClient.invalidateQueries(queryName); await queryClient.invalidateQueries(queryName);
goNext(); goNext();
setIsSubmiting(false); setIsSubmitting(false);
}, },
onError: err => { onError: err => {
console.error(err.response); console.error(err.response);
setIsSubmitting(false);
toggleNotification({ toggleNotification({
type: 'warning', type: 'warning',
@ -62,7 +63,7 @@ const ModalForm = ({ queryName, onToggle }) => {
const handleSubmit = async body => { const handleSubmit = async body => {
lockApp(); lockApp();
setIsSubmiting(true); setIsSubmitting(true);
postMutation.mutateAsync(body); postMutation.mutateAsync(body);
}; };

View File

@ -1,13 +1,15 @@
import React from 'react'; import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Box } from '@strapi/parts/Box'; import { Box } from '@strapi/parts/Box';
import { Row } from '@strapi/parts/Row'; import { Row } from '@strapi/parts/Row';
import { Stack } from '@strapi/parts/Stack'; import { Stack } from '@strapi/parts/Stack';
import { Text } from '@strapi/parts/Text'; import { Text } from '@strapi/parts/Text';
import { Tooltip } from '@strapi/parts/Tooltip';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/helper-plugin';
import { Duplicate } from '@strapi/icons'; import Duplicate from '@strapi/icons/Duplicate';
import styled from 'styled-components'; import styled from 'styled-components';
import { CopyToClipboard } from 'react-copy-to-clipboard'; import { CopyToClipboard } from 'react-copy-to-clipboard';
import { useIntl } from 'react-intl';
// FIXME replace with parts when ready // FIXME replace with parts when ready
const Envelope = () => ( const Envelope = () => (
@ -26,10 +28,9 @@ const Envelope = () => (
</svg> </svg>
); );
const Wrapper = styled.div` const Wrapper = styled.button`
padding-left: ${({ theme }) => theme.spaces[2]}; padding-left: ${({ theme }) => theme.spaces[2]};
font-size: ${({ theme }) => theme.spaces[3]}; font-size: ${({ theme }) => theme.spaces[3]};
cursor: pointer;
svg { svg {
> g, > g,
path { path {
@ -40,11 +41,24 @@ const Wrapper = styled.div`
const MagicLinkWrapper = ({ children, target }) => { const MagicLinkWrapper = ({ children, target }) => {
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const copyButtonRef = useRef();
const { formatMessage } = useIntl();
useEffect(() => {
if (copyButtonRef.current) {
copyButtonRef.current.focus();
}
}, []);
const handleCopy = () => { const handleCopy = () => {
toggleNotification({ type: 'info', message: { id: 'notification.link-copied' } }); toggleNotification({ type: 'info', message: { id: 'notification.link-copied' } });
}; };
const copyLabel = formatMessage({
id: 'app.component.CopyToClipboard.label',
defaultMessage: 'Copy to clipboard',
});
return ( return (
<Box padding={6} background="neutral0" shadow="tableShadow" hasRadius> <Box padding={6} background="neutral0" shadow="tableShadow" hasRadius>
<Row> <Row>
@ -57,14 +71,16 @@ const MagicLinkWrapper = ({ children, target }) => {
<Text small textColor="neutral800" highlighted> <Text small textColor="neutral800" highlighted>
{target} {target}
</Text> </Text>
<CopyToClipboard onCopy={handleCopy} text={target}> <Tooltip description={copyLabel}>
<Wrapper small> <CopyToClipboard onCopy={handleCopy} text={target}>
<Duplicate /> <Wrapper small type="button" ref={copyButtonRef}>
</Wrapper> <Duplicate />
</CopyToClipboard> </Wrapper>
</CopyToClipboard>
</Tooltip>
</Stack> </Stack>
<Text small textColor="neutral500" highlighted> <Text small textColor="neutral600" highlighted>
{children} {children}
</Text> </Text>
</Stack> </Stack>

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { Select, Option } from '@strapi/parts'; import { Select, Option } from '@strapi/parts/Select';
import { useQuery } from 'react-query'; import { useQuery } from 'react-query';
import styled, { keyframes } from 'styled-components'; import styled, { keyframes } from 'styled-components';
import LoadingIcon from '@strapi/icons/LoadingIcon'; import LoadingIcon from '@strapi/icons/LoadingIcon';

View File

@ -211,6 +211,7 @@
"app.components.Button.confirm": "Confirm", "app.components.Button.confirm": "Confirm",
"app.components.Button.reset": "Reset", "app.components.Button.reset": "Reset",
"app.components.Button.save": "Save", "app.components.Button.save": "Save",
"app.component.CopyToClipboard.label": "Copy to clipboard",
"app.components.ComingSoonPage.comingSoon": "Coming soon", "app.components.ComingSoonPage.comingSoon": "Coming soon",
"app.components.ConfirmDialog.title": "Confirmation", "app.components.ConfirmDialog.title": "Confirmation",
"app.components.DownloadInfo.download": "Download in progress...", "app.components.DownloadInfo.download": "Download in progress...",

View File

@ -37,7 +37,6 @@ const Input = ({
if (type === 'bool') { if (type === 'bool') {
return ( return (
<ToggleInput <ToggleInput
aria-label={name}
checked={value} checked={value}
disabled={disabled} disabled={disabled}
hint={hint} hint={hint}
@ -69,7 +68,6 @@ const Input = ({
return ( return (
<TextInput <TextInput
aria-label={name}
disabled={disabled} disabled={disabled}
error={errorMessage} error={errorMessage}
label={label} label={label}