Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merchant name of the deleted expense in OD report is still shown in ND report #42015

Merged
merged 4 commits into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ function ReportPreview({
return displayAmount;
};

// We're using this function to check if the parsed result of getDisplayAmount equals
// to 0 in order to hide the subtitle (merchant / description) when the expense
// is removed from OD report and display amount changes to 0 (any currency)
function isDisplayAmountZero(displayAmount: string) {
if (!displayAmount || displayAmount === '') {
return false;
}
const numericPart = displayAmount.replace(/[^\d.-]/g, '');
const amount = parseFloat(numericPart);
return !Number.isNaN(amount) && amount === 0;
}

const getPreviewMessage = () => {
if (isScanning) {
return translate('common.receipt');
Expand Down Expand Up @@ -225,7 +237,7 @@ function ReportPreview({
*/
const shouldShowSingleRequestMerchantOrDescription =
numberOfRequests === 1 && (!!formattedMerchant || !!formattedDescription) && !(hasOnlyTransactionsWithPendingRoutes && !totalDisplaySpend);
const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchantOrDescription || numberOfRequests > 1);
const shouldShowSubtitle = !isScanning && (shouldShowSingleRequestMerchantOrDescription || numberOfRequests > 1) && !isDisplayAmountZero(getDisplayAmount());
const shouldShowScanningSubtitle = numberOfScanningReceipts === 1 && numberOfRequests === 1;
const shouldShowPendingSubtitle = numberOfPendingRequests === 1 && numberOfRequests === 1;

Expand Down
Loading