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 LHN displays "...owes 0.00" when user receives split request message #46166

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DraftCommentUtils from '@libs/DraftCommentUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -118,6 +119,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`];
const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1'];

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

const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`];
const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction)
? ReportActionsUtils.getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? '-1'
Expand All @@ -141,6 +146,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
fullReport={itemFullReport}
reportActions={itemReportActions}
parentReportAction={itemParentReportAction}
iouReportReportActions={itemIouReportReportActions}
policy={itemPolicy}
personalDetails={personalDetails ?? {}}
transaction={itemTransaction}
Expand Down
2 changes: 2 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function OptionRowLHNData({
policy,
receiptTransactions,
parentReportAction,
iouReportReportActions,
transaction,
lastReportActionTransaction,
transactionViolations,
Expand Down Expand Up @@ -68,6 +69,7 @@ function OptionRowLHNData({
preferredLocale,
policy,
parentReportAction,
iouReportReportActions,
transaction,
transactionViolations,
canUseViolations,
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 @@ -71,6 +71,9 @@ type OptionRowLHNDataProps = {
/** Array of report actions for this report */
reportActions: OnyxEntry<ReportActions>;

/** Array of report actions of IOU report related to this report last action */
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Could you please explain more about why this is needed, so that data displayed in the option item is updated when a new action is pushed, such as display the split amount owed?

iouReportReportActions: OnyxEntry<ReportActions>;

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

Expand Down
15 changes: 15 additions & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,20 @@ function isSearchStringMatchUserDetails(personalDetail: PersonalDetails, searchV
return isSearchStringMatch(searchValue.trim(), memberDetails.toLowerCase());
}

/**
* Get IOU report ID of report last action if the action is report action preview
*/
function getIOUReportIDOfLastAction(report: OnyxEntry<Report>): string | undefined {
if (!report?.reportID) {
return;
}
const lastAction = visibleReportActionItems[report.reportID];
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Can we rename visibleReportActionItems to lastVisibleReportActions? Not a blocker since it's been named that way for a while. You can create a follow up PR for this and tag me for review.

if (!ReportActionUtils.isReportPreviewAction(lastAction)) {
return;
}
return getReportOrDraftReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastAction))?.reportID;
}

/**
* Get the last message text from the report directly or from other sources for special cases.
*/
Expand Down Expand Up @@ -2626,6 +2640,7 @@ export {
isSearchStringMatchUserDetails,
getAllReportErrors,
getPolicyExpenseReportOption,
getIOUReportIDOfLastAction,
getParticipantsOption,
isSearchStringMatch,
shouldOptionShowTooltip,
Expand Down
Loading