forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoneyRequestSelectorPage.js
141 lines (131 loc) · 5.81 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
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import React 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 usePermissions from '../../hooks/usePermissions';
import OnyxTabNavigator, {TopTab} from '../../libs/Navigation/OnyxTabNavigator';
import participantPropTypes from '../../components/participantPropTypes';
import NewRequestAmountPage from './steps/NewRequestAmountPage';
const propTypes = {
/** React Navigation route */
route: PropTypes.shape({
params: PropTypes.shape({
iouType: PropTypes.string,
reportID: PropTypes.string,
}),
}),
/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
iou: PropTypes.shape({
id: PropTypes.string,
amount: PropTypes.number,
currency: PropTypes.string,
participants: PropTypes.arrayOf(participantPropTypes),
}),
/** Which tab has been selected */
selectedTab: PropTypes.string,
};
const defaultProps = {
route: {
params: {
iouType: '',
reportID: '',
},
},
iou: {
id: '',
amount: 0,
currency: CONST.CURRENCY.USD,
participants: [],
},
selectedTab: CONST.TAB.MANUAL,
};
function MoneyRequestSelectorPage(props) {
const iouType = lodashGet(props.route, 'params.iouType', '');
const reportID = lodashGet(props.route, 'params.reportID', '');
const {translate} = useLocalize();
const {canUseScanReceipts, canUseDistanceRequests} = usePermissions();
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 resetMoneyRequestInfo = () => {
const moneyRequestID = `${iouType}${reportID}`;
IOU.resetMoneyRequestInfo(moneyRequestID);
};
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableKeyboardAvoidingView={false}
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!IOUUtils.isValidMoneyRequestType(iouType)}>
<DragAndDropProvider isDisabled={props.selectedTab === CONST.TAB.MANUAL}>
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton
title={title[iouType]}
onBackButtonPress={Navigation.dismissModal}
/>
{(canUseScanReceipts || canUseDistanceRequests) && iouType === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST ? (
<OnyxTabNavigator
id={CONST.TAB.RECEIPT_TAB_ID}
tabBar={({state, navigation}) => (
<TabSelector
state={state}
navigation={navigation}
onTabPress={resetMoneyRequestInfo}
/>
)}
>
<TopTab.Screen
name={CONST.TAB.MANUAL}
component={NewRequestAmountPage}
initialParams={{reportID, iouType}}
/>
{canUseScanReceipts && (
<TopTab.Screen
name={CONST.TAB.SCAN}
component={ReceiptSelector}
initialParams={{reportID, iouType}}
/>
)}
{canUseDistanceRequests && (
<TopTab.Screen
name={CONST.TAB.DISTANCE}
component={DistanceRequestPage}
/>
)}
</OnyxTabNavigator>
) : (
<NewRequestAmountPage route={props.route} />
)}
</View>
</DragAndDropProvider>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
MoneyRequestSelectorPage.propTypes = propTypes;
MoneyRequestSelectorPage.defaultProps = defaultProps;
MoneyRequestSelectorPage.displayName = 'MoneyRequestSelectorPage';
export default withOnyx({
selectedTab: {
key: `${ONYXKEYS.SELECTED_TAB}_${CONST.TAB.RECEIPT_TAB_ID}`,
},
})(MoneyRequestSelectorPage);