-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCommentDeleteButton.js
More file actions
62 lines (56 loc) · 1.88 KB
/
CommentDeleteButton.js
File metadata and controls
62 lines (56 loc) · 1.88 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
import { useDataMutation } from '@dhis2/app-runtime'
import { IconDelete16, colors } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../../locales/index.js'
import { MessageIconButton } from '../common/index.js'
const mutation = {
resource: 'interpretations',
id: ({ interpretationId, commentId }) =>
`${interpretationId}/comments/${commentId}`,
type: 'delete',
}
const CommentDeleteButton = ({ commentId, interpretationId, onComplete }) => {
const [deleteError, setDeleteError] = useState(null)
const [remove, { loading }] = useDataMutation(mutation, {
onComplete: () => {
setDeleteError(null)
onComplete()
},
onError: () => setDeleteError(i18n.t('Delete failed')),
variables: { commentId, interpretationId },
})
const onDelete = () => {
setDeleteError(null)
remove()
}
return (
<div className="delete-button-container">
<MessageIconButton
tooltipContent={i18n.t('Delete')}
iconComponent={IconDelete16}
onClick={onDelete}
disabled={loading}
/>
{deleteError && <span className="delete-error">{deleteError}</span>}
<style jsx>{`
.delete-button-container {
display: flex;
align-items: center;
gap: 4px;
}
.delete-error {
color: ${colors.red500};
font-size: 12px;
line-height: 12px;
}
`}</style>
</div>
)
}
CommentDeleteButton.propTypes = {
commentId: PropTypes.string.isRequired,
interpretationId: PropTypes.string.isRequired,
onComplete: PropTypes.func.isRequired,
}
export { CommentDeleteButton }