-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathHoldReasonPage.js
104 lines (91 loc) · 3.53 KB
/
HoldReasonPage.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
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useRef} from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
const propTypes = {
/** Navigation route context info provided by react navigation */
route: PropTypes.shape({
/** Route specific parameters used on this screen via route :iouType/new/category/:reportID? */
params: PropTypes.shape({
/** ID of the transaction the page was opened for */
transactionID: PropTypes.string,
/** ID of the report that user is providing hold reason to */
reportID: PropTypes.string,
/** Link to previous page */
backTo: PropTypes.string,
}),
}).isRequired,
};
function HoldReasonPage({route}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const reasonRef = useRef();
const transactionID = lodashGet(route, 'params.transactionID', '');
const reportID = lodashGet(route, 'params.reportID', '');
const backTo = lodashGet(route, 'params.backTo', '');
const navigateBack = () => {
Navigation.navigate(backTo);
};
const onSubmit = (values) => {
IOU.putOnHold(transactionID, values.comment, reportID);
navigateBack();
};
const validate = useCallback((value) => {
const errors = {};
if (_.isEmpty(value.comment)) {
errors.comment = 'common.error.fieldRequired';
}
return errors;
}, []);
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
testID={HoldReasonPage.displayName}
>
<HeaderWithBackButton
title={translate('iou.holdRequest')}
onBackButtonPress={navigateBack}
/>
<FormProvider
formID="moneyHoldReason"
submitButtonText={translate('iou.holdRequest')}
style={[styles.flexGrow1, styles.ph5]}
onSubmit={onSubmit}
validate={validate}
enabledWhenOffline
>
<Text style={[styles.textHeadline, styles.mb6]}>{translate('iou.explainHold')}</Text>
<View>
<InputWrapper
InputComponent={TextInput}
inputID="comment"
valueType="string"
name="comment"
defaultValue=""
label="Reason"
accessibilityLabel={translate('iou.reason')}
role={CONST.ACCESSIBILITY_ROLE.TEXT}
ref={(e) => (reasonRef.current = e)}
autoFocus
/>
</View>
</FormProvider>
</ScreenWrapper>
);
}
HoldReasonPage.displayName = 'MoneyRequestHoldReasonPage';
HoldReasonPage.propTypes = propTypes;
export default HoldReasonPage;