-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
EReceipt.tsx
109 lines (100 loc) · 5.43 KB
/
EReceipt.tsx
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
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as CardUtils from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Transaction} from '@src/types/onyx';
import EReceiptThumbnail from './EReceiptThumbnail';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';
type EReceiptOnyxProps = {
transaction: OnyxEntry<Transaction>;
};
type EReceiptProps = EReceiptOnyxProps & {
/* TransactionID of the transaction this EReceipt corresponds to */
transactionID: string;
};
function EReceipt({transaction, transactionID}: EReceiptProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
// Get receipt colorway, or default to Yellow.
const {backgroundColor: primaryColor, color: secondaryColor} = StyleUtils.getEReceiptColorStyles(StyleUtils.getEReceiptColorCode(transaction)) ?? {};
const {
amount: transactionAmount,
currency: transactionCurrency,
merchant: transactionMerchant,
created: transactionDate,
cardID: transactionCardID,
} = ReportUtils.getTransactionDetails(transaction, CONST.DATE.MONTH_DAY_YEAR_FORMAT) ?? {};
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency);
const currency = CurrencyUtils.getCurrencySymbol(transactionCurrency ?? '');
const amount = currency ? formattedAmount.replace(currency, '') : formattedAmount;
const cardDescription = TransactionUtils.getCardName(transaction) ?? (transactionCardID ? CardUtils.getCardDescription(transactionCardID) : '');
const secondaryTextColorStyle = secondaryColor ? StyleUtils.getColorStyle(secondaryColor) : undefined;
return (
<View style={[styles.eReceiptContainer, primaryColor ? StyleUtils.getBackgroundColorStyle(primaryColor) : undefined]}>
<View style={styles.fullScreen}>
<EReceiptThumbnail
transactionID={transactionID}
centerIconV={false}
/>
</View>
<View style={[styles.alignItemsCenter, styles.ph8, styles.pb14, styles.pt8]}>
<View style={[StyleUtils.getWidthAndHeightStyle(variables.eReceiptIconWidth, variables.eReceiptIconHeight)]} />
</View>
<View style={[styles.flexColumn, styles.justifyContentBetween, styles.alignItemsCenter, styles.ph9, styles.flex1]}>
<View style={[styles.alignItemsCenter, styles.alignSelfCenter, styles.flexColumn, styles.gap2, styles.mb8]}>
<View style={[styles.flexRow, styles.justifyContentCenter, StyleUtils.getWidthStyle(variables.eReceiptTextContainerWidth)]}>
<View style={[styles.flexColumn, styles.pt1]}>
<Text style={[styles.eReceiptCurrency, secondaryTextColorStyle]}>{currency}</Text>
</View>
<Text
adjustsFontSizeToFit
style={[styles.eReceiptAmountLarge, secondaryTextColorStyle]}
>
{amount}
</Text>
</View>
<Text style={[styles.eReceiptMerchant, styles.breakWord, styles.textAlignCenter]}>{transactionMerchant}</Text>
</View>
<View style={[styles.alignSelfStretch, styles.flexColumn, styles.mb8, styles.gap4]}>
<View style={[styles.flexColumn, styles.gap1]}>
<Text style={[styles.eReceiptWaypointTitle, secondaryTextColorStyle]}>{translate('eReceipt.transactionDate')}</Text>
<Text style={[styles.eReceiptWaypointAddress]}>{transactionDate}</Text>
</View>
<View style={[styles.flexColumn, styles.gap1]}>
<Text style={[styles.eReceiptWaypointTitle, secondaryTextColorStyle]}>{translate('common.card')}</Text>
<Text style={[styles.eReceiptWaypointAddress]}>{cardDescription}</Text>
</View>
</View>
<View style={[styles.justifyContentBetween, styles.alignItemsCenter, styles.alignSelfStretch, styles.flexRow, styles.mb8]}>
<Icon
width={variables.eReceiptWordmarkWidth}
height={variables.eReceiptWordmarkHeight}
fill={secondaryColor}
src={Expensicons.ExpensifyWordmark}
/>
<Text style={styles.eReceiptGuaranteed}>{translate('eReceipt.guaranteed')}</Text>
</View>
</View>
</View>
);
}
EReceipt.displayName = 'EReceipt';
export default withOnyx<EReceiptProps, EReceiptOnyxProps>({
transaction: {
key: ({transactionID}) => `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
},
})(EReceipt);
export type {EReceiptProps, EReceiptOnyxProps};