-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
MoneyRequestSelectorPage.js
151 lines (139 loc) · 6.4 KB
/
MoneyRequestSelectorPage.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import React, {useState} from 'react';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import ONYXKEYS from '../../ONYXKEYS';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import ScreenWrapper from '../../components/ScreenWrapper';
import HeaderWithBackButton from '../../components/HeaderWithBackButton';
import TabSelector from '../../components/TabSelector/TabSelector';
import CONST from '../../CONST';
import useLocalize from '../../hooks/useLocalize';
import * as IOUUtils from '../../libs/IOUUtils';
import Navigation from '../../libs/Navigation/Navigation';
import styles from '../../styles/styles';
import ReceiptSelector from './ReceiptSelector';
import * as IOU from '../../libs/actions/IOU';
import DistanceRequestPage from './DistanceRequestPage';
import DragAndDropProvider from '../../components/DragAndDrop/Provider';
import OnyxTabNavigator, {TopTab} from '../../libs/Navigation/OnyxTabNavigator';
import NewRequestAmountPage from './steps/NewRequestAmountPage';
import reportPropTypes from '../reportPropTypes';
import * as ReportUtils from '../../libs/ReportUtils';
import themeColors from '../../styles/themes/default';
const propTypes = {
/** React Navigation route */
route: PropTypes.shape({
/** Params from the route */
params: PropTypes.shape({
/** The type of IOU report, i.e. bill, request, send */
iouType: PropTypes.string,
/** The report ID of the IOU */
reportID: PropTypes.string,
}),
}).isRequired,
/** Report on which the money request is being created */
report: reportPropTypes,
/** Which tab has been selected */
selectedTab: PropTypes.string,
};
const defaultProps = {
selectedTab: CONST.TAB.SCAN,
report: {},
};
function MoneyRequestSelectorPage(props) {
const [isDraggingOver, setIsDraggingOver] = useState(false);
const iouType = lodashGet(props.route, 'params.iouType', '');
const reportID = lodashGet(props.route, 'params.reportID', '');
const {translate} = useLocalize();
const title = {
[CONST.IOU.MONEY_REQUEST_TYPE.REQUEST]: translate('iou.requestMoney'),
[CONST.IOU.MONEY_REQUEST_TYPE.SEND]: translate('iou.sendMoney'),
[CONST.IOU.MONEY_REQUEST_TYPE.SPLIT]: translate('iou.splitBill'),
};
const isFromGlobalCreate = !reportID;
const isExpenseRequest = ReportUtils.isPolicyExpenseChat(props.report);
const shouldDisplayDistanceRequest = isExpenseRequest || isFromGlobalCreate;
const resetMoneyRequestInfo = () => {
const moneyRequestID = `${iouType}${reportID}`;
IOU.resetMoneyRequestInfo(moneyRequestID);
};
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableKeyboardAvoidingView={false}
headerGapStyles={
isDraggingOver
? [
{
backgroundColor: themeColors.receiptDropUIBG,
},
]
: []
}
testID={MoneyRequestSelectorPage.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!IOUUtils.isValidMoneyRequestType(iouType)}>
<DragAndDropProvider
isDisabled={props.selectedTab !== CONST.TAB.SCAN}
setIsDraggingOver={setIsDraggingOver}
>
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton
title={title[iouType]}
onBackButtonPress={Navigation.dismissModal}
/>
{iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST ? (
<OnyxTabNavigator
id={CONST.TAB.RECEIPT_TAB_ID}
selectedTab={props.selectedTab}
tabBar={({state, navigation, position}) => (
<TabSelector
state={state}
navigation={navigation}
onTabPress={resetMoneyRequestInfo}
position={position}
/>
)}
>
<TopTab.Screen
name={CONST.TAB.MANUAL}
component={NewRequestAmountPage}
initialParams={{reportID, iouType}}
/>
<TopTab.Screen
name={CONST.TAB.SCAN}
component={ReceiptSelector}
initialParams={{reportID, iouType, pageIndex: 1}}
/>
{shouldDisplayDistanceRequest && (
<TopTab.Screen
name={CONST.TAB.DISTANCE}
component={DistanceRequestPage}
initialParams={{reportID, iouType}}
/>
)}
</OnyxTabNavigator>
) : (
<NewRequestAmountPage route={props.route} />
)}
</View>
</DragAndDropProvider>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
MoneyRequestSelectorPage.propTypes = propTypes;
MoneyRequestSelectorPage.defaultProps = defaultProps;
MoneyRequestSelectorPage.displayName = 'MoneyRequestSelectorPage';
export default withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
},
selectedTab: {
key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`,
},
})(MoneyRequestSelectorPage);