2019-08-31 04:07:25 +05:00
|
|
|
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';
|
2019-10-05 06:12:36 +05:00
|
|
|
import DueDate from '../DueDate';
|
2019-08-31 04:07:25 +05:00
|
|
|
import Timer from '../Timer';
|
|
|
|
|
|
|
|
import styles from './Card.module.css';
|
|
|
|
|
|
|
|
const Card = React.memo(
|
|
|
|
({
|
|
|
|
id,
|
|
|
|
index,
|
|
|
|
name,
|
2019-10-05 06:12:36 +05:00
|
|
|
dueDate,
|
2019-08-31 04:07:25 +05:00
|
|
|
timer,
|
2020-04-23 03:02:53 +05:00
|
|
|
coverUrl,
|
2019-08-31 04:07:25 +05:00
|
|
|
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(
|
2020-03-25 00:15:47 +05:00
|
|
|
(newName) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
onUpdate({
|
|
|
|
name: newName,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[onUpdate],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleNameEdit = useCallback(() => {
|
|
|
|
editName.current.open();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const contentNode = (
|
|
|
|
<>
|
2020-04-23 03:02:53 +05:00
|
|
|
{coverUrl && <img src={coverUrl} alt="" className={styles.cover} />}
|
|
|
|
<div className={styles.details}>
|
|
|
|
{labels.length > 0 && (
|
|
|
|
<span className={styles.labels}>
|
|
|
|
{labels.map((label) => (
|
|
|
|
<span
|
|
|
|
key={label.id}
|
|
|
|
className={classNames(styles.attachment, styles.attachmentLeft)}
|
|
|
|
>
|
|
|
|
<Label name={label.name} color={label.color} size="tiny" />
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
<div className={styles.name}>{name}</div>
|
|
|
|
{tasks.length > 0 && <Tasks items={tasks} />}
|
|
|
|
{(dueDate || timer || notificationsTotal > 0) && (
|
|
|
|
<span className={styles.attachments}>
|
|
|
|
{notificationsTotal > 0 && (
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
styles.attachment,
|
|
|
|
styles.attachmentLeft,
|
|
|
|
styles.notification,
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{notificationsTotal}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{dueDate && (
|
|
|
|
<span className={classNames(styles.attachment, styles.attachmentLeft)}>
|
|
|
|
<DueDate value={dueDate} size="tiny" />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{timer && (
|
|
|
|
<span className={classNames(styles.attachment, styles.attachmentLeft)}>
|
|
|
|
<Timer startedAt={timer.startedAt} total={timer.total} size="tiny" />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{users.length > 0 && (
|
|
|
|
<span className={classNames(styles.attachments, styles.attachmentsRight)}>
|
|
|
|
{users.map((user) => (
|
|
|
|
<span
|
|
|
|
key={user.id}
|
|
|
|
className={classNames(styles.attachment, styles.attachmentRight)}
|
|
|
|
>
|
2020-04-30 05:27:46 +05:00
|
|
|
<User name={user.name} avatarUrl={user.avatarUrl} size="small" />
|
2020-04-23 03:02:53 +05:00
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2019-08-31 04:07:25 +05:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Draggable draggableId={`card:${id}`} index={index} isDragDisabled={!isPersisted}>
|
|
|
|
{({ innerRef, draggableProps, dragHandleProps }) => (
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
<div {...draggableProps} {...dragHandleProps} ref={innerRef} className={styles.wrapper}>
|
|
|
|
<EditName ref={editName} defaultValue={name} onUpdate={handleNameUpdate}>
|
|
|
|
<div className={styles.card}>
|
|
|
|
{isPersisted ? (
|
|
|
|
<>
|
|
|
|
<Link
|
2020-04-23 03:02:53 +05:00
|
|
|
to={Paths.CARDS.replace(':id', id)}
|
2019-08-31 04:07:25 +05:00
|
|
|
className={styles.content}
|
|
|
|
onClick={handleClick}
|
|
|
|
>
|
|
|
|
{contentNode}
|
|
|
|
</Link>
|
|
|
|
<ActionsPopup
|
|
|
|
card={{
|
|
|
|
id,
|
|
|
|
name,
|
2019-10-05 06:12:36 +05:00
|
|
|
dueDate,
|
2019-08-31 04:07:25 +05:00
|
|
|
timer,
|
|
|
|
isPersisted,
|
|
|
|
}}
|
|
|
|
projectMemberships={allProjectMemberships}
|
2020-03-25 00:15:47 +05:00
|
|
|
currentUserIds={users.map((user) => user.id)}
|
2019-08-31 04:07:25 +05:00
|
|
|
labels={allLabels}
|
2020-03-25 00:15:47 +05:00
|
|
|
currentLabelIds={labels.map((label) => label.id)}
|
2019-08-31 04:07:25 +05:00
|
|
|
onNameEdit={handleNameEdit}
|
|
|
|
onUpdate={onUpdate}
|
|
|
|
onDelete={onDelete}
|
|
|
|
onUserAdd={onUserAdd}
|
|
|
|
onUserRemove={onUserRemove}
|
|
|
|
onLabelAdd={onLabelAdd}
|
|
|
|
onLabelRemove={onLabelRemove}
|
|
|
|
onLabelCreate={onLabelCreate}
|
|
|
|
onLabelUpdate={onLabelUpdate}
|
|
|
|
onLabelDelete={onLabelDelete}
|
|
|
|
>
|
|
|
|
<Button className={classNames(styles.actionsButton, styles.target)}>
|
|
|
|
<Icon fitted name="pencil" size="small" />
|
|
|
|
</Button>
|
|
|
|
</ActionsPopup>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<span className={styles.content}>{contentNode}</span>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</EditName>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Draggable>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Card.propTypes = {
|
2019-10-10 02:51:54 +05:00
|
|
|
id: PropTypes.string.isRequired,
|
2019-08-31 04:07:25 +05:00
|
|
|
index: PropTypes.number.isRequired,
|
|
|
|
name: PropTypes.string.isRequired,
|
2019-10-05 06:12:36 +05:00
|
|
|
dueDate: PropTypes.instanceOf(Date),
|
2019-08-31 04:07:25 +05:00
|
|
|
timer: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
2020-04-23 03:02:53 +05:00
|
|
|
coverUrl: PropTypes.string,
|
2019-08-31 04:07:25 +05:00
|
|
|
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 = {
|
2019-10-05 06:12:36 +05:00
|
|
|
dueDate: undefined,
|
2019-08-31 04:07:25 +05:00
|
|
|
timer: undefined,
|
2020-04-23 03:02:53 +05:00
|
|
|
coverUrl: undefined,
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Card;
|