Skip to content

Commit

Permalink
Merge pull request #26611 from pradeepmdk/fix/26585-uri-should-be-string
Browse files Browse the repository at this point in the history
[CP Staging] Fix crash upon Request Preview open
  • Loading branch information
Hayata Suenaga authored Sep 4, 2023
2 parents f85e7ae + 13dd7b1 commit a7dfd6f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/Image/imagePropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const imagePropTypes = {
source: PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
uri: PropTypes.string.isRequired,
uri: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
// eslint-disable-next-line react/forbid-prop-types
headers: PropTypes.object,
}),
Expand Down
5 changes: 4 additions & 1 deletion src/components/Image/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function Image(props) {
const {source, isAuthTokenRequired, session, ...rest} = props;

let imageSource = source;
if (typeof source !== 'number' && isAuthTokenRequired) {
if (source && source.uri && typeof source.uri === 'number') {
imageSource = source.uri;
}
if (typeof imageSource !== 'number' && isAuthTokenRequired) {
const authToken = lodashGet(props, 'session.encryptedAuthToken', null);
imageSource = {
...source,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function MoneyRequestPreview(props) {
<View style={[styles.moneyRequestPreviewBox, isScanning ? styles.reportPreviewBoxHoverBorder : undefined, ...props.containerStyles]}>
{hasReceipt && (
<ReportActionItemImages
images={[ReceiptUtils.getThumbnailAndImageURIs(props.transaction.receipt.source, props.transaction.filename)]}
images={[ReceiptUtils.getThumbnailAndImageURIs(props.transaction.receipt.source, props.transaction.filename || '')]}
isHovered={isScanning}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportActionItemImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const propTypes = {
/** thumbnail URI for the image */
thumbnail: PropTypes.string,

/** URI for the image */
image: PropTypes.string.isRequired,
/** URI for the image or local numeric reference for the image */
image: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,

/** whether or not to enable the image preview modal */
enablePreviewModal: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function ReportPreview(props) {
<View style={[styles.reportPreviewBox, props.isHovered || isScanning ? styles.reportPreviewBoxHoverBorder : undefined]}>
{hasReceipts && (
<ReportActionItemImages
images={_.map(lastThreeTransactionsWithReceipts, ({receipt, filename}) => ReceiptUtils.getThumbnailAndImageURIs(receipt.source, filename))}
images={_.map(lastThreeTransactionsWithReceipts, ({receipt, filename}) => ReceiptUtils.getThumbnailAndImageURIs(receipt.source, filename || ''))}
size={3}
total={transactionsWithReceipts.length}
isHovered={props.isHovered || isScanning}
Expand Down

0 comments on commit a7dfd6f

Please sign in to comment.