-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInterpretationUpdateForm.js
More file actions
86 lines (82 loc) · 2.69 KB
/
InterpretationUpdateForm.js
File metadata and controls
86 lines (82 loc) · 2.69 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { useDataMutation } from '@dhis2/app-runtime'
import { Button, spacers, colors } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import i18n from '../../../../locales/index.js'
import { RichTextEditor } from '../../../RichText/index.js'
import {
MessageEditorContainer,
MessageButtonStrip,
InterpretationSharingLink,
} from '../index.js'
const mutation = {
resource: 'interpretations',
type: 'update',
partial: false,
id: ({ id }) => id,
data: ({ interpretationText }) => interpretationText,
}
export const InterpretationUpdateForm = ({
close,
currentUser,
id,
onComplete,
showSharingLink,
text,
}) => {
const [interpretationText, setInterpretationText] = useState(text || '')
const [update, { loading, error }] = useDataMutation(mutation, {
onComplete: () => {
onComplete()
close()
},
variables: { id },
})
const errorText = error
? error.message || i18n.t('Could not update interpretation')
: ''
return (
<div className="message">
<MessageEditorContainer currentUser={currentUser}>
<RichTextEditor
inputPlaceholder={i18n.t('Enter interpretation text')}
onChange={setInterpretationText}
value={interpretationText}
disabled={loading}
errorText={errorText}
/>
{showSharingLink && (
<InterpretationSharingLink id={id} type="interpretation" />
)}
<MessageButtonStrip>
<Button
loading={loading}
primary
small
onClick={() => update({ interpretationText })}
>
{i18n.t('Update')}
</Button>
<Button disabled={loading} secondary small onClick={close}>
{i18n.t('Cancel')}
</Button>
</MessageButtonStrip>
</MessageEditorContainer>
<style jsx>{`
.message {
padding: 0 ${spacers.dp8} ${spacers.dp8};
background-color: ${colors.grey100};
border-radius: 5px;
}
`}</style>
</div>
)
}
InterpretationUpdateForm.propTypes = {
close: PropTypes.func.isRequired,
currentUser: PropTypes.object.isRequired,
id: PropTypes.string.isRequired,
onComplete: PropTypes.func.isRequired,
showSharingLink: PropTypes.bool,
text: PropTypes.string,
}