-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
DistanceEReceipt.js
121 lines (117 loc) · 5.97 KB
/
DistanceEReceipt.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
import React, {useMemo} from 'react';
import {View, ScrollView} from 'react-native';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import Text from './Text';
import styles from '../styles/styles';
import transactionPropTypes from './transactionPropTypes';
import * as ReceiptUtils from '../libs/ReceiptUtils';
import * as ReportUtils from '../libs/ReportUtils';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import * as TransactionUtils from '../libs/TransactionUtils';
import tryResolveUrlFromApiRoot from '../libs/tryResolveUrlFromApiRoot';
import ThumbnailImage from './ThumbnailImage';
import useLocalize from '../hooks/useLocalize';
import Icon from './Icon';
import themeColors from '../styles/themes/default';
import * as Expensicons from './Icon/Expensicons';
import EReceiptBackground from '../../assets/images/eReceipt_background.svg';
import useNetwork from '../hooks/useNetwork';
import PendingMapView from './MapView/PendingMapView';
const propTypes = {
/** The transaction for the distance request */
transaction: transactionPropTypes,
};
const defaultProps = {
transaction: {},
};
function DistanceEReceipt({transaction}) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {thumbnail} = TransactionUtils.hasReceipt(transaction) ? ReceiptUtils.getThumbnailAndImageURIs(transaction.receipt.source, transaction.filename) : {};
const {amount: transactionAmount, currency: transactionCurrency, merchant: transactionMerchant, created: transactionDate} = ReportUtils.getTransactionDetails(transaction);
const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail || '');
const waypoints = lodashGet(transaction, 'comment.waypoints', {});
const sortedWaypoints = useMemo(
() =>
// The waypoint keys are sometimes out of order
_.chain(waypoints)
.keys()
.sort((keyA, keyB) => TransactionUtils.getWaypointIndex(keyA) - TransactionUtils.getWaypointIndex(keyB))
.map((key) => ({[key]: waypoints[key]}))
.reduce((result, obj) => (obj ? _.assign(result, obj) : result), {})
.value(),
[waypoints],
);
return (
<View style={[styles.flex1, styles.alignItemsCenter]}>
<ScrollView
style={styles.w100}
contentContainerStyle={[styles.flexGrow1, styles.justifyContentCenter, styles.alignItemsCenter]}
>
<View style={styles.eReceiptPanel}>
<EReceiptBackground
style={styles.eReceiptBackground}
pointerEvents="none"
/>
<View style={[styles.moneyRequestViewImage, styles.mh0, styles.mt0, styles.mb5, styles.borderNone]}>
{isOffline || !thumbnailSource ? (
<PendingMapView />
) : (
<ThumbnailImage
previewSourceURL={thumbnailSource}
style={[styles.w100, styles.h100]}
isAuthTokenRequired
shouldDynamicallyResize={false}
/>
)}
</View>
<View style={[styles.mb10, styles.gap5, styles.ph2, styles.flexColumn, styles.alignItemsCenter]}>
<Text style={styles.eReceiptAmount}>{formattedTransactionAmount}</Text>
<Text style={styles.eReceiptMerchant}>{transactionMerchant}</Text>
</View>
<View style={[styles.mb10, styles.gap5, styles.ph2]}>
{_.map(sortedWaypoints, (waypoint, key) => {
const index = TransactionUtils.getWaypointIndex(key);
let descriptionKey = 'distance.waypointDescription.';
if (index === 0) {
descriptionKey += 'start';
} else if (index === _.size(waypoints) - 1) {
descriptionKey += 'finish';
} else {
descriptionKey += 'stop';
}
return (
<View
style={styles.gap1}
key={key}
>
<Text style={styles.eReceiptWaypointTitle}>{translate(descriptionKey)}</Text>
<Text style={styles.eReceiptWaypointAddress}>{waypoint.address || ''}</Text>
</View>
);
})}
<View style={styles.gap1}>
<Text style={styles.eReceiptWaypointTitle}>{translate('common.date')}</Text>
<Text style={styles.eReceiptWaypointAddress}>{transactionDate}</Text>
</View>
</View>
<View style={[styles.ph2, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}>
<Icon
width={86}
height={19.25}
fill={themeColors.textBrand}
src={Expensicons.ExpensifyWordmark}
/>
<Text style={styles.eReceiptGuaranteed}>{translate('eReceipt.guaranteed')}</Text>
</View>
</View>
</ScrollView>
</View>
);
}
export default DistanceEReceipt;
DistanceEReceipt.displayName = 'DistanceEReceipt';
DistanceEReceipt.propTypes = propTypes;
DistanceEReceipt.defaultProps = defaultProps;