Skip to content

Commit 1716d65

Browse files
authored
Merge pull request Expensify#75907 from callstack-internal/callstack-internal/szymonzalarski/money-request
Optimize getOutstandingReportsForUser function in money request page
2 parents 299d904 + 8f9a9e3 commit 1716d65

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/MoneyRequestConfirmationListFooter.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,15 @@ function MoneyRequestConfirmationListFooter({
323323
const policyID = selectedParticipants?.at(0)?.policyID;
324324
const selectedPolicy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`];
325325
const shouldUseTransactionReport = (!!transactionReport && isReportOutstanding(transactionReport, policyID, undefined, false)) || isUnreported;
326-
const availableOutstandingReports = getOutstandingReportsForUser(policyID, selectedParticipants?.at(0)?.ownerAccountID, allReports, reportNameValuePairs, false).sort((a, b) =>
327-
localeCompare(a?.reportName?.toLowerCase() ?? '', b?.reportName?.toLowerCase() ?? ''),
328-
);
326+
327+
const ownerAccountID = selectedParticipants?.at(0)?.ownerAccountID;
328+
329+
const availableOutstandingReports = useMemo(() => {
330+
return getOutstandingReportsForUser(policyID, ownerAccountID, outstandingReportsByPolicyID?.[policyID ?? CONST.DEFAULT_NUMBER_ID] ?? {}, reportNameValuePairs, false).sort((a, b) =>
331+
localeCompare(a?.reportName?.toLowerCase() ?? '', b?.reportName?.toLowerCase() ?? ''),
332+
);
333+
}, [policyID, ownerAccountID, outstandingReportsByPolicyID, reportNameValuePairs, localeCompare]);
334+
329335
const iouReportID = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.iouReportID;
330336
const outstandingReportID = isPolicyExpenseChat ? (iouReportID ?? availableOutstandingReports.at(0)?.reportID) : reportID;
331337
const [selectedReportID, selectedReport] = useMemo(() => {

0 commit comments

Comments
 (0)