import React, { useCallback, useRef } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Button, Icon } from 'semantic-ui-react'; import { Link } from 'react-router-dom'; import { Draggable } from 'react-beautiful-dnd'; import Paths from '../../constants/Paths'; import Tasks from './Tasks'; import EditName from './EditName'; import ActionsPopup from './ActionsPopup'; import User from '../User'; import Label from '../Label'; import DueDate from '../DueDate'; import Timer from '../Timer'; import styles from './Card.module.css'; const Card = React.memo( ({ id, index, name, dueDate, timer, isPersisted, notificationsTotal, users, labels, tasks, allProjectMemberships, allLabels, onUpdate, onDelete, onUserAdd, onUserRemove, onLabelAdd, onLabelRemove, onLabelCreate, onLabelUpdate, onLabelDelete, }) => { const editName = useRef(null); const handleClick = useCallback(() => { if (document.activeElement) { document.activeElement.blur(); } }, []); const handleNameUpdate = useCallback( newName => { onUpdate({ name: newName, }); }, [onUpdate], ); const handleNameEdit = useCallback(() => { editName.current.open(); }, []); const contentNode = ( <> {labels.length > 0 && ( {labels.map(label => ( ))} )}
{name}
{tasks.length > 0 && } {(dueDate || timer || notificationsTotal > 0) && ( {notificationsTotal > 0 && ( {notificationsTotal} )} {dueDate && ( )} {timer && ( )} )} {users.length > 0 && ( {users.map(user => ( ))} )} ); return ( {({ innerRef, draggableProps, dragHandleProps }) => ( // eslint-disable-next-line react/jsx-props-no-spreading
{isPersisted ? ( <> {contentNode} user.id)} labels={allLabels} currentLabelIds={labels.map(label => label.id)} onNameEdit={handleNameEdit} onUpdate={onUpdate} onDelete={onDelete} onUserAdd={onUserAdd} onUserRemove={onUserRemove} onLabelAdd={onLabelAdd} onLabelRemove={onLabelRemove} onLabelCreate={onLabelCreate} onLabelUpdate={onLabelUpdate} onLabelDelete={onLabelDelete} > ) : ( {contentNode} )}
)}
); }, ); Card.propTypes = { id: PropTypes.string.isRequired, index: PropTypes.number.isRequired, name: PropTypes.string.isRequired, dueDate: PropTypes.instanceOf(Date), timer: PropTypes.object, // eslint-disable-line react/forbid-prop-types isPersisted: PropTypes.bool.isRequired, notificationsTotal: PropTypes.number.isRequired, /* eslint-disable react/forbid-prop-types */ users: PropTypes.array.isRequired, labels: PropTypes.array.isRequired, tasks: PropTypes.array.isRequired, allProjectMemberships: PropTypes.array.isRequired, allLabels: PropTypes.array.isRequired, /* eslint-enable react/forbid-prop-types */ onUpdate: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, onUserAdd: PropTypes.func.isRequired, onUserRemove: PropTypes.func.isRequired, onLabelAdd: PropTypes.func.isRequired, onLabelRemove: PropTypes.func.isRequired, onLabelCreate: PropTypes.func.isRequired, onLabelUpdate: PropTypes.func.isRequired, onLabelDelete: PropTypes.func.isRequired, }; Card.defaultProps = { dueDate: undefined, timer: undefined, }; export default Card;