Skip to content

Commit

Permalink
Merge pull request Expensify#30747 from pradeepmdk/fix/27680-failed-l…
Browse files Browse the repository at this point in the history
…oad-pdf

Scan - Failed to load PDF file uploaded in request money scan
  • Loading branch information
Gonals authored Nov 14, 2023
2 parents 4bd53b8 + ad1ee15 commit 62e437b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
<ReportActionItemImage
thumbnail={receiptURIs.thumbnail}
image={receiptURIs.image}
isLocalFile={receiptURIs.isLocalFile}
transaction={transaction}
enablePreviewModal
/>
Expand Down
12 changes: 8 additions & 4 deletions src/components/ReportActionItem/ReportActionItemImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ROUTES from '@src/ROUTES';

const propTypes = {
/** thumbnail URI for the image */
thumbnail: PropTypes.string,
thumbnail: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

/** URI for the image or local numeric reference for the image */
image: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
Expand All @@ -28,12 +28,16 @@ const propTypes = {

/* The transaction associated with this image, if any. Passed for handling eReceipts. */
transaction: transactionPropTypes,

/** whether thumbnail is refer the local file or not */
isLocalFile: PropTypes.bool,
};

const defaultProps = {
thumbnail: null,
transaction: {},
enablePreviewModal: false,
isLocalFile: false,
};

/**
Expand All @@ -42,7 +46,7 @@ const defaultProps = {
* and optional preview modal as well.
*/

function ReportActionItemImage({thumbnail, image, enablePreviewModal, transaction}) {
function ReportActionItemImage({thumbnail, image, enablePreviewModal, transaction, isLocalFile}) {
const {translate} = useLocalize();
const imageSource = tryResolveUrlFromApiRoot(image || '');
const thumbnailSource = tryResolveUrlFromApiRoot(thumbnail || '');
Expand All @@ -56,7 +60,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal, transactio
<EReceiptThumbnail transactionID={transaction.transactionID} />
</View>
);
} else if (thumbnail) {
} else if (thumbnail && !isLocalFile) {
receiptImageComponent = (
<ThumbnailImage
previewSourceURL={thumbnailSource}
Expand All @@ -68,7 +72,7 @@ function ReportActionItemImage({thumbnail, image, enablePreviewModal, transactio
} else {
receiptImageComponent = (
<Image
source={{uri: image}}
source={{uri: thumbnail || image}}
style={[styles.w100, styles.h100]}
/>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/ReportActionItemImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const propTypes = {
/** array of image and thumbnail URIs */
images: PropTypes.arrayOf(
PropTypes.shape({
thumbnail: PropTypes.string,
thumbnail: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
image: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
transaction: transactionPropTypes,
}),
Expand Down Expand Up @@ -74,7 +74,7 @@ function ReportActionItemImages({images, size, total, isHovered}) {

return (
<View style={[styles.reportActionItemImages, hoverStyle, heightStyle]}>
{_.map(shownImages, ({thumbnail, image, transaction}, index) => {
{_.map(shownImages, ({thumbnail, image, transaction, isLocalFile}, index) => {
const isLastImage = index === numberOfShownImages - 1;

// Show a border to separate multiple images. Shown to the right for each except the last.
Expand All @@ -88,6 +88,7 @@ function ReportActionItemImages({images, size, total, isHovered}) {
<ReportActionItemImage
thumbnail={thumbnail}
image={image}
isLocalFile={isLocalFile}
transaction={transaction}
/>
{isLastImage && remaining > 0 && (
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import * as FileUtils from './fileDownload/FileUtils';

type ThumbnailAndImageURI = {
image: ImageSourcePropType | string;
thumbnail: string | null;
thumbnail: ImageSourcePropType | string | null;
transaction?: Transaction;
isLocalFile?: boolean;
};

type FileNameAndExtension = {
Expand Down Expand Up @@ -65,7 +66,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
image = ReceiptSVG;
}

return {thumbnail: null, image};
return {thumbnail: image, image: path, isLocalFile: true};
}

// eslint-disable-next-line import/prefer-default-export
Expand Down

0 comments on commit 62e437b

Please sign in to comment.