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 approve report partially shows wrong owes amount in LHN #49279

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio

const iouReportIDOfLastAction = OptionsListUtils.getIOUReportIDOfLastAction(itemFullReport);
const itemIouReportReportActions = iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined;
const itemIouReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${iouReportIDOfLastAction}`];

const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`];
const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction)
Expand Down Expand Up @@ -162,7 +163,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
}
: null;
}
const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(itemFullReport, lastActorDetails, itemPolicy);
const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(itemFullReport, itemIouReport, lastActorDetails, itemPolicy);

return (
<OptionRowLHNData
Expand All @@ -171,6 +172,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
reportActions={itemReportActions}
parentReportAction={itemParentReportAction}
iouReportReportActions={itemIouReportReportActions}
iouReport={itemIouReport}
policy={itemPolicy}
invoiceReceiverPolicy={itemInvoiceReceiverPolicy}
personalDetails={personalDetails ?? {}}
Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function OptionRowLHNData({
receiptTransactions,
parentReportAction,
iouReportReportActions,
iouReport,
transaction,
lastReportActionTransaction,
transactionViolations,
Expand All @@ -44,6 +45,7 @@ function OptionRowLHNData({
// Note: ideally we'd have this as a dependent selector in onyx!
const item = SidebarUtils.getOptionData({
report: fullReport,
iouReport,
reportActions,
personalDetails,
preferredLocale: preferredLocale ?? CONST.LOCALES.DEFAULT,
Expand All @@ -66,6 +68,7 @@ function OptionRowLHNData({
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [
fullReport,
iouReport,
lastReportActionTransaction,
reportActions,
personalDetails,
Expand Down
3 changes: 3 additions & 0 deletions src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type OptionRowLHNDataProps = {
*/
iouReportReportActions: OnyxEntry<ReportActions>;

/** IOU report related to the last action of this report */
iouReport: OnyxEntry<Report>;

/** List of transaction violation */
transactionViolations: OnyxCollection<TransactionViolation[]>;

Expand Down
10 changes: 5 additions & 5 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function getIOUReportIDOfLastAction(report: OnyxEntry<Report>): string | undefin
/**
* Get the last message text from the report directly or from other sources for special cases.
*/
function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>): string {
function getLastMessageTextForReport(report: OnyxEntry<Report>, iouReport: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null, policy?: OnyxEntry<Policy>): string {
const reportID = report?.reportID ?? '-1';
const lastReportAction = lastVisibleReportActions[reportID] ?? null;

Expand Down Expand Up @@ -623,15 +623,15 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
const properSchemaForMoneyRequestMessage = ReportUtils.getReportPreviewMessage(report, lastReportAction, true, false, null, true);
lastMessageTextFromReport = ReportUtils.formatReportLastMessageText(properSchemaForMoneyRequestMessage);
} else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) {
const iouReport = ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));
const lastIOUMoneyReportAction = allSortedReportActions[iouReport?.reportID ?? '-1']?.find(
const iouReportValue = iouReport ?? ReportUtils.getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction));
const lastIOUMoneyReportAction = allSortedReportActions[iouReportValue?.reportID ?? '-1']?.find(
(reportAction, key): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> =>
ReportActionUtils.shouldReportActionBeVisible(reportAction, key) &&
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE &&
ReportActionUtils.isMoneyRequestAction(reportAction),
);
const reportPreviewMessage = ReportUtils.getReportPreviewMessage(
!isEmptyObject(iouReport) ? iouReport : null,
!isEmptyObject(iouReportValue) ? iouReportValue : null,
lastIOUMoneyReportAction,
true,
ReportUtils.isChatReport(report),
Expand Down Expand Up @@ -766,7 +766,7 @@ function createOption(

const lastActorDetails = personalDetailMap[report.lastActorAccountID ?? -1] ?? null;
const lastActorDisplayName = getLastActorDisplayName(lastActorDetails, hasMultipleParticipants);
const lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails);
const lastMessageTextFromReport = getLastMessageTextForReport(report, undefined, lastActorDetails);
let lastMessageText = lastMessageTextFromReport;

const lastAction = lastVisibleReportActions[report.reportID];
Expand Down
4 changes: 3 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function getOrderedReportIDs(
*/
function getOptionData({
report,
iouReport,
reportActions,
personalDetails,
preferredLocale,
Expand All @@ -245,6 +246,7 @@ function getOptionData({
invoiceReceiverPolicy,
}: {
report: OnyxEntry<Report>;
iouReport: OnyxEntry<Report>;
reportActions: OnyxEntry<ReportActions>;
personalDetails: OnyxEntry<PersonalDetailsList>;
preferredLocale: DeepValueOf<typeof CONST.LOCALES>;
Expand Down Expand Up @@ -389,7 +391,7 @@ function getOptionData({

let lastMessageTextFromReport = lastMessageTextFromReportProp;
if (!lastMessageTextFromReport) {
lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, lastActorDetails, policy);
lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, iouReport, lastActorDetails, policy);
}

// We need to remove sms domain in case the last message text has a phone number mention with sms domain.
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6440,11 +6440,12 @@ function getReportFromHoldRequestsOnyxData(
const firstHoldTransaction = holdTransactions[0];
const newParentReportActionID = rand64();

const holdTotal = iouReport.total && iouReport.unheldTotal ? iouReport.total - iouReport.unheldTotal : 0;
const optimisticExpenseReport = ReportUtils.buildOptimisticExpenseReport(
chatReport.reportID,
chatReport.policyID ?? iouReport.policyID ?? '',
recipient.accountID ?? 1,
(firstHoldTransaction?.amount ?? 0) * -1,
holdTotal * -1,
getCurrency(firstHoldTransaction),
false,
newParentReportActionID,
Expand Down Expand Up @@ -7044,6 +7045,7 @@ function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?:
key: `${ONYXKEYS.COLLECTION.REPORT}${expenseReport?.reportID}`,
value: {
...expenseReport,
total,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

But let's not update the total, as that total is meant for the total that was approved and not for what's left as total to be paid.

@s77rt I still don't understand this comment, can you explain more?

lastMessageText: ReportActionsUtils.getReportActionText(optimisticApprovedReportAction),
lastMessageHtml: ReportActionsUtils.getReportActionHtml(optimisticApprovedReportAction),
stateNum: predictedNextState,
Expand Down
Loading