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 { Popup } from '../../lib/custom-ui';
|
|
|
|
|
|
|
|
import { useSteps } from '../../hooks';
|
2024-04-22 21:56:07 +02:00
|
|
|
import ListSortStep from '../ListSortStep';
|
2019-08-31 04:07:25 +05:00
|
|
|
import DeleteStep from '../DeleteStep';
|
|
|
|
|
2023-01-24 18:53:13 +01:00
|
|
|
import styles from './ActionsStep.module.scss';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
const StepTypes = {
|
|
|
|
DELETE: 'DELETE',
|
2024-04-22 21:56:07 +02:00
|
|
|
SORT: 'SORT',
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
2024-04-22 21:56:07 +02:00
|
|
|
const ActionsStep = React.memo(({ onNameEdit, onCardAdd, onSort, 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]);
|
|
|
|
|
2024-04-22 21:56:07 +02:00
|
|
|
const handleSortClick = useCallback(() => {
|
|
|
|
openStep(StepTypes.SORT);
|
|
|
|
}, [openStep]);
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
const handleDeleteClick = useCallback(() => {
|
|
|
|
openStep(StepTypes.DELETE);
|
|
|
|
}, [openStep]);
|
|
|
|
|
2024-04-22 21:56:07 +02:00
|
|
|
const handleSortTypeSelect = useCallback(
|
|
|
|
(type) => {
|
|
|
|
onSort({
|
|
|
|
type,
|
|
|
|
});
|
|
|
|
|
|
|
|
onClose();
|
|
|
|
},
|
|
|
|
[onSort, onClose],
|
|
|
|
);
|
|
|
|
|
|
|
|
if (step && step.type) {
|
|
|
|
switch (step.type) {
|
|
|
|
case StepTypes.SORT:
|
|
|
|
return <ListSortStep onTypeSelect={handleSortTypeSelect} onBack={handleBack} />;
|
|
|
|
case StepTypes.DELETE:
|
|
|
|
return (
|
|
|
|
<DeleteStep
|
|
|
|
title="common.deleteList"
|
|
|
|
content="common.areYouSureYouWantToDeleteThisList"
|
|
|
|
buttonContent="action.deleteList"
|
|
|
|
onConfirm={onDelete}
|
|
|
|
onBack={handleBack}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
}
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
2024-04-22 21:56:07 +02:00
|
|
|
<Menu.Item className={styles.menuItem} onClick={handleSortClick}>
|
|
|
|
{t('action.sortList', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Menu.Item>
|
2021-06-24 01:05:22 +05:00
|
|
|
<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,
|
2021-06-24 01:05:22 +05:00
|
|
|
onDelete: PropTypes.func.isRequired,
|
2024-04-22 21:56:07 +02:00
|
|
|
onSort: PropTypes.func.isRequired,
|
2019-08-31 04:07:25 +05:00
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2023-01-24 18:53:13 +01:00
|
|
|
export default ActionsStep;
|