-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathNewTaskDetailsPage.js
108 lines (97 loc) · 3.53 KB
/
NewTaskDetailsPage.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
import React, {useRef} 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 HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import Navigation from '../../libs/Navigation/Navigation';
import ScreenWrapper from '../../components/ScreenWrapper';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import * as ErrorUtils from '../../libs/ErrorUtils';
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),
...withLocalizePropTypes,
};
const defaultProps = {
betas: [],
};
const NewTaskPage = (props) => {
const inputRef = useRef();
/**
* @param {Object} values - form input values passed by the Form component
* @returns {Boolean}
*/
function validate(values) {
const errors = {};
if (!values.taskTitle) {
// We error if the user doesn't enter a task name
ErrorUtils.addErrorMessage(errors, 'taskTitle', props.translate('newTaskPage.pleaseEnterTaskName'));
}
return errors;
}
// On submit, we want to call the assignTask function and wait to validate
// the response
function onSubmit(values) {
TaskUtils.setDetailsValue(values.taskTitle, values.taskDescription);
Navigation.navigate(ROUTES.NEW_TASK);
}
if (!Permissions.canUseTasks(props.betas)) {
Navigation.dismissModal();
return null;
}
return (
<ScreenWrapper
onEntryTransitionEnd={() => inputRef.current && inputRef.current.focus()}
includeSafeAreaPaddingBottom={false}
>
<HeaderWithCloseButton
title={props.translate('newTaskPage.assignTask')}
onCloseButtonPress={() => Navigation.dismissModal()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
/>
<Form
formID={ONYXKEYS.FORMS.NEW_TASK_FORM}
submitButtonText={props.translate('common.next')}
style={[styles.mh5, styles.mt5, styles.flexGrow1]}
validate={(values) => validate(values)}
onSubmit={(values) => onSubmit(values)}
enabledWhenOffline
>
<View style={styles.mb5}>
<TextInput
ref={(el) => (inputRef.current = el)}
inputID="taskTitle"
label={props.translate('newTaskPage.title')}
/>
</View>
<View style={styles.mb5}>
<TextInput
inputID="taskDescription"
defaultValue=""
label={props.translate('newTaskPage.descriptionOptional')}
/>
</View>
</Form>
</ScreenWrapper>
);
};
NewTaskPage.displayName = 'NewTaskPage';
NewTaskPage.propTypes = propTypes;
NewTaskPage.defaultProps = defaultProps;
export default compose(
withOnyx({
betas: {
key: ONYXKEYS.BETAS,
},
}),
withLocalize,
)(NewTaskPage);