import React, { useCallback, useRef } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import { Button, Grid, Icon, Modal } from 'semantic-ui-react'; import { Markdown } from '../../lib/custom-ui'; import NameField from './NameField'; import DescriptionEdit from './DescriptionEdit'; import Tasks from './Tasks'; import Attachments from './Attachments'; import AttachmentAddZone from './AttachmentAddZone'; import AttachmentAddPopup from './AttachmentAddPopup'; import Actions from './Actions'; import User from '../User'; import Label from '../Label'; import DueDate from '../DueDate'; import Timer from '../Timer'; import BoardMembershipsPopup from '../BoardMembershipsPopup'; import LabelsPopup from '../LabelsPopup'; import DueDateEditPopup from '../DueDateEditPopup'; import TimerEditPopup from '../TimerEditPopup'; import CardMovePopup from '../CardMovePopup'; import DeletePopup from '../DeletePopup'; import styles from './CardModal.module.scss'; const CardModal = React.memo( ({ name, description, dueDate, timer, isSubscribed, isActionsFetching, isAllActionsFetched, listId, boardId, projectId, users, labels, tasks, attachments, actions, allProjectsToLists, allBoardMemberships, allLabels, canEdit, canEditAllCommentActions, onUpdate, onMove, onTransfer, onDelete, onUserAdd, onUserRemove, onBoardFetch, onLabelAdd, onLabelRemove, onLabelCreate, onLabelUpdate, onLabelDelete, onTaskCreate, onTaskUpdate, onTaskMove, onTaskDelete, onAttachmentCreate, onAttachmentUpdate, onAttachmentDelete, onActionsFetch, onCommentActionCreate, onCommentActionUpdate, onCommentActionDelete, onClose, }) => { const [t] = useTranslation(); const isGalleryOpened = useRef(false); const handleNameUpdate = useCallback( (newName) => { onUpdate({ name: newName, }); }, [onUpdate], ); const handleDescriptionUpdate = useCallback( (newDescription) => { onUpdate({ description: newDescription, }); }, [onUpdate], ); const handleDueDateUpdate = useCallback( (newDueDate) => { onUpdate({ dueDate: newDueDate, }); }, [onUpdate], ); const handleTimerUpdate = useCallback( (newTimer) => { onUpdate({ timer: newTimer, }); }, [onUpdate], ); const handleCoverUpdate = useCallback( (newCoverAttachmentId) => { onUpdate({ coverAttachmentId: newCoverAttachmentId, }); }, [onUpdate], ); const handleToggleSubscriptionClick = useCallback(() => { onUpdate({ isSubscribed: !isSubscribed, }); }, [isSubscribed, onUpdate]); const handleGalleryOpen = useCallback(() => { isGalleryOpened.current = true; }, []); const handleGalleryClose = useCallback(() => { isGalleryOpened.current = false; }, []); const handleClose = useCallback(() => { if (isGalleryOpened.current) { return; } onClose(); }, [onClose]); const userIds = users.map((user) => user.id); const labelIds = labels.map((label) => label.id); const contentNode = (
{canEdit ? ( ) : (
{name}
)}
{(users.length > 0 || labels.length > 0 || dueDate || timer) && (
{users.length > 0 && (
{t('common.members', { context: 'title', })}
{users.map((user) => ( {canEdit ? ( ) : ( )} ))} {canEdit && ( )}
)} {labels.length > 0 && (
{t('common.labels', { context: 'title', })}
{labels.map((label) => ( {canEdit ? ( ) : ( ))} {canEdit && ( )}
)} {dueDate && (
{t('common.dueDate', { context: 'title', })}
{canEdit ? ( ) : ( )}
)} {timer && (
{t('common.timer', { context: 'title', })}
{canEdit ? ( ) : ( )}
)}
)} {(description || canEdit) && (
{t('common.description')}
{canEdit ? ( {description ? ( ) : ( )} ) : (
{description}
)}
)} {(tasks.length > 0 || canEdit) && (
{t('common.tasks')}
)} {attachments.length > 0 && (
{t('common.attachments')}
)}
{canEdit && (
{t('action.addToCard')}
{t('common.actions')}
)}
); return ( {canEdit ? ( {contentNode} ) : ( contentNode )} ); }, ); CardModal.propTypes = { name: PropTypes.string.isRequired, description: PropTypes.string, dueDate: PropTypes.instanceOf(Date), timer: PropTypes.object, // eslint-disable-line react/forbid-prop-types isSubscribed: PropTypes.bool.isRequired, isActionsFetching: PropTypes.bool.isRequired, isAllActionsFetched: PropTypes.bool.isRequired, listId: PropTypes.string.isRequired, boardId: PropTypes.string.isRequired, projectId: PropTypes.string.isRequired, /* eslint-disable react/forbid-prop-types */ users: PropTypes.array.isRequired, labels: PropTypes.array.isRequired, tasks: PropTypes.array.isRequired, attachments: PropTypes.array.isRequired, actions: PropTypes.array.isRequired, allProjectsToLists: PropTypes.array.isRequired, allBoardMemberships: PropTypes.array.isRequired, allLabels: PropTypes.array.isRequired, /* eslint-enable react/forbid-prop-types */ canEdit: PropTypes.bool.isRequired, canEditAllCommentActions: PropTypes.bool.isRequired, onUpdate: PropTypes.func.isRequired, onMove: PropTypes.func.isRequired, onTransfer: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, onUserAdd: PropTypes.func.isRequired, onUserRemove: PropTypes.func.isRequired, onBoardFetch: PropTypes.func.isRequired, onLabelAdd: PropTypes.func.isRequired, onLabelRemove: PropTypes.func.isRequired, onLabelCreate: PropTypes.func.isRequired, onLabelUpdate: PropTypes.func.isRequired, onLabelDelete: PropTypes.func.isRequired, onTaskCreate: PropTypes.func.isRequired, onTaskUpdate: PropTypes.func.isRequired, onTaskMove: PropTypes.func.isRequired, onTaskDelete: PropTypes.func.isRequired, onAttachmentCreate: PropTypes.func.isRequired, onAttachmentUpdate: PropTypes.func.isRequired, onAttachmentDelete: PropTypes.func.isRequired, onActionsFetch: PropTypes.func.isRequired, onCommentActionCreate: PropTypes.func.isRequired, onCommentActionUpdate: PropTypes.func.isRequired, onCommentActionDelete: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, }; CardModal.defaultProps = { description: undefined, dueDate: undefined, timer: undefined, }; export default CardModal;