1
1
import _ from 'underscore' ;
2
- import React from 'react' ;
2
+ import React , { useEffect } from 'react' ;
3
3
import PropTypes from 'prop-types' ;
4
4
import { View , StyleSheet } from 'react-native' ;
5
+ import lodashGet from 'lodash/get' ;
5
6
import * as optionRowStyles from '../../styles/optionRowStyles' ;
6
7
import styles from '../../styles/styles' ;
7
8
import * as StyleUtils from '../../styles/StyleUtils' ;
@@ -12,6 +13,7 @@ import Hoverable from '../Hoverable';
12
13
import DisplayNames from '../DisplayNames' ;
13
14
import colors from '../../styles/colors' ;
14
15
import withLocalize , { withLocalizePropTypes } from '../withLocalize' ;
16
+ import { withReportCommentDrafts } from '../OnyxProvider' ;
15
17
import Text from '../Text' ;
16
18
import SubscriptAvatar from '../SubscriptAvatar' ;
17
19
import CONST from '../../CONST' ;
@@ -23,12 +25,18 @@ import PressableWithSecondaryInteraction from '../PressableWithSecondaryInteract
23
25
import * as ReportActionContextMenu from '../../pages/home/report/ContextMenu/ReportActionContextMenu' ;
24
26
import * as ContextMenuActions from '../../pages/home/report/ContextMenu/ContextMenuActions' ;
25
27
import * as OptionsListUtils from '../../libs/OptionsListUtils' ;
28
+ import compose from '../../libs/compose' ;
29
+ import ONYXKEYS from '../../ONYXKEYS' ;
30
+ import * as Report from '../../libs/actions/Report' ;
26
31
27
32
const propTypes = {
28
33
/** Style for hovered state */
29
34
// eslint-disable-next-line react/forbid-prop-types
30
35
hoverStyle : PropTypes . object ,
31
36
37
+ /** The comment left by the user */
38
+ comment : PropTypes . string ,
39
+
32
40
/** The ID of the report that the option is for */
33
41
reportID : PropTypes . string . isRequired ,
34
42
@@ -52,11 +60,20 @@ const defaultProps = {
52
60
onSelectRow : ( ) => { } ,
53
61
isFocused : false ,
54
62
style : null ,
63
+ comment : '' ,
55
64
} ;
56
65
57
66
function OptionRowLHN ( props ) {
58
67
const optionItem = SidebarUtils . getOptionData ( props . reportID ) ;
59
68
69
+ useEffect ( ( ) => {
70
+ if ( ! optionItem || optionItem . hasDraftComment || ! props . comment || props . comment . length <= 0 || props . isFocused ) {
71
+ return ;
72
+ }
73
+ Report . setReportWithDraft ( props . reportID , true ) ;
74
+ // eslint-disable-next-line react-hooks/exhaustive-deps
75
+ } , [ ] ) ;
76
+
60
77
if ( ! optionItem ) {
61
78
return null ;
62
79
}
@@ -254,4 +271,13 @@ OptionRowLHN.propTypes = propTypes;
254
271
OptionRowLHN . defaultProps = defaultProps ;
255
272
OptionRowLHN . displayName = 'OptionRowLHN' ;
256
273
257
- export default withLocalize ( OptionRowLHN ) ;
274
+ export default compose (
275
+ withLocalize ,
276
+ withReportCommentDrafts ( {
277
+ propName : 'comment' ,
278
+ transformValue : ( drafts , props ) => {
279
+ const draftKey = `${ ONYXKEYS . COLLECTION . REPORT_DRAFT_COMMENT } ${ props . reportID } ` ;
280
+ return lodashGet ( drafts , draftKey , '' ) ;
281
+ } ,
282
+ } ) ,
283
+ ) ( OptionRowLHN ) ;
0 commit comments