-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReportWelcomeMessagePage.js
132 lines (121 loc) · 5.37 KB
/
ReportWelcomeMessagePage.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import React, {useCallback, useRef, useState} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import {useFocusEffect} from '@react-navigation/native';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import ScreenWrapper from '../components/ScreenWrapper';
import HeaderWithBackButton from '../components/HeaderWithBackButton';
import styles from '../styles/styles';
import reportPropTypes from './reportPropTypes';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import Text from '../components/Text';
import TextInput from '../components/TextInput';
import * as Report from '../libs/actions/Report';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import Form from '../components/Form';
import * as PolicyUtils from '../libs/PolicyUtils';
import {policyPropTypes, policyDefaultProps} from './workspace/withPolicy';
import ROUTES from '../ROUTES';
import Navigation from '../libs/Navigation/Navigation';
import updateMultilineInputRange from '../libs/UpdateMultilineInputRange';
const propTypes = {
...withLocalizePropTypes,
...policyPropTypes,
/** The report currently being looked at */
report: reportPropTypes.isRequired,
/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** Report ID passed via route r/:reportID/welcomeMessage */
reportID: PropTypes.string,
}),
}).isRequired,
};
const defaultProps = {
...policyDefaultProps,
};
function ReportWelcomeMessagePage(props) {
const parser = new ExpensiMark();
const [welcomeMessage, setWelcomeMessage] = useState(parser.htmlToMarkdown(props.report.welcomeMessage));
const welcomeMessageInputRef = useRef(null);
const focusTimeoutRef = useRef(null);
const handleWelcomeMessageChange = useCallback((value) => {
setWelcomeMessage(value);
}, []);
const submitForm = useCallback(() => {
Report.updateWelcomeMessage(props.report.reportID, props.report.welcomeMessage, welcomeMessage.trim());
}, [props.report.reportID, props.report.welcomeMessage, welcomeMessage]);
useFocusEffect(
useCallback(() => {
focusTimeoutRef.current = setTimeout(() => {
if (welcomeMessageInputRef.current) {
welcomeMessageInputRef.current.focus();
}
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, CONST.ANIMATED_TRANSITION);
}, []),
);
return (
<ScreenWrapper testID={ReportWelcomeMessagePage.displayName}>
<FullPageNotFoundView shouldShow={!PolicyUtils.isPolicyAdmin(props.policy)}>
<HeaderWithBackButton
title={props.translate('welcomeMessagePage.welcomeMessage')}
onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(props.report.reportID))}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM}
onSubmit={submitForm}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<Text style={[styles.mb5]}>{props.translate('welcomeMessagePage.explainerText')}</Text>
<View style={[styles.mb6]}>
<TextInput
inputID="welcomeMessage"
label={props.translate('welcomeMessagePage.welcomeMessage')}
accessibilityLabel={props.translate('welcomeMessagePage.welcomeMessage')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
autoGrowHeight
maxLength={CONST.MAX_COMMENT_LENGTH}
ref={(el) => {
if (!el) {
return;
}
welcomeMessageInputRef.current = el;
updateMultilineInputRange(welcomeMessageInputRef.current);
}}
value={welcomeMessage}
onChangeText={handleWelcomeMessageChange}
autoCapitalize="none"
textAlignVertical="top"
containerStyles={[styles.autoGrowHeightMultilineInput]}
/>
</View>
</Form>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
ReportWelcomeMessagePage.displayName = 'ReportWelcomeMessagePage';
ReportWelcomeMessagePage.propTypes = propTypes;
ReportWelcomeMessagePage.defaultProps = defaultProps;
export default compose(
withLocalize,
withReportOrNotFound,
withOnyx({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
}),
)(ReportWelcomeMessagePage);