forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOUAction.js
147 lines (128 loc) · 5.23 KB
/
IOUAction.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
import _ from 'underscore';
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../../ONYXKEYS';
import CONST from '../../CONST';
import {withNetwork} from '../OnyxProvider';
import compose from '../../libs/compose';
import IOUQuote from './IOUQuote';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import networkPropTypes from '../networkPropTypes';
import iouReportPropTypes from '../../pages/iouReportPropTypes';
import IOUPreview from './IOUPreview';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import styles from '../../styles/styles';
import * as IOUUtils from '../../libs/IOUUtils';
const propTypes = {
/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,
/** The ID of the associated chatReport */
chatReportID: PropTypes.string.isRequired,
/** The ID of the associated request report */
requestReportID: PropTypes.string.isRequired,
/** Is this IOUACTION the most recent? */
isMostRecentIOUReportAction: PropTypes.bool.isRequired,
/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: PropTypes.shape({current: PropTypes.elementType}),
/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive: PropTypes.func,
/* Onyx Props */
/** chatReport associated with iouReport */
chatReport: PropTypes.shape({
/** The participants of this report */
participants: PropTypes.arrayOf(PropTypes.string),
/** Whether the chat report has an outstanding IOU */
hasOutstandingIOU: PropTypes.bool.isRequired,
}),
/** IOU report data object */
iouReport: iouReportPropTypes,
/** Array of report actions for this report */
reportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
/** Whether the IOU is hovered so we can modify its style */
isHovered: PropTypes.bool,
network: networkPropTypes.isRequired,
};
const defaultProps = {
contextMenuAnchor: undefined,
checkIfContextMenuActive: () => {},
chatReport: {
participants: [],
},
iouReport: {},
reportActions: {},
isHovered: false,
};
const IOUAction = (props) => {
const hasMultipleParticipants = props.chatReport.participants.length > 1;
const onIOUPreviewPressed = () => {
if (hasMultipleParticipants) {
Navigation.navigate(ROUTES.getReportParticipantsRoute(props.chatReportID));
} else {
Navigation.navigate(ROUTES.getIouDetailsRoute(props.chatReportID, props.action.originalMessage.IOUReportID));
}
};
const shouldShowIOUPreview = props.isMostRecentIOUReportAction || props.action.originalMessage.type === 'pay';
let shouldShowPendingConversionMessage = false;
if (
!_.isEmpty(props.iouReport)
&& !_.isEmpty(props.reportActions)
&& props.chatReport.hasOutstandingIOU
&& props.isMostRecentIOUReportAction
&& props.action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD
&& props.network.isOffline
) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(props.reportActions, props.iouReport);
}
return (
<>
<IOUQuote
action={props.action}
chatReportID={props.chatReportID}
contextMenuAnchor={props.contextMenuAnchor}
onViewDetailsPressed={onIOUPreviewPressed}
checkIfContextMenuActive={props.checkIfContextMenuActive}
isHovered={props.isHovered}
/>
{shouldShowIOUPreview && (
<IOUPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
isBillSplit={hasMultipleParticipants}
action={props.action}
contextMenuAnchor={props.contextMenuAnchor}
checkIfContextMenuActive={props.checkIfContextMenuActive}
shouldShowPendingConversionMessage={shouldShowPendingConversionMessage}
onPayButtonPressed={onIOUPreviewPressed}
onPreviewPressed={onIOUPreviewPressed}
containerStyles={[
styles.cursorPointer,
props.isHovered
? styles.iouPreviewBoxHover
: undefined,
]}
isHovered={props.isHovered}
/>
)}
</>
);
};
IOUAction.propTypes = propTypes;
IOUAction.defaultProps = defaultProps;
IOUAction.displayName = 'IOUAction';
export default compose(
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
iouReport: {
key: ({requestReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${requestReportID}`,
},
reportActions: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`,
canEvict: false,
},
}),
withNetwork(),
)(IOUAction);