Skip to content
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
17 changes: 4 additions & 13 deletions src/hooks/useOutstandingReports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {OnyxEntry} from 'react-native-onyx';
import {getOutstandingReportsForUser, isReportIneligibleForMoveExpenses, isSelfDM} from '@libs/ReportUtils';
import {getOutstandingReportsForUser, isSelfDM} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report} from '@src/types/onyx';
import type {Policy} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import useMappedPolicies from './useMappedPolicies';
import useOnyx from './useOnyx';
Expand All @@ -13,7 +13,6 @@ export default function useOutstandingReports(selectedReportID: string | undefin
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID);
const [allPoliciesID] = useMappedPolicies(policyIdMapper);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [selectedReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`);

Expand All @@ -22,12 +21,6 @@ export default function useOutstandingReports(selectedReportID: string | undefin
return [];
}

const filterEligibleReports = (reports: Array<OnyxEntry<Report>>) =>
reports.filter((report) => {
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
return !isReportIneligibleForMoveExpenses(report, policy);
});

if (!selectedPolicyID || selectedPolicyID === personalPolicyID || isSelfDM(selectedReport)) {
const result = [];
for (const policyID of Object.values(allPoliciesID ?? {})) {
Expand All @@ -38,10 +31,8 @@ export default function useOutstandingReports(selectedReportID: string | undefin
const reports = getOutstandingReportsForUser(policyID, ownerAccountID, outstandingReportsByPolicyID[policyID] ?? {}, reportNameValuePairs, isEditing);
result.push(...reports);
}
return filterEligibleReports(result);
return result;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Filter ineligible reports from move-expense destinations

Returning result directly here reintroduces reports that isReportIneligibleForMoveExpenses() marks as invalid (instant-submit + submit-and-close workspaces with only non-reimbursable transactions). In this state, those reports can be shown as selectable move targets in the report picker, but moving expenses into them fails server-side (403), so users hit a broken flow after selecting an option that should have been excluded; the same unfiltered return was also reintroduced in the selected-policy branch below.

Useful? React with 👍 / 👎.

}

return filterEligibleReports(
getOutstandingReportsForUser(selectedPolicyID, ownerAccountID, outstandingReportsByPolicyID?.[selectedPolicyID ?? CONST.DEFAULT_NUMBER_ID] ?? {}, reportNameValuePairs, isEditing),
);
return getOutstandingReportsForUser(selectedPolicyID, ownerAccountID, outstandingReportsByPolicyID?.[selectedPolicyID ?? CONST.DEFAULT_NUMBER_ID] ?? {}, reportNameValuePairs, isEditing);
}
190 changes: 0 additions & 190 deletions tests/unit/hooks/useOutstandingReports.test.ts

This file was deleted.

Loading