-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathIOUDetailsModal.js
162 lines (144 loc) · 6.16 KB
/
IOUDetailsModal.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
155
156
157
158
159
160
161
162
import React, {Component} from 'react';
import {View, ActivityIndicator, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import themeColors from '../../styles/themes/default';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import Navigation from '../../libs/Navigation/Navigation';
import ScreenWrapper from '../../components/ScreenWrapper';
import * as IOU from '../../libs/actions/IOU';
import * as Report from '../../libs/actions/Report';
import IOUPreview from '../../components/ReportActionItem/IOUPreview';
import IOUTransactions from './IOUTransactions';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import compose from '../../libs/compose';
import CONST from '../../CONST';
import SettlementButton from '../../components/SettlementButton';
const propTypes = {
/** URL Route params */
route: PropTypes.shape({
/** Params from the URL path */
params: PropTypes.shape({
/** chatReportID passed via route: /iou/details/:chatReportID/:iouReportID */
chatReportID: PropTypes.string,
/** iouReportID passed via route: /iou/details/:chatReportID/:iouReportID */
iouReportID: PropTypes.string,
}),
}).isRequired,
/* Onyx Props */
/** Holds data related to IOU view state, rather than the underlying IOU data. */
iou: PropTypes.shape({
/** Is the IOU Report currently being paid? */
loading: PropTypes.bool,
/** Error message, empty represents no error */
error: PropTypes.bool,
}),
/** IOU Report data object */
iouReport: PropTypes.shape({
/** ID for the chatReport that this IOU is linked to */
chatReportID: PropTypes.number,
/** Manager is the person who currently owes money */
managerEmail: PropTypes.string,
/** Owner is the person who is owed money */
ownerEmail: 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,
}).isRequired,
...withLocalizePropTypes,
};
const defaultProps = {
iou: {},
iouReport: undefined,
};
class IOUDetailsModal extends Component {
componentDidMount() {
Report.fetchIOUReportByID(this.props.route.params.iouReportID, this.props.route.params.chatReportID, true);
}
/**
* @returns {String}
*/
getSubmitterPhoneNumber() {
return _.first(lodashGet(this.props, 'iouReport.submitterPhoneNumbers', [])) || '';
}
/**
* @param {String} paymentMethodType
*/
performIOUPayment(paymentMethodType) {
IOU.payIOUReport({
chatReportID: this.props.route.params.chatReportID,
reportID: this.props.route.params.iouReportID,
paymentMethodType,
amount: this.props.iouReport.total,
currency: this.props.iouReport.currency,
submitterPayPalMeAddress: this.props.iouReport.submitterPayPalMeAddress,
submitterPhoneNumber: this.getSubmitterPhoneNumber(),
});
}
render() {
const sessionEmail = lodashGet(this.props.session, 'email', null);
const reportIsLoading = _.isUndefined(this.props.iouReport);
return (
<ScreenWrapper>
<HeaderWithCloseButton
title={this.props.translate('common.details')}
onCloseButtonPress={Navigation.dismissModal}
/>
{reportIsLoading ? <ActivityIndicator color={themeColors.text} /> : (
<View style={[styles.flex1, styles.justifyContentBetween]}>
<ScrollView contentContainerStyle={styles.iouDetailsContainer}>
<IOUPreview
iou={this.props.iouReport}
chatReportID={Number(this.props.route.params.chatReportID)}
iouReportID={Number(this.props.route.params.iouReportID)}
shouldHidePayButton
/>
<IOUTransactions
chatReportID={Number(this.props.route.params.chatReportID)}
iouReportID={Number(this.props.route.params.iouReportID)}
isIOUSettled={this.props.iouReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED}
userEmail={sessionEmail}
/>
</ScrollView>
{(this.props.iouReport.hasOutstandingIOU
&& this.props.iouReport.managerEmail === sessionEmail && (
<View style={styles.p5}>
<SettlementButton
isLoading={this.props.iou.loading}
onPress={paymentMethodType => this.performIOUPayment(paymentMethodType)}
recipientPhoneNumber={this.getSubmitterPhoneNumber()}
shouldShowPaypal={Boolean(lodashGet(this.props, 'iouReport.submitterPayPalMeAddress'))}
currency={lodashGet(this.props, 'iouReport.currency')}
/>
</View>
))}
</View>
)}
</ScreenWrapper>
);
}
}
IOUDetailsModal.propTypes = propTypes;
IOUDetailsModal.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
iou: {
key: ONYXKEYS.IOU,
},
iouReport: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_IOUS}${route.params.iouReportID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(IOUDetailsModal);