Skip to content

Commit

Permalink
Merge pull request #25613 from Expensify/andrewli-polishreceipts
Browse files Browse the repository at this point in the history
[CP Staging] Polish displaying receipts in chat
  • Loading branch information
mountiny authored Aug 22, 2023
2 parents 2dbfb4b + 406f293 commit 176748c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function MoneyRequestPreview(props) {
</View>
)}
</View>
{requestMerchant && (
{!_.isEmpty(requestMerchant) && (
<View style={[styles.flexRow]}>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh16]}>{requestMerchant}</Text>
</View>
Expand Down
9 changes: 9 additions & 0 deletions src/components/ReportActionItem/ReportActionItemImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ const defaultProps = {
isHovered: false,
};

/**
* This component displays a row of images in a report action item like a card, such
* as report previews or money request previews which contain receipt images. The maximum of images
* shown in this row is dictated by the size prop, which, if not passed, is just the number of images.
* Otherwise, if size is passed and the number of images is over size, we show a small overlay on the
* last image of how many additional images there are. If passed, total prop can be used to change how this
* additional number when subtracted from size.
*/

function ReportActionItemImages({images, size, total, isHovered}) {
const numberOfShownImages = size || images.length;
const shownImages = images.slice(0, size);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function ReportPreview(props) {
const numberOfRequests = ReportActionUtils.getNumberOfMoneyRequests(props.action);
const moneyRequestComment = lodashGet(props.action, 'childLastMoneyRequestComment', '');

const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReport);
const transactionsWithReceipts = ReportUtils.getTransactionsWithReceipts(props.iouReportID);
const numberOfScanningReceipts = _.filter(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction)).length;
const hasReceipts = transactionsWithReceipts.length > 0;
const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReport, props.action);
const isScanning = hasReceipts && ReportUtils.areAllRequestsBeingSmartScanned(props.iouReportID, props.action);
const lastThreeTransactionsWithReceipts = ReportUtils.getReportPreviewDisplayTransactions(props.action);

const hasOnlyOneReceiptRequest = numberOfRequests === 1 && hasReceipts;
Expand Down
17 changes: 8 additions & 9 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,12 +1253,11 @@ function getTransactionDetails(transaction) {
/**
* Gets all transactions on an IOU report with a receipt
*
* @param {Object|null} iouReport
* @param {Object|null} iouReportID
* @returns {[Object]}
*/
function getTransactionsWithReceipts(iouReport) {
const reportID = lodashGet(iouReport, 'reportID');
const reportActions = ReportActionsUtils.getAllReportActions(reportID);
function getTransactionsWithReceipts(iouReportID) {
const reportActions = ReportActionsUtils.getAllReportActions(iouReportID);
return _.reduce(
reportActions,
(transactions, action) => {
Expand All @@ -1281,17 +1280,17 @@ function getTransactionsWithReceipts(iouReport) {
* or as soon as one receipt request is done scanning, we have at least one
* "ready" money request, and we remove this indicator to show the partial report total.
*
* @param {Object|null} iouReport
* @param {Object|null} iouReportID
* @param {Object|null} reportPreviewAction the preview action associated with the IOU report
* @returns {Boolean}
*/
function areAllRequestsBeingSmartScanned(iouReport, reportPreviewAction) {
const transactions = getTransactionsWithReceipts(iouReport);
function areAllRequestsBeingSmartScanned(iouReportID, reportPreviewAction) {
const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID);
// If we have more requests than requests with receipts, we have some manual requests
if (ReportActionsUtils.getNumberOfMoneyRequests(reportPreviewAction) > transactions.length) {
if (ReportActionsUtils.getNumberOfMoneyRequests(reportPreviewAction) > transactionsWithReceipts.length) {
return false;
}
return _.all(transactions, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction));
return _.all(transactionsWithReceipts, (transaction) => TransactionUtils.isReceiptBeingScanned(transaction));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ function getMoneyRequestInformation(report, participant, comment, amount, curren
optimisticTransaction.transactionID,
'',
iouReport.reportID,
false,
false,
receiptObject,
);

Expand Down

0 comments on commit 176748c

Please sign in to comment.