-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportPreview.js
154 lines (135 loc) · 5.9 KB
/
ReportPreview.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
152
153
154
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import Text from '../Text';
import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import styles from '../../styles/styles';
import reportActionPropTypes from '../../pages/home/report/reportActionPropTypes';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import ControlSelection from '../../libs/ControlSelection';
import * as DeviceCapabilities from '../../libs/DeviceCapabilities';
import {showContextMenuForReport} from '../ShowContextMenuContext';
import * as StyleUtils from '../../styles/StyleUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import SettlementButton from '../SettlementButton';
import getButtonState from '../../libs/getButtonState';
import * as IOU from '../../libs/actions/IOU';
import refPropTypes from '../refPropTypes';
import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback';
const propTypes = {
/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,
/** The associated chatReport */
chatReportID: PropTypes.string.isRequired,
/** The active IOUReport, used for Onyx subscription */
// eslint-disable-next-line react/no-unused-prop-types
iouReportID: PropTypes.string.isRequired,
/* 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,
}),
/** Active IOU Report for current report */
iouReport: PropTypes.shape({
/** Email address of the manager in this iou report */
managerEmail: PropTypes.string,
/** Email address of the creator of this iou report */
ownerEmail: PropTypes.string,
/** Outstanding amount in cents of this transaction */
total: PropTypes.number,
/** Currency of outstanding amount of this transaction */
currency: PropTypes.string,
/** Does the iouReport have an outstanding IOU? */
hasOutstandingIOU: PropTypes.bool,
}),
/** Session info for the currently logged in user. */
session: PropTypes.shape({
/** Currently logged in user email */
email: PropTypes.string,
}),
/** Popover context menu anchor, used for showing context menu */
contextMenuAnchor: refPropTypes,
/** Callback for updating context menu active state, used for showing context menu */
checkIfContextMenuActive: PropTypes.func,
/** Whether the IOU is hovered so we can modify its style */
isHovered: PropTypes.bool,
...withLocalizePropTypes,
};
const defaultProps = {
contextMenuAnchor: null,
isHovered: false,
chatReport: {},
iouReport: {},
checkIfContextMenuActive: () => {},
session: {
email: null,
},
};
function ReportPreview(props) {
const managerEmail = props.iouReport.managerEmail || '';
const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null);
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const displayingMessage = ReportUtils.getReportPreviewMessage(props.iouReport, props.action);
return (
<View style={[styles.chatItemMessage]}>
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.getReportRoute(props.iouReportID));
}}
onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)}
style={[styles.flexRow, styles.justifyContentBetween]}
accessibilityRole="button"
accessibilityLabel={props.translate('iou.viewDetails')}
>
<View style={[styles.flexShrink1]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>{displayingMessage}</Text>
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
/>
</PressableWithoutFeedback>
{isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && (
<SettlementButton
currency={props.iouReport.currency}
policyID={props.iouReport.policyID}
chatReportID={props.chatReportID}
iouReport={props.iouReport}
onPress={(paymentType) => IOU.payMoneyRequest(paymentType, props.chatReport, props.iouReport)}
enablePaymentsRoute={ROUTES.BANK_ACCOUNT_NEW}
addBankAccountRoute={bankAccountRoute}
style={[styles.requestPreviewBox]}
/>
)}
</View>
);
}
ReportPreview.propTypes = propTypes;
ReportPreview.defaultProps = defaultProps;
ReportPreview.displayName = 'ReportPreview';
export default compose(
withLocalize,
withOnyx({
chatReport: {
key: ({chatReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`,
},
iouReport: {
key: ({iouReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(ReportPreview);