2020-03-25 13:05:23 +01:00
|
|
|
import React, { useState, useRef } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
import { useClickAwayListener } from '@buffetjs/hooks';
|
|
|
|
import { useGlobalContext } from 'strapi-helper-plugin';
|
|
|
|
import DoubleFile from '../../icons/DoubleFile';
|
|
|
|
import File from '../../icons/File';
|
|
|
|
import DropdownSection from '../DropdownSection';
|
|
|
|
import Padded from '../Padded';
|
|
|
|
import Button from './Button';
|
|
|
|
import Spacer from './Spacer';
|
|
|
|
import StyledCardControl from './StyledCardControl';
|
|
|
|
import { getTrad } from '../../utils';
|
|
|
|
|
2020-03-31 16:30:43 +02:00
|
|
|
const CheckControl = ({ title, onSubmitEdit }) => {
|
2020-03-25 13:05:23 +01:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
const { formatMessage } = useGlobalContext();
|
|
|
|
const dropdownRef = useRef();
|
|
|
|
|
|
|
|
useClickAwayListener(dropdownRef, () => setIsOpen(false));
|
|
|
|
|
|
|
|
const handleClick = e => {
|
|
|
|
e.persist();
|
|
|
|
setIsOpen(false);
|
|
|
|
onSubmitEdit(e);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleClickDuplicate = e => {
|
|
|
|
e.persist();
|
|
|
|
setIsOpen(false);
|
|
|
|
onSubmitEdit(e, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleToggle = () => {
|
|
|
|
setIsOpen(v => !v);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-03-31 16:30:43 +02:00
|
|
|
<StyledCardControl
|
|
|
|
title={formatMessage({ id: getTrad(`control-card.${title}`) })}
|
|
|
|
color="#ffffff"
|
|
|
|
ref={dropdownRef}
|
|
|
|
onClick={handleToggle}
|
|
|
|
>
|
2020-03-25 13:05:23 +01:00
|
|
|
<FontAwesomeIcon icon="check" />
|
|
|
|
<DropdownSection isOpen={isOpen}>
|
|
|
|
<Padded left right bottom top size="15px">
|
|
|
|
<Button onClick={handleClick}>
|
|
|
|
<File />
|
|
|
|
{formatMessage({ id: getTrad('checkControl.crop-original') })}
|
|
|
|
</Button>
|
|
|
|
<Spacer />
|
|
|
|
<Button onClick={handleClickDuplicate}>
|
|
|
|
<DoubleFile />
|
|
|
|
{formatMessage({ id: getTrad('checkControl.crop-duplicate') })}
|
|
|
|
</Button>
|
|
|
|
</Padded>
|
|
|
|
</DropdownSection>
|
|
|
|
</StyledCardControl>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
CheckControl.defaultProps = {
|
|
|
|
onSubmitEdit: () => {},
|
2020-03-31 16:30:43 +02:00
|
|
|
title: null,
|
2020-03-25 13:05:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckControl.propTypes = {
|
|
|
|
onSubmitEdit: PropTypes.func,
|
2020-03-31 16:30:43 +02:00
|
|
|
title: PropTypes.string,
|
2020-03-25 13:05:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default CheckControl;
|