diff --git a/client/src/components/CardCopyPopup.jsx b/client/src/components/CardCopyPopup.jsx new file mode 100644 index 0000000..548e231 --- /dev/null +++ b/client/src/components/CardCopyPopup.jsx @@ -0,0 +1,5 @@ +import { withPopup } from '../lib/popup'; + +import CardCopyStep from './CardCopyStep'; + +export default withPopup(CardCopyStep); diff --git a/client/src/components/CardCopyStep/CardCopyStep.jsx b/client/src/components/CardCopyStep/CardCopyStep.jsx new file mode 100644 index 0000000..e115812 --- /dev/null +++ b/client/src/components/CardCopyStep/CardCopyStep.jsx @@ -0,0 +1,167 @@ +import React, { useMemo, useCallback } from 'react'; +import PropTypes from 'prop-types'; +import { useTranslation } from 'react-i18next'; +import { Button, Dropdown, Form, TextArea, Checkbox } from 'semantic-ui-react'; +import { Popup } from '../../lib/custom-ui'; + +import { useForm } from '../../hooks'; + +import styles from './CardCopyStep.module.scss'; + +const CardCopyStep = React.memo( + ({ projectsToLists, defaultPath, onMove, onTransfer, onBoardFetch, onBack, onClose }) => { + const [t] = useTranslation(); + + const [path, handleFieldChange] = useForm(() => ({ + projectId: null, + boardId: null, + listId: null, + name: null, + description: null, + tasks: [], + attachments: [], + labels: [], + users: [], + ...defaultPath, + })); + + const selectedProject = useMemo( + () => projectsToLists.find((project) => project.id === path.projectId) || null, + [projectsToLists, path.projectId], + ); + + const selectedBoard = useMemo( + () => + (selectedProject && selectedProject.boards.find((board) => board.id === path.boardId)) || + null, + [selectedProject, path.boardId], + ); + + const selectedList = useMemo( + () => (selectedBoard && selectedBoard.lists.find((list) => list.id === path.listId)) || null, + [selectedBoard, path.listId], + ); + + const handleBoardIdChange = useCallback( + (event, data) => { + if (selectedProject.boards.find((board) => board.id === data.value).isFetching === null) { + onBoardFetch(data.value); + } + + handleFieldChange(event, data); + }, + [onBoardFetch, handleFieldChange, selectedProject], + ); + + const handleSubmit = useCallback(() => { + if (selectedBoard.id !== defaultPath.boardId) { + onTransfer(selectedBoard.id, selectedList.id); + } else if (selectedList.id !== defaultPath.listId) { + onMove(selectedList.id); + } + + onClose(); + }, [defaultPath, onMove, onTransfer, onClose, selectedBoard, selectedList]); + + return ( + <> + + {t('Copy Card', { + context: 'title', + })} + + +
+
{t('common.project')}
+ ({ + text: project.name, + value: project.id, + }))} + value={selectedProject && selectedProject.id} + placeholder={ + projectsToLists.length === 0 ? t('common.noProjects') : t('common.selectProject') + } + disabled={projectsToLists.length === 0} + className={styles.field} + onChange={handleFieldChange} + /> + {selectedProject && ( + <> +
{t('common.board')}
+ ({ + text: board.name, + value: board.id, + }))} + value={selectedBoard && selectedBoard.id} + placeholder={ + selectedProject.boards.length === 0 + ? t('common.noBoards') + : t('common.selectBoard') + } + disabled={selectedProject.boards.length === 0} + className={styles.field} + onChange={handleBoardIdChange} + /> + + )} + {selectedBoard && ( + <> +
{t('common.list')}
+ ({ + text: list.name, + value: list.id, + }))} + value={selectedList && selectedList.id} + placeholder={ + selectedBoard.isFetching === false && selectedBoard.lists.length === 0 + ? t('common.noLists') + : t('common.selectList') + } + loading={selectedBoard.isFetching !== false} + disabled={selectedBoard.isFetching !== false || selectedBoard.lists.length === 0} + className={styles.field} + onChange={handleFieldChange} + /> + + )} + + + +