2019-08-31 04:07:25 +05:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { Menu } from 'semantic-ui-react';
|
|
|
|
import { withPopup } from '../../lib/popup';
|
|
|
|
import { Popup } from '../../lib/custom-ui';
|
|
|
|
|
|
|
|
import { useSteps } from '../../hooks';
|
|
|
|
import DeleteStep from '../DeleteStep';
|
|
|
|
|
2020-05-29 19:31:19 +05:00
|
|
|
import styles from './ActionsPopup.module.scss';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const StepTypes = {
|
|
|
|
DELETE: 'DELETE',
|
|
|
|
};
|
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onDelete, onClose }) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const [t] = useTranslation();
|
|
|
|
const [step, openStep, handleBack] = useSteps();
|
|
|
|
|
2020-05-16 04:09:46 +05:00
|
|
|
const handleEditNameClick = useCallback(() => {
|
2019-08-31 04:07:25 +05:00
|
|
|
onNameEdit();
|
|
|
|
onClose();
|
|
|
|
}, [onNameEdit, onClose]);
|
|
|
|
|
2020-05-16 04:09:46 +05:00
|
|
|
const handleAddCardClick = useCallback(() => {
|
2019-08-31 04:07:25 +05:00
|
|
|
onCardAdd();
|
|
|
|
onClose();
|
|
|
|
}, [onCardAdd, onClose]);
|
|
|
|
|
|
|
|
const handleDeleteClick = useCallback(() => {
|
|
|
|
openStep(StepTypes.DELETE);
|
|
|
|
}, [openStep]);
|
|
|
|
|
|
|
|
if (step && step.type === StepTypes.DELETE) {
|
|
|
|
return (
|
|
|
|
<DeleteStep
|
|
|
|
title={t('common.deleteList', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
content={t('common.areYouSureYouWantToDeleteThisList')}
|
|
|
|
buttonContent={t('action.deleteList')}
|
|
|
|
onConfirm={onDelete}
|
|
|
|
onBack={handleBack}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Popup.Header>
|
|
|
|
{t('common.listActions', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Popup.Header>
|
|
|
|
<Popup.Content>
|
|
|
|
<Menu secondary vertical className={styles.menu}>
|
2020-05-16 04:09:46 +05:00
|
|
|
<Menu.Item className={styles.menuItem} onClick={handleEditNameClick}>
|
2019-08-31 04:07:25 +05:00
|
|
|
{t('action.editTitle', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Menu.Item>
|
2020-05-16 04:09:46 +05:00
|
|
|
<Menu.Item className={styles.menuItem} onClick={handleAddCardClick}>
|
2019-08-31 04:07:25 +05:00
|
|
|
{t('action.addCard', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Menu.Item>
|
2020-04-30 05:27:46 +05:00
|
|
|
{onDelete && (
|
|
|
|
<Menu.Item className={styles.menuItem} onClick={handleDeleteClick}>
|
|
|
|
{t('action.deleteList', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Menu.Item>
|
|
|
|
)}
|
2019-08-31 04:07:25 +05:00
|
|
|
</Menu>
|
|
|
|
</Popup.Content>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
ActionsStep.propTypes = {
|
|
|
|
onNameEdit: PropTypes.func.isRequired,
|
|
|
|
onCardAdd: PropTypes.func.isRequired,
|
2020-04-30 05:27:46 +05:00
|
|
|
onDelete: PropTypes.func,
|
2019-08-31 04:07:25 +05:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2020-04-30 05:27:46 +05:00
|
|
|
ActionsStep.defaultProps = {
|
|
|
|
onDelete: undefined,
|
|
|
|
};
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
export default withPopup(ActionsStep);
|