-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathNewTaskDescriptionPage.js
120 lines (108 loc) · 4.03 KB
/
NewTaskDescriptionPage.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
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
import HeaderWithBackButton from '../../components/HeaderWithBackButton';
import Navigation from '../../libs/Navigation/Navigation';
import ScreenWrapper from '../../components/ScreenWrapper';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import Form from '../../components/Form';
import TextInput from '../../components/TextInput';
import Permissions from '../../libs/Permissions';
import ROUTES from '../../ROUTES';
import * as TaskUtils from '../../libs/actions/Task';
const propTypes = {
/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),
/** Grab the Share description of the Task */
task: PropTypes.shape({
/** Description of the Task */
description: PropTypes.string,
}),
...withLocalizePropTypes,
};
const defaultProps = {
betas: [],
task: {
description: '',
},
};
function NewTaskDescriptionPage(props) {
const inputRef = useRef(null);
// The selection will be used to place the cursor at the end if there is prior text in the text input area
const [selection, setSelection] = useState({start: 0, end: 0});
// eslint-disable-next-line rulesdir/prefer-early-return
useEffect(() => {
if (props.task.description) {
const length = props.task.description.length;
setSelection({start: length, end: length});
}
}, [props.task.description]);
// On submit, we want to call the assignTask function and wait to validate
// the response
const onSubmit = (values) => {
TaskUtils.setDescriptionValue(values.taskDescription);
Navigation.navigate(ROUTES.NEW_TASK);
};
if (!Permissions.canUseTasks(props.betas)) {
Navigation.dismissModal();
return null;
}
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
onEntryTransitionEnd={() => {
if (!inputRef.current) {
return;
}
inputRef.current.focus();
}}
>
<HeaderWithBackButton
title={props.translate('newTaskPage.description')}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
onBackButtonPress={() => Navigation.goBack(ROUTES.NEW_TASK)}
/>
<Form
formID={ONYXKEYS.FORMS.NEW_TASK_FORM}
submitButtonText={props.translate('common.next')}
style={[styles.mh5, styles.mt5, styles.flexGrow1]}
onSubmit={(values) => onSubmit(values)}
enabledWhenOffline
>
<View style={styles.mb5}>
<TextInput
defaultValue={props.task.description}
inputID="taskDescription"
label={props.translate('newTaskPage.descriptionOptional')}
ref={(el) => (inputRef.current = el)}
autoGrowHeight
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
selection={selection}
onSelectionChange={(e) => {
setSelection(e.nativeEvent.selection);
}}
/>
</View>
</Form>
</ScreenWrapper>
);
}
NewTaskDescriptionPage.displayName = 'NewTaskDescriptionPage';
NewTaskDescriptionPage.propTypes = propTypes;
NewTaskDescriptionPage.defaultProps = defaultProps;
export default compose(
withOnyx({
betas: {
key: ONYXKEYS.BETAS,
},
task: {
key: ONYXKEYS.TASK,
},
}),
withLocalize,
)(NewTaskDescriptionPage);