-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathIOUBadge.js
68 lines (61 loc) · 1.7 KB
/
IOUBadge.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
import React from 'react';
import PropTypes from 'prop-types';
import {Text, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../ONYXKEYS';
import styles from '../styles/styles';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
const propTypes = {
/** IOU Report data object */
iouReport: PropTypes.shape({
/** The total amount in cents */
total: PropTypes.number,
/** The owner of the IOUReport */
ownerEmail: PropTypes.string,
}),
/** Session of currently logged in user */
session: PropTypes.shape({
email: PropTypes.string.isRequired,
}).isRequired,
...withLocalizePropTypes,
};
const defaultProps = {
iouReport: {
total: 0,
ownerEmail: null,
},
};
const IOUBadge = props => (
<View
style={[
styles.badge,
styles.ml2,
props.session.email === props.iouReport.ownerEmail ? styles.badgeSuccess : styles.badgeDanger,
]}
>
<Text
style={styles.badgeText}
numberOfLines={1}
>
{props.numberFormat(
props.iouReport.total / 100,
{style: 'currency', currency: props.iouReport.currency},
)}
</Text>
</View>
);
IOUBadge.displayName = 'IOUBadge';
IOUBadge.propTypes = propTypes;
IOUBadge.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
iouReport: {
key: ({iouReportID}) => `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(IOUBadge);