1
- import React from 'react' ;
2
1
import PropTypes from 'prop-types' ;
3
- import styles from '../../styles/styles' ;
4
- import Image from '../Image' ;
5
- import ThumbnailImage from '../ThumbnailImage' ;
6
- import tryResolveUrlFromApiRoot from '../../libs/tryResolveUrlFromApiRoot' ;
7
- import ROUTES from '../../ROUTES' ;
8
- import CONST from '../../CONST' ;
9
- import { ShowContextMenuContext } from '../ShowContextMenuContext' ;
10
- import Navigation from '../../libs/Navigation/Navigation' ;
11
- import PressableWithoutFocus from '../Pressable/PressableWithoutFocus' ;
12
- import useLocalize from '../../hooks/useLocalize' ;
2
+ import React from 'react' ;
3
+ import { View } from 'react-native' ;
4
+ import _ from 'underscore' ;
5
+ import EReceiptThumbnail from '@components/EReceiptThumbnail' ;
6
+ import Image from '@components/Image' ;
7
+ import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus' ;
8
+ import { ShowContextMenuContext } from '@components/ShowContextMenuContext' ;
9
+ import ThumbnailImage from '@components/ThumbnailImage' ;
10
+ import transactionPropTypes from '@components/transactionPropTypes' ;
11
+ import useLocalize from '@hooks/useLocalize' ;
12
+ import Navigation from '@libs/Navigation/Navigation' ;
13
+ import * as TransactionUtils from '@libs/TransactionUtils' ;
14
+ import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot' ;
15
+ import styles from '@styles/styles' ;
16
+ import CONST from '@src/CONST' ;
17
+ import ROUTES from '@src/ROUTES' ;
18
+ import Icon from '../../components/Icon' ;
19
+ import * as StyleUtils from '@styles/StyleUtils' ;
20
+ import variables from '@styles/variables' ;
21
+ import * as Expensicons from '../../components/Icon/Expensicons' ;
22
+ import colors from '../../styles/colors' ;
23
+ import useNetwork from '@hooks/useNetwork' ;
13
24
14
25
const propTypes = {
15
26
/** thumbnail URI for the image */
@@ -20,11 +31,23 @@ const propTypes = {
20
31
21
32
/** whether or not to enable the image preview modal */
22
33
enablePreviewModal : PropTypes . bool ,
34
+
35
+ /* The transaction associated with this image, if any. Passed for handling eReceipts. */
36
+ transaction : transactionPropTypes ,
37
+
38
+ /** Icon to use as a fallback when offline */
39
+ fallbackIcon : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] ) ,
40
+
41
+ /** The fill color to pass into the icon. */
42
+ iconFill : PropTypes . string ,
23
43
} ;
24
44
25
45
const defaultProps = {
26
46
thumbnail : null ,
47
+ transaction : { } ,
27
48
enablePreviewModal : false ,
49
+ iconFill : colors . green700 ,
50
+ fallbackIcon : Expensicons . ReceiptPlaceholderImage , // Default fallback icon
28
51
} ;
29
52
30
53
/**
@@ -33,24 +56,50 @@ const defaultProps = {
33
56
* and optional preview modal as well.
34
57
*/
35
58
36
- function ReportActionItemImage ( { thumbnail, image, enablePreviewModal} ) {
59
+ function ReportActionItemImage ( { thumbnail, image, enablePreviewModal, transaction } ) {
37
60
const { translate} = useLocalize ( ) ;
38
61
const imageSource = tryResolveUrlFromApiRoot ( image || '' ) ;
39
62
const thumbnailSource = tryResolveUrlFromApiRoot ( thumbnail || '' ) ;
63
+ const isEReceipt = ! _ . isEmpty ( transaction ) && TransactionUtils . hasEReceipt ( transaction ) ;
64
+ const { isOffline} = useNetwork ( ) ;
65
+ let heightStyle = StyleUtils . getHeight ( variables . iconImageHeight ) ;
40
66
41
- const receiptImageComponent = thumbnail ? (
42
- < ThumbnailImage
43
- previewSourceURL = { thumbnailSource }
44
- style = { [ styles . w100 , styles . h100 ] }
45
- isAuthTokenRequired
46
- shouldDynamicallyResize = { false }
47
- />
48
- ) : (
49
- < Image
50
- source = { { uri : image } }
51
- style = { [ styles . w100 , styles . h100 ] }
52
- />
53
- ) ;
67
+ let receiptImageComponent ;
68
+
69
+ if ( isEReceipt ) {
70
+ if ( isOffline ) {
71
+ receiptImageComponent = (
72
+ < Icon
73
+ src = { props . fallbackIcon }
74
+ fill = { props . iconFill }
75
+ height = { heightStyle . height }
76
+ width = { heightStyle . height }
77
+ />
78
+ ) ;
79
+ } else {
80
+ receiptImageComponent = (
81
+ < View style = { [ styles . w100 , styles . h100 ] } >
82
+ < EReceiptThumbnail transactionID = { transaction . transactionID } />
83
+ </ View >
84
+ ) ;
85
+ }
86
+ } else if ( thumbnail ) {
87
+ receiptImageComponent = (
88
+ < ThumbnailImage
89
+ previewSourceURL = { thumbnailSource }
90
+ style = { [ styles . w100 , styles . h100 ] }
91
+ isAuthTokenRequired
92
+ shouldDynamicallyResize = { false }
93
+ />
94
+ ) ;
95
+ } else {
96
+ receiptImageComponent = (
97
+ < Image
98
+ source = { { uri : image } }
99
+ style = { [ styles . w100 , styles . h100 ] }
100
+ />
101
+ ) ;
102
+ }
54
103
55
104
if ( enablePreviewModal ) {
56
105
return (
@@ -79,4 +128,4 @@ ReportActionItemImage.propTypes = propTypes;
79
128
ReportActionItemImage . defaultProps = defaultProps ;
80
129
ReportActionItemImage . displayName = 'ReportActionItemImage' ;
81
130
82
- export default ReportActionItemImage ;
131
+ export default ReportActionItemImage ;
0 commit comments