-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathComment.js
More file actions
69 lines (63 loc) · 2.06 KB
/
Comment.js
File metadata and controls
69 lines (63 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { IconEdit16 } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../../locales/index.js'
import {
Message,
MessageIconButton,
MessageStatsBar,
getCommentAccess,
} from '../common/index.js'
import { CommentDeleteButton } from './CommentDeleteButton.js'
import { CommentUpdateForm } from './CommentUpdateForm.js'
const Comment = ({
comment,
currentUser,
interpretationId,
onThreadUpdated,
canComment,
}) => {
const [isUpdateMode, setIsUpdateMode] = useState(false)
const commentAccess = getCommentAccess(comment, canComment, currentUser)
return isUpdateMode ? (
<CommentUpdateForm
close={() => setIsUpdateMode(false)}
commentId={comment.id}
interpretationId={interpretationId}
onComplete={() => onThreadUpdated(false)}
text={comment.text}
currentUser={currentUser}
/>
) : (
<Message
text={comment.text}
created={comment.created}
username={comment.createdBy.displayName}
>
{commentAccess.edit && (
<MessageStatsBar>
<MessageIconButton
iconComponent={IconEdit16}
tooltipContent={i18n.t('Edit')}
onClick={() => setIsUpdateMode(true)}
/>
{commentAccess.delete && (
<CommentDeleteButton
commentId={comment.id}
interpretationId={interpretationId}
onComplete={() => onThreadUpdated(true)}
/>
)}
</MessageStatsBar>
)}
</Message>
)
}
Comment.propTypes = {
comment: PropTypes.object.isRequired,
currentUser: PropTypes.object.isRequired,
interpretationId: PropTypes.string.isRequired,
onThreadUpdated: PropTypes.func.isRequired,
canComment: PropTypes.bool,
}
export { Comment }