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

Fix the incorrect payer name on the non-reimbursable transaction #37773

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,18 @@ function ReportPreview({
if (isScanning) {
return translate('common.receipt');
}
const payerOrApproverName = isPolicyExpenseChat ? ReportUtils.getPolicyName(chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
let payerOrApproverName = isPolicyExpenseChat ? ReportUtils.getPolicyName(chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
if (isApproved) {
return translate('iou.managerApproved', {manager: payerOrApproverName});
}
const managerName = isPolicyExpenseChat && !hasNonReimbursableTransactions ? ReportUtils.getPolicyName(chatReport) : ReportUtils.getDisplayNameForParticipant(managerID, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check !hasNonReimbursableTransactions is not needed here, so that's why I using the previous variable to get the payer name.

let paymentVerb: TranslationPaths = hasNonReimbursableTransactions ? 'iou.payerSpent' : 'iou.payerOwes';
let paymentVerb: TranslationPaths = 'iou.payerOwes';
if (iouSettled || iouReport?.isWaitingOnBankAccount) {
paymentVerb = 'iou.payerPaid';
} else if (hasNonReimbursableTransactions) {
paymentVerb = 'iou.payerSpent';
payerOrApproverName = ReportUtils.getDisplayNameForParticipant(chatReport?.ownerAccountID, true);
}
return translate(paymentVerb, {payer: managerName});
return translate(paymentVerb, {payer: payerOrApproverName});
};

const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
Expand Down
14 changes: 9 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2072,8 +2072,7 @@ function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<

const moneyRequestTotal = getMoneyRequestSpendBreakdown(report).totalDisplaySpend;
const formattedAmount = CurrencyUtils.convertToDisplayString(moneyRequestTotal, report?.currency);
const payerOrApproverName =
isExpenseReport(report) && !hasNonReimbursableTransactions(report?.reportID ?? '') ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? '';
let payerOrApproverName = isExpenseReport(report) ? getPolicyName(report, false, policy) : getDisplayNameForParticipant(report?.managerID) ?? '';
const payerPaidAmountMessage = Localize.translateLocal('iou.payerPaidAmount', {
payer: payerOrApproverName,
amount: formattedAmount,
Expand All @@ -2090,7 +2089,8 @@ function getMoneyRequestReportName(report: OnyxEntry<Report>, policy: OnyxEntry<
return `${payerPaidAmountMessage} • ${Localize.translateLocal('iou.pending')}`;
}

if (hasNonReimbursableTransactions(report?.reportID)) {
if (!isSettled(report?.reportID) && hasNonReimbursableTransactions(report?.reportID)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue I stumbled upon while working on the PR is that after the non-reimbursable transaction is paid and clicking on the report preview, the money report header still shows <name> spent instead of <name> paid.

Screen.Recording.2024-03-05.at.21.33.16.mp4

So adding the check if the transaction paid shows the spent verb.

payerOrApproverName = getDisplayNameForParticipant(report?.ownerAccountID) ?? '';
return Localize.translateLocal('iou.payerSpentAmount', {payer: payerOrApproverName, amount: formattedAmount});
}

Expand Down Expand Up @@ -2374,7 +2374,7 @@ function getReportPreviewMessage(
const containsNonReimbursable = hasNonReimbursableTransactions(report.reportID);
const totalAmount = getMoneyRequestSpendBreakdown(report).totalDisplaySpend;
const policyName = getPolicyName(report, false, policy);
const payerName = isExpenseReport(report) && !containsNonReimbursable ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport);
const payerName = isExpenseReport(report) ? policyName : getDisplayNameForParticipant(report.managerID, !isPreviewMessageForParentChatReport);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • {workspace name} approved $xxx. (this branch)
Screenshot 2024-03-10 at 5 30 01 PM
  • {payer name} approved $xxx. (main)
Screenshot 2024-03-10 at 5 29 31 PM

I think {payer name} was existing bug (regression from #35529) and {workspace name} is correct.
@mollfpr can you confirm?

Copy link
Contributor Author

@mollfpr mollfpr Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe so!

@grgia Do you mind confirming if the above result is correct?


const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency);

Expand Down Expand Up @@ -2444,7 +2444,11 @@ function getReportPreviewMessage(
return `${requestorName ? `${requestorName}: ` : ''}${Localize.translateLocal('iou.requestedAmount', {formattedAmount: amountToDisplay})}`;
}

return Localize.translateLocal(containsNonReimbursable ? 'iou.payerSpentAmount' : 'iou.payerOwesAmount', {payer: payerName ?? '', amount: formattedAmount});
if (containsNonReimbursable) {
return Localize.translateLocal('iou.payerSpentAmount', {payer: getDisplayNameForParticipant(report.ownerAccountID) ?? '', amount: formattedAmount});
}

return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName ?? '', amount: formattedAmount});
}

/**
Expand Down
Loading