Skip to content

Commit

Permalink
Merge pull request #34840 from tobyjsullivan/fix/31859
Browse files Browse the repository at this point in the history
Fix: IOU description can't be seen on the LHN reports
  • Loading branch information
dangrous authored Mar 19, 2024
2 parents d3b894d + defc91c commit 73ecb3f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export default {
splitAmount: ({amount}: SplitAmountParams) => `split ${amount}`,
didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `split ${formattedAmount}${comment ? ` for ${comment}` : ''}`,
amountEach: ({amount}: AmountEachParams) => `${amount} each`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} owes ${amount}`,
payerOwesAmount: ({payer, amount, comment}: PayerOwesAmountParams) => `${payer} owes ${amount}${comment ? ` for ${comment}` : ''}`,
payerOwes: ({payer}: PayerOwesParams) => `${payer} owes: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams): string => `${payer ? `${payer} ` : ''}paid ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} paid: `,
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ export default {
splitAmount: ({amount}: SplitAmountParams) => `dividir ${amount}`,
didSplitAmount: ({formattedAmount, comment}: DidSplitAmountMessageParams) => `dividió ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
amountEach: ({amount}: AmountEachParams) => `${amount} cada uno`,
payerOwesAmount: ({payer, amount}: PayerOwesAmountParams) => `${payer} debe ${amount}`,
payerOwesAmount: ({payer, amount, comment}: PayerOwesAmountParams) => `${payer} debe ${amount}${comment ? ` para ${comment}` : ''}`,
payerOwes: ({payer}: PayerOwesParams) => `${payer} debe: `,
payerPaidAmount: ({payer, amount}: PayerPaidAmountParams) => `${payer ? `${payer} ` : ''}pagó ${amount}`,
payerPaid: ({payer}: PayerPaidParams) => `${payer} pagó: `,
Expand Down
2 changes: 1 addition & 1 deletion src/languages/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type DidSplitAmountMessageParams = {formattedAmount: string; comment: string};

type AmountEachParams = {amount: string};

type PayerOwesAmountParams = {payer: string; amount: number | string};
type PayerOwesAmountParams = {payer: string; amount: number | string; comment?: string};

type PayerOwesParams = {payer: string};

Expand Down
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
ReportUtils.isChatReport(report),
null,
true,
lastReportAction,
);
} else if (ReportActionUtils.isReimbursementQueuedAction(lastReportAction)) {
lastMessageTextFromReport = ReportUtils.getReimbursementQueuedActionMessage(lastReportAction, report);
Expand Down
39 changes: 28 additions & 11 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2414,27 +2414,31 @@ function getTransactionReportName(reportAction: OnyxEntry<ReportAction | Optimis
/**
* Get money request message for an IOU report
*
* @param [reportAction] This can be either a report preview action or the IOU action
* @param [iouReportAction] This is always an IOU action. When necessary, report preview actions will be unwrapped and the child iou report action is passed here (the original report preview
* action will be passed as `originalReportAction` in this case).
* @param [originalReportAction] This can be either a report preview action or the IOU action. This will be the original report preview action in cases where `iouReportAction` was unwrapped
* from a report preview action. Otherwise, it will be the same as `iouReportAction`.
*/
function getReportPreviewMessage(
report: OnyxEntry<Report> | EmptyObject,
reportAction: OnyxEntry<ReportAction> | EmptyObject = {},
iouReportAction: OnyxEntry<ReportAction> | EmptyObject = {},
shouldConsiderScanningReceiptOrPendingRoute = false,
isPreviewMessageForParentChatReport = false,
policy: OnyxEntry<Policy> = null,
isForListPreview = false,
originalReportAction: OnyxEntry<ReportAction> | EmptyObject = iouReportAction,
): string {
const reportActionMessage = reportAction?.message?.[0].html ?? '';
const reportActionMessage = iouReportAction?.message?.[0].html ?? '';

if (isEmptyObject(report) || !report?.reportID) {
// The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled
// As a temporary solution until we know how to solve this the best, we just use the message that returned from BE
return reportActionMessage;
}

if (!isEmptyObject(reportAction) && !isIOUReport(report) && reportAction && ReportActionsUtils.isSplitBillAction(reportAction)) {
if (!isEmptyObject(iouReportAction) && !isIOUReport(report) && iouReportAction && ReportActionsUtils.isSplitBillAction(iouReportAction)) {
// This covers group chats where the last action is a split bill action
const linkedTransaction = getLinkedTransaction(reportAction);
const linkedTransaction = getLinkedTransaction(iouReportAction);
if (isEmptyObject(linkedTransaction)) {
return reportActionMessage;
}
Expand Down Expand Up @@ -2469,8 +2473,8 @@ function getReportPreviewMessage(
}

let linkedTransaction;
if (!isEmptyObject(reportAction) && shouldConsiderScanningReceiptOrPendingRoute && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) {
linkedTransaction = getLinkedTransaction(reportAction);
if (!isEmptyObject(iouReportAction) && shouldConsiderScanningReceiptOrPendingRoute && iouReportAction && ReportActionsUtils.isMoneyRequestAction(iouReportAction)) {
linkedTransaction = getLinkedTransaction(iouReportAction);
}

if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) {
Expand All @@ -2481,7 +2485,7 @@ function getReportPreviewMessage(
return Localize.translateLocal('iou.routePending');
}

const originalMessage = reportAction?.originalMessage as IOUMessage | undefined;
const originalMessage = iouReportAction?.originalMessage as IOUMessage | undefined;

// Show Paid preview message if it's settled or if the amount is paid & stuck at receivers end for only chat reports.
if (isSettled(report.reportID) || (report.isWaitingOnBankAccount && isPreviewMessageForParentChatReport)) {
Expand Down Expand Up @@ -2509,7 +2513,7 @@ function getReportPreviewMessage(
return Localize.translateLocal('iou.waitingOnBankAccount', {submitterDisplayName});
}

const lastActorID = reportAction?.actorAccountID;
const lastActorID = iouReportAction?.actorAccountID;
let amount = originalMessage?.amount;
let currency = originalMessage?.currency ? originalMessage?.currency : report.currency;

Expand All @@ -2518,16 +2522,29 @@ function getReportPreviewMessage(
currency = TransactionUtils.getCurrency(linkedTransaction);
}

if (isEmptyObject(linkedTransaction) && !isEmptyObject(iouReportAction)) {
linkedTransaction = getLinkedTransaction(iouReportAction);
}

let comment = !isEmptyObject(linkedTransaction) ? TransactionUtils.getDescription(linkedTransaction) : undefined;
if (!isEmptyObject(originalReportAction) && ReportActionsUtils.isReportPreviewAction(originalReportAction) && ReportActionsUtils.getNumberOfMoneyRequests(originalReportAction) !== 1) {
comment = undefined;
}

// if we have the amount in the originalMessage and lastActorID, we can use that to display the preview message for the latest request
if (amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) {
const amountToDisplay = CurrencyUtils.convertToDisplayString(Math.abs(amount), currency);

// We only want to show the actor name in the preview if it's not the current user who took the action
const requestorName = lastActorID && lastActorID !== currentUserAccountID ? getDisplayNameForParticipant(lastActorID, !isPreviewMessageForParentChatReport) : '';
return `${requestorName ? `${requestorName}: ` : ''}${Localize.translateLocal('iou.requestedAmount', {formattedAmount: amountToDisplay})}`;
return `${requestorName ? `${requestorName}: ` : ''}${Localize.translateLocal('iou.requestedAmount', {formattedAmount: amountToDisplay, comment})}`;
}

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

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

/**
Expand Down

0 comments on commit 73ecb3f

Please sign in to comment.