1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/client/src/components/CardModal/Actions/ItemComment.jsx

87 lines
2.8 KiB
React
Raw Normal View History

2019-08-31 04:07:25 +05:00
import React, { useCallback, useRef } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';
import { Comment } from 'semantic-ui-react';
import { Markdown } from '../../../lib/custom-ui';
2019-08-31 04:07:25 +05:00
import CommentEdit from './CommentEdit';
2019-08-31 04:07:25 +05:00
import User from '../../User';
import DeletePopup from '../../DeletePopup';
import styles from './ItemComment.module.scss';
2019-08-31 04:07:25 +05:00
const ItemComment = React.memo(
({ data, createdAt, isPersisted, user, canEdit, onUpdate, onDelete }) => {
2019-08-31 04:07:25 +05:00
const [t] = useTranslation();
const commentEdit = useRef(null);
2019-08-31 04:07:25 +05:00
const handleEditClick = useCallback(() => {
commentEdit.current.open();
2019-08-31 04:07:25 +05:00
}, []);
return (
<Comment>
<span className={styles.user}>
2020-04-21 05:04:34 +05:00
<User name={user.name} avatarUrl={user.avatarUrl} />
2019-08-31 04:07:25 +05:00
</span>
<div className={classNames(styles.content)}>
<div className={styles.title}>
<span className={styles.author}>{user.name}</span>
<span className={styles.date}>
{t('format:longDateTime', {
postProcess: 'formatDate',
value: createdAt,
})}
</span>
</div>
<CommentEdit ref={commentEdit} defaultData={data} onUpdate={onUpdate}>
2019-08-31 04:07:25 +05:00
<>
2022-04-22 02:06:12 +05:00
<div className={styles.text}>
<Markdown linkTarget="_blank">{data.text}</Markdown>
</div>
{canEdit && (
<Comment.Actions>
2019-08-31 04:07:25 +05:00
<Comment.Action
as="button"
content={t('action.edit')}
disabled={!isPersisted}
onClick={handleEditClick}
/>
<DeletePopup
title={t('common.deleteComment', {
context: 'title',
})}
content={t('common.areYouSureYouWantToDeleteThisComment')}
buttonContent={t('action.deleteComment')}
onConfirm={onDelete}
>
<Comment.Action
as="button"
content={t('action.delete')}
disabled={!isPersisted}
/>
</DeletePopup>
</Comment.Actions>
)}
2019-08-31 04:07:25 +05:00
</>
</CommentEdit>
2019-08-31 04:07:25 +05:00
</div>
</Comment>
);
},
);
ItemComment.propTypes = {
data: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
createdAt: PropTypes.instanceOf(Date).isRequired,
isPersisted: PropTypes.bool.isRequired,
user: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
canEdit: PropTypes.bool.isRequired,
2019-08-31 04:07:25 +05:00
onUpdate: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
};
export default ItemComment;