From c84fdb3fffb5c5814225ca942fc3b9a51315288b Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 11:44:42 -0600 Subject: [PATCH 1/7] fix report options --- src/components/MoneyRequestConfirmationListFooter.tsx | 3 ++- src/libs/ReportUtils.ts | 7 ++++--- src/pages/iou/request/step/IOURequestStepReport.tsx | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 2e4624066510..d51a11e20080 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -286,8 +286,9 @@ function MoneyRequestConfirmationListFooter({ */ const transactionReport = !!transaction?.reportID && Object.values(allReports ?? {}).find((report) => report?.reportID === transaction.reportID); const policyID = selectedParticipants?.at(0)?.policyID; + const reportOwnerAccountID = selectedParticipants?.at(0)?.accountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const firstOutstandingReport = getOutstandingReports(policyID, allReports ?? {}).at(0); + const firstOutstandingReport = getOutstandingReports(policyID, reportOwnerAccountID, allReports ?? {}).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { reportName = transactionReport.reportName; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dcd4a216f838..90492bdf65ad 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3866,7 +3866,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry } if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) { - return getOutstandingReports(moneyRequestReport?.policyID, allReports ?? {}).length > 0; + return getOutstandingReports(moneyRequestReport?.policyID, moneyRequestReport?.ownerAccountID, allReports ?? {}).length > 0; } return true; @@ -9552,15 +9552,16 @@ function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: stri /** * Get outstanding expense reports for a given policy ID * @param policyID - The policy ID to filter reports by + * @param reportOwnerAccountID - The accountID of the report owner * @param reports - Collection of reports to filter * @returns Array of outstanding expense reports sorted by name */ -function getOutstandingReports(policyID: string | undefined, reports: OnyxCollection = allReports): Array> { +function getOutstandingReports(policyID: string | undefined, reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports): Array> { if (!reports) { return []; } return Object.values(reports) - .filter((report) => isReportOutstanding(report, policyID)) + .filter((report) => isReportOutstanding(report, policyID) && reportOwnerAccountID && report?.ownerAccountID === reportOwnerAccountID) .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 52231de38976..2e9c23014366 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -48,10 +48,10 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const isEditing = action === CONST.IOU.ACTION.EDIT; // We need to get the policyID because it's not defined in the transaction object before we select a report manually. - const policyID = Object.values(allReports ?? {}).find( + const transactionReport = Object.values(allReports ?? {}).find( (report) => report?.reportID === transaction?.reportID || report?.reportID === transaction?.participants?.at(0)?.reportID, - )?.policyID; - const expenseReports = getOutstandingReports(policyID, allReports ?? {}); + ); + const expenseReports = getOutstandingReports(transactionReport?.policyID, transactionReport?.ownerAccountID, allReports ?? {}); const reportOptions: ReportListItem[] = useMemo(() => { if (!allReports) { From 643e3e35630c320af9476ad697b7a05fc90fe3af Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 12:12:17 -0600 Subject: [PATCH 2/7] fix logic --- src/libs/ReportUtils.ts | 2 +- src/pages/iou/request/step/IOURequestStepReport.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 90492bdf65ad..20a8a8ba2dee 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9561,7 +9561,7 @@ function getOutstandingReports(policyID: string | undefined, reportOwnerAccountI return []; } return Object.values(reports) - .filter((report) => isReportOutstanding(report, policyID) && reportOwnerAccountID && report?.ownerAccountID === reportOwnerAccountID) + .filter((report) => isReportOutstanding(report, policyID) && report?.ownerAccountID === reportOwnerAccountID) .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 2e9c23014366..b5239276269d 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -6,6 +6,7 @@ import type {ListItem} from '@components/SelectionList/types'; import UserListItem from '@components/SelectionList/UserListItem'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {changeTransactionsReport, setTransactionReport} from '@libs/actions/Transaction'; import Navigation from '@libs/Navigation/Navigation'; import {getOutstandingReports} from '@libs/ReportUtils'; @@ -33,6 +34,7 @@ type IOURequestStepReportProps = WithWritableReportOrNotFoundProps): OnyxEntry => report && { + ownerAccountID: report.ownerAccountID, reportID: report.reportID, policyID: report.policyID, reportName: report.reportName, @@ -45,14 +47,14 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const {translate} = useLocalize(); const {backTo, action} = route.params; const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (c) => mapOnyxCollectionItems(c, reportSelector), canBeMissing: true}); + const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const isEditing = action === CONST.IOU.ACTION.EDIT; // We need to get the policyID because it's not defined in the transaction object before we select a report manually. const transactionReport = Object.values(allReports ?? {}).find( (report) => report?.reportID === transaction?.reportID || report?.reportID === transaction?.participants?.at(0)?.reportID, ); - const expenseReports = getOutstandingReports(transactionReport?.policyID, transactionReport?.ownerAccountID, allReports ?? {}); - + const expenseReports = getOutstandingReports(transactionReport?.policyID, transactionReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}); const reportOptions: ReportListItem[] = useMemo(() => { if (!allReports) { return []; From 167cd145e6b23668dce96feffc88278bc993fa7c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 12:14:36 -0600 Subject: [PATCH 3/7] rename function --- src/components/MoneyRequestConfirmationListFooter.tsx | 2 +- src/libs/ReportUtils.ts | 4 ++-- src/pages/iou/request/step/IOURequestStepReport.tsx | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index d51a11e20080..c072d734fc0d 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -288,7 +288,7 @@ function MoneyRequestConfirmationListFooter({ const policyID = selectedParticipants?.at(0)?.policyID; const reportOwnerAccountID = selectedParticipants?.at(0)?.accountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const firstOutstandingReport = getOutstandingReports(policyID, reportOwnerAccountID, allReports ?? {}).at(0); + const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { reportName = transactionReport.reportName; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 20a8a8ba2dee..7b5ac73ebbbb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3866,7 +3866,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxInputOrEntry } if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.REPORT) { - return getOutstandingReports(moneyRequestReport?.policyID, moneyRequestReport?.ownerAccountID, allReports ?? {}).length > 0; + return getOutstandingReportsForUser(moneyRequestReport?.policyID, moneyRequestReport?.ownerAccountID, allReports ?? {}).length > 0; } return true; @@ -9556,7 +9556,7 @@ function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: stri * @param reports - Collection of reports to filter * @returns Array of outstanding expense reports sorted by name */ -function getOutstandingReports(policyID: string | undefined, reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports): Array> { +function getOutstandingReportsForUser(policyID: string | undefined, reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports): Array> { if (!reports) { return []; } diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index b5239276269d..999f8dc229dd 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -54,7 +54,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const transactionReport = Object.values(allReports ?? {}).find( (report) => report?.reportID === transaction?.reportID || report?.reportID === transaction?.participants?.at(0)?.reportID, ); - const expenseReports = getOutstandingReports(transactionReport?.policyID, transactionReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}); + const expenseReports = getOutstandingReportsForUser(transactionReport?.policyID, transactionReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}); const reportOptions: ReportListItem[] = useMemo(() => { if (!allReports) { return []; From 60b4a75de6dc79d78154790a911a0d3919777057 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 12:15:10 -0600 Subject: [PATCH 4/7] fix imports --- src/components/MoneyRequestConfirmationListFooter.tsx | 2 +- src/libs/ReportUtils.ts | 2 +- src/pages/iou/request/step/IOURequestStepReport.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index c072d734fc0d..8a16eed8fe0e 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -18,7 +18,7 @@ import {getDestinationForDisplay, getSubratesFields, getSubratesForDisplay, getT import {canSendInvoice, getPerDiemCustomUnit, isMultiLevelTags as isMultiLevelTagsPolicyUtils, isPaidGroupPolicy} from '@libs/PolicyUtils'; import type {ThumbnailAndImageURI} from '@libs/ReceiptUtils'; import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils'; -import {buildOptimisticExpenseReport, getDefaultWorkspaceAvatar, getOutstandingReports, isReportOutstanding, populateOptimisticReportFormula} from '@libs/ReportUtils'; +import {buildOptimisticExpenseReport, getDefaultWorkspaceAvatar, getOutstandingReportsForUser, isReportOutstanding, populateOptimisticReportFormula} from '@libs/ReportUtils'; import {hasEnabledTags} from '@libs/TagsOptionsListUtils'; import { getTagForDisplay, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7b5ac73ebbbb..e4cdb4561f0a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -10839,7 +10839,7 @@ export { getChatListItemReportName, buildOptimisticMovedTransactionAction, populateOptimisticReportFormula, - getOutstandingReports, + getOutstandingReportsForUser, isReportOutstanding, isAllowedToSubmitDraftExpenseReport, }; diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 999f8dc229dd..48c060cb9685 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -9,7 +9,7 @@ import useLocalize from '@hooks/useLocalize'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {changeTransactionsReport, setTransactionReport} from '@libs/actions/Transaction'; import Navigation from '@libs/Navigation/Navigation'; -import {getOutstandingReports} from '@libs/ReportUtils'; +import {getOutstandingReportsForUser} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; From e826dd8c3aa0b7b866b3fe8aab4381d17724e81c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 12:23:39 -0600 Subject: [PATCH 5/7] fix logic on request footer --- src/components/MoneyRequestConfirmationListFooter.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 8a16eed8fe0e..a1d1c7ab462e 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -286,7 +286,7 @@ function MoneyRequestConfirmationListFooter({ */ const transactionReport = !!transaction?.reportID && Object.values(allReports ?? {}).find((report) => report?.reportID === transaction.reportID); const policyID = selectedParticipants?.at(0)?.policyID; - const reportOwnerAccountID = selectedParticipants?.at(0)?.accountID; + const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0); let reportName: string | undefined; From 06abb6060f53a96d3a4efad98ba282eda96b9bf8 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 24 Apr 2025 12:34:21 -0600 Subject: [PATCH 6/7] fix lint --- src/pages/iou/request/step/IOURequestStepReport.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 48c060cb9685..9b40377abaa5 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -4,9 +4,9 @@ import {useOnyx} from 'react-native-onyx'; import SelectionList from '@components/SelectionList'; import type {ListItem} from '@components/SelectionList/types'; import UserListItem from '@components/SelectionList/UserListItem'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useDebouncedState from '@hooks/useDebouncedState'; import useLocalize from '@hooks/useLocalize'; -import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {changeTransactionsReport, setTransactionReport} from '@libs/actions/Transaction'; import Navigation from '@libs/Navigation/Navigation'; import {getOutstandingReportsForUser} from '@libs/ReportUtils'; @@ -51,9 +51,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const isEditing = action === CONST.IOU.ACTION.EDIT; // We need to get the policyID because it's not defined in the transaction object before we select a report manually. - const transactionReport = Object.values(allReports ?? {}).find( - (report) => report?.reportID === transaction?.reportID || report?.reportID === transaction?.participants?.at(0)?.reportID, - ); + const transactionReport = Object.values(allReports ?? {}).find((report) => report?.reportID === transaction?.reportID || report?.reportID === transaction?.participants?.at(0)?.reportID); const expenseReports = getOutstandingReportsForUser(transactionReport?.policyID, transactionReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}); const reportOptions: ReportListItem[] = useMemo(() => { if (!allReports) { From fcc5d1f55e7123c6a4a22db9b02bc0f36c258d09 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 25 Apr 2025 21:28:03 +0200 Subject: [PATCH 7/7] fix prettier --- src/pages/iou/request/step/IOURequestStepReport.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 854ce739960e..a7d3622e6b5f 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -51,7 +51,9 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); const isEditing = action === CONST.IOU.ACTION.EDIT; // We need to get the policyID because it's not defined in the transaction object before we select a report manually. - const transactionReport = Object.values(allReports ?? {}).find((report) => report?.reportID === transaction?.reportID || (transaction?.participants && report?.reportID === transaction?.participants?.at(0)?.reportID)); + const transactionReport = Object.values(allReports ?? {}).find( + (report) => report?.reportID === transaction?.reportID || (transaction?.participants && report?.reportID === transaction?.participants?.at(0)?.reportID), + ); const expenseReports = getOutstandingReportsForUser(transactionReport?.policyID, transactionReport?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}); const reportOptions: ReportListItem[] = useMemo(() => { if (!allReports) {