From d156bd7360a0e94a8913f9648209e29d1bc745a0 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 22 May 2025 22:10:08 +0700 Subject: [PATCH 01/17] fix: show correct report field --- .../MoneyRequestConfirmationListFooter.tsx | 3 ++- src/libs/ReportUtils.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 15b5cf32d0bd..9a6f523fd592 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -288,7 +288,8 @@ function MoneyRequestConfirmationListFooter({ const policyID = selectedParticipants?.at(0)?.policyID; const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0); + const shouldAllowProcessingReport = !isPolicyExpenseChat || action !== CONST.IOU.ACTION.CREATE; + const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, shouldAllowProcessingReport).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { reportName = transactionReport.reportName; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ce3e63e81637..c3916995449c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9626,7 +9626,7 @@ function hasForwardedAction(reportID: string): boolean { return Object.values(reportActions).some((action) => action?.actionName === CONST.REPORT.ACTIONS.TYPE.FORWARDED); } -function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: string | undefined): boolean { +function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: string | undefined, allowSubmitted = true): boolean { if (!iouReport || isEmptyObject(iouReport)) { return false; } @@ -9635,8 +9635,8 @@ function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: stri iouReport?.stateNum !== undefined && iouReport?.statusNum !== undefined && iouReport?.policyID === policyID && - iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED && - iouReport?.statusNum <= CONST.REPORT.STATUS_NUM.SUBMITTED && + (allowSubmitted ? iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.stateNum < CONST.REPORT.STATE_NUM.SUBMITTED) && + (allowSubmitted ? iouReport?.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.statusNum < CONST.REPORT.STATE_NUM.SUBMITTED) && !hasForwardedAction(iouReport.reportID) ); } @@ -9646,14 +9646,20 @@ function isReportOutstanding(iouReport: OnyxInputOrEntry, policyID: stri * @param policyID - The policy ID to filter reports by * @param reportOwnerAccountID - The accountID of the report owner * @param reports - Collection of reports to filter + * @param allowSubmitted - Whether to include submitted reports * @returns Array of outstanding expense reports sorted by name */ -function getOutstandingReportsForUser(policyID: string | undefined, reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports): Array> { +function getOutstandingReportsForUser( + policyID: string | undefined, + reportOwnerAccountID: number | undefined, + reports: OnyxCollection = allReports, + allowSubmitted = true, +): Array> { if (!reports) { return []; } return Object.values(reports) - .filter((report) => isReportOutstanding(report, policyID) && report?.ownerAccountID === reportOwnerAccountID) + .filter((report) => isReportOutstanding(report, policyID, allowSubmitted) && report?.ownerAccountID === reportOwnerAccountID) .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } From 21964e82183d3315cde229931b7c5463bea8d84b Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 22 May 2025 22:17:39 +0700 Subject: [PATCH 02/17] fix: correct logics --- src/components/MoneyRequestConfirmationListFooter.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 9a6f523fd592..db2348f66852 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -288,8 +288,7 @@ function MoneyRequestConfirmationListFooter({ const policyID = selectedParticipants?.at(0)?.policyID; const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const shouldAllowProcessingReport = !isPolicyExpenseChat || action !== CONST.IOU.ACTION.CREATE; - const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, shouldAllowProcessingReport).at(0); + const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, false).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { reportName = transactionReport.reportName; From 06ccc922b90dddb5ee65c6c1697216c322a87c3f Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 27 May 2025 16:17:25 +0700 Subject: [PATCH 03/17] refactor: rename param --- src/libs/ReportUtils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 17bbbb434e74..36fbc46f64d5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9691,7 +9691,7 @@ function isReportOutstanding( iouReport: OnyxInputOrEntry, policyID: string | undefined, reportNameValuePairs: OnyxCollection = allReportNameValuePair, - allowSubmitted = true, + shouldAllowSubmittedReport = true, ): boolean { if (!iouReport || isEmptyObject(iouReport)) { return false; @@ -9702,8 +9702,8 @@ function isReportOutstanding( iouReport?.stateNum !== undefined && iouReport?.statusNum !== undefined && iouReport?.policyID === policyID && - (allowSubmitted ? iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.stateNum < CONST.REPORT.STATE_NUM.SUBMITTED) && - (allowSubmitted ? iouReport?.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.statusNum < CONST.REPORT.STATE_NUM.SUBMITTED) && + (shouldAllowSubmittedReport ? iouReport?.stateNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.stateNum < CONST.REPORT.STATE_NUM.SUBMITTED) && + (shouldAllowSubmittedReport ? iouReport?.statusNum <= CONST.REPORT.STATE_NUM.SUBMITTED : iouReport?.statusNum < CONST.REPORT.STATE_NUM.SUBMITTED) && !hasForwardedAction(iouReport.reportID) && !isArchivedReport(reportNameValuePair) ); @@ -9714,7 +9714,7 @@ function isReportOutstanding( * @param policyID - The policy ID to filter reports by * @param reportOwnerAccountID - The accountID of the report owner * @param reports - Collection of reports to filter - * @param allowSubmitted - Whether to include submitted reports + * @param shouldAllowSubmittedReport - Whether to include submitted reports * @returns Array of outstanding expense reports sorted by name */ function getOutstandingReportsForUser( @@ -9722,13 +9722,13 @@ function getOutstandingReportsForUser( reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports, reportNameValuePairs: OnyxCollection = allReportNameValuePair, - allowSubmitted = true, + shouldAllowSubmittedReport = true, ): Array> { if (!reports) { return []; } return Object.values(reports) - .filter((report) => isReportOutstanding(report, policyID, reportNameValuePairs, allowSubmitted) && report?.ownerAccountID === reportOwnerAccountID) + .filter((report) => isReportOutstanding(report, policyID, reportNameValuePairs, shouldAllowSubmittedReport) && report?.ownerAccountID === reportOwnerAccountID) .sort((a, b) => a?.reportName?.localeCompare(b?.reportName?.toLowerCase() ?? '') ?? 0); } From e8efeceb38a2bc29f936966267d50a90d8fdbf53 Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 28 May 2025 21:45:12 +0700 Subject: [PATCH 04/17] fix: show report for instant submit policy only --- src/components/MoneyRequestConfirmationListFooter.tsx | 4 ++-- src/libs/Permissions.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index d28c0dcb438e..0f0c2d0cff1d 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -16,7 +16,7 @@ import DistanceRequestUtils from '@libs/DistanceRequestUtils'; import Navigation from '@libs/Navigation/Navigation'; import {hasEnabledOptions} from '@libs/OptionsListUtils'; import {getDestinationForDisplay, getSubratesFields, getSubratesForDisplay, getTimeDifferenceIntervals, getTimeForDisplay} from '@libs/PerDiemRequestUtils'; -import {canSendInvoice, getPerDiemCustomUnit, isMultiLevelTags as isMultiLevelTagsPolicyUtils, isPaidGroupPolicy} from '@libs/PolicyUtils'; +import {canSendInvoice, getPerDiemCustomUnit, isInstantSubmitEnabled, isMultiLevelTags as isMultiLevelTagsPolicyUtils, isPaidGroupPolicy} from '@libs/PolicyUtils'; import type {ThumbnailAndImageURI} from '@libs/ReceiptUtils'; import {getThumbnailAndImageURIs} from '@libs/ReceiptUtils'; import {buildOptimisticExpenseReport, getDefaultWorkspaceAvatar, getOutstandingReportsForUser, isReportOutstanding, populateOptimisticReportFormula} from '@libs/ReportUtils'; @@ -289,7 +289,7 @@ function MoneyRequestConfirmationListFooter({ const policyID = selectedParticipants?.at(0)?.policyID; const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const outstandingReports = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, false); + const outstandingReports = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, isInstantSubmitEnabled(policy)); const firstOutstandingReport = outstandingReports.at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index 24eefbc3de8c..d022e904415d 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return !!betas?.includes(CONST.BETAS.ALL); + return true || !!betas?.includes(CONST.BETAS.ALL); } function canUseDefaultRooms(betas: OnyxEntry): boolean { From 2af2aa32d1cadd0944a2ed84c04bad07bc51addf Mon Sep 17 00:00:00 2001 From: daledah Date: Wed, 28 May 2025 21:50:55 +0700 Subject: [PATCH 05/17] fix: revert changes --- src/libs/Permissions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Permissions.ts b/src/libs/Permissions.ts index d022e904415d..24eefbc3de8c 100644 --- a/src/libs/Permissions.ts +++ b/src/libs/Permissions.ts @@ -3,7 +3,7 @@ import CONST from '@src/CONST'; import type Beta from '@src/types/onyx/Beta'; function canUseAllBetas(betas: OnyxEntry): boolean { - return true || !!betas?.includes(CONST.BETAS.ALL); + return !!betas?.includes(CONST.BETAS.ALL); } function canUseDefaultRooms(betas: OnyxEntry): boolean { From efa2d20bae75dee32d259b7e6751a677a2fbd263 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 7 Jul 2025 16:04:06 +0700 Subject: [PATCH 06/17] fix: allow submitted report selection for processing reports --- src/libs/Navigation/Navigation.ts | 2 ++ src/libs/ReportUtils.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index ea3585a24ff9..0af0017bb7c3 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -106,6 +106,8 @@ function canNavigate(methodName: string, params: CanNavigateParams = {}): boolea */ const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; +window.getReportID = getTopmostReportId; + /** * Extracts from the topmost report its action id. */ diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 96dc64cdf42b..711ea1e1b795 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9957,9 +9957,11 @@ function isReportOutstanding( if (!iouReport || isEmptyObject(iouReport)) { return false; } + const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${Navigation.getTopmostReportId()}`]; const policy = allPolicies?.[policyID ?? '']; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; - const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy); + const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); + console.log(Navigation.getTopmostReportId(), activeReport, shouldAllowSubmittedReport); return ( isExpenseReport(iouReport) && iouReport?.stateNum !== undefined && From 2ded8812eef6ab8b27b11e964592d430399b992a Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 7 Jul 2025 16:04:27 +0700 Subject: [PATCH 07/17] fix: remove unused --- src/libs/Navigation/Navigation.ts | 2 -- src/libs/ReportUtils.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 0af0017bb7c3..ea3585a24ff9 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -106,8 +106,6 @@ function canNavigate(methodName: string, params: CanNavigateParams = {}): boolea */ const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; -window.getReportID = getTopmostReportId; - /** * Extracts from the topmost report its action id. */ diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 711ea1e1b795..7606621fb124 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9961,7 +9961,6 @@ function isReportOutstanding( const policy = allPolicies?.[policyID ?? '']; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); - console.log(Navigation.getTopmostReportId(), activeReport, shouldAllowSubmittedReport); return ( isExpenseReport(iouReport) && iouReport?.stateNum !== undefined && From b9a41a972d5675fb7c28a339fb4a49ec3182a962 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 7 Jul 2025 16:07:50 +0700 Subject: [PATCH 08/17] fix: lint --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 7606621fb124..aab9994b7143 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9958,7 +9958,7 @@ function isReportOutstanding( return false; } const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${Navigation.getTopmostReportId()}`]; - const policy = allPolicies?.[policyID ?? '']; + const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); return ( From adee10e07e0663806ca2038eb51e1d0fbb291248 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 7 Jul 2025 16:23:39 +0700 Subject: [PATCH 09/17] fix: add test case --- tests/unit/ReportUtilsTest.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 760ea8005f97..20fd62993867 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -104,6 +104,11 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // Be sure to include the mocked permissions library or else the beta tests won't work jest.mock('@libs/Permissions'); +jest.mock('@libs/Navigation/Navigation', () => ({ + setNavigationActionToMicrotaskQueue: jest.fn(), + getTopmostReportId: jest.fn(() => '2'), +})); + const testDate = DateUtils.getDBTime(); const currentUserEmail = 'bjorn@vikings.net'; const currentUserAccountID = 5; @@ -3405,6 +3410,24 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; + expect(isReportOutstanding(report, policy.id)).toBe(false); + }); + it('should return true for submitted reports if top most report ID is processing', async () => { + const report: Report = { + ...createRandomReport(1), + policyID: policy.id, + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + }; + const activeReport: Report = { + ...createRandomReport(2), + policyID: policy.id, + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + }; + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${activeReport.reportID}`, activeReport); expect(isReportOutstanding(report, policy.id)).toBe(true); }); it('should return false for archived report', async () => { From fc529bf6691cdbb62d89ee9a278b60bf31967cde Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 8 Jul 2025 16:29:03 +0700 Subject: [PATCH 10/17] fix: get correct reportID --- src/libs/Navigation/Navigation.ts | 9 ++++++++- src/libs/ReportUtils.ts | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index ea3585a24ff9..a17129e2ee8f 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -33,7 +33,7 @@ import setNavigationActionToMicrotaskQueue from './helpers/setNavigationActionTo import {linkingConfig} from './linkingConfig'; import {SPLIT_TO_SIDEBAR} from './linkingConfig/RELATIONS'; import navigationRef from './navigationRef'; -import type {NavigationPartialRoute, NavigationRoute, NavigationStateRoute, ReportsSplitNavigatorParamList, RootNavigatorParamList, State} from './types'; +import type {MoneyRequestNavigatorParamList, NavigationPartialRoute, NavigationRoute, NavigationStateRoute, ReportsSplitNavigatorParamList, RootNavigatorParamList, State} from './types'; // Routes which are part of the flow to set up 2FA const SET_UP_2FA_ROUTES: Route[] = [ @@ -106,6 +106,12 @@ function canNavigate(methodName: string, params: CanNavigateParams = {}): boolea */ const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; +/** Extracts from the current route its reportID. This function should only be used in: Report Screens, Money Request Screens */ +const getCurrentRouteReportID = () => { + const currentRoute = navigationRef.getCurrentRoute(); + return (currentRoute?.params as MoneyRequestNavigatorParamList[typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION] | ReportsSplitNavigatorParamList[typeof SCREENS.REPORT])?.reportID; +}; + /** * Extracts from the topmost report its action id. */ @@ -686,6 +692,7 @@ export default { replaceWithSplitNavigator, isTopmostRouteModalScreen, isOnboardingFlow, + getCurrentRouteReportID, }; export {navigationRef}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index aab9994b7143..6156f2e61edb 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9957,7 +9957,7 @@ function isReportOutstanding( if (!iouReport || isEmptyObject(iouReport)) { return false; } - const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${Navigation.getTopmostReportId()}`]; + const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${Navigation.getCurrentRouteReportID()}`]; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); From db06b9103205b845686e763f8c58fd2f6cf0c24d Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 8 Jul 2025 16:58:12 +0700 Subject: [PATCH 11/17] fix: test --- tests/unit/ReportUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 20fd62993867..a93aa05754c9 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -106,7 +106,7 @@ jest.mock('@libs/Permissions'); jest.mock('@libs/Navigation/Navigation', () => ({ setNavigationActionToMicrotaskQueue: jest.fn(), - getTopmostReportId: jest.fn(() => '2'), + getCurrentRouteReportID: jest.fn(() => '2'), })); const testDate = DateUtils.getDBTime(); From bf201dc6f58d1c726589f25d8f52fc42cc1590c0 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 11 Jul 2025 00:12:36 +0700 Subject: [PATCH 12/17] fix: apply suggestions --- src/libs/Navigation/Navigation.ts | 9 +-------- src/libs/ReportUtils.ts | 5 ++++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libs/Navigation/Navigation.ts b/src/libs/Navigation/Navigation.ts index 26435b61aa1b..50d8a683f685 100644 --- a/src/libs/Navigation/Navigation.ts +++ b/src/libs/Navigation/Navigation.ts @@ -33,7 +33,7 @@ import setNavigationActionToMicrotaskQueue from './helpers/setNavigationActionTo import {linkingConfig} from './linkingConfig'; import {SPLIT_TO_SIDEBAR} from './linkingConfig/RELATIONS'; import navigationRef from './navigationRef'; -import type {MoneyRequestNavigatorParamList, NavigationPartialRoute, NavigationRoute, NavigationStateRoute, ReportsSplitNavigatorParamList, RootNavigatorParamList, State} from './types'; +import type {NavigationPartialRoute, NavigationRoute, NavigationStateRoute, ReportsSplitNavigatorParamList, RootNavigatorParamList, State} from './types'; // Routes which are part of the flow to set up 2FA const SET_UP_2FA_ROUTES: Route[] = [ @@ -106,12 +106,6 @@ function canNavigate(methodName: string, params: CanNavigateParams = {}): boolea */ const getTopmostReportId = (state = navigationRef.getState()) => getTopmostReportParams(state)?.reportID; -/** Extracts from the current route its reportID. This function should only be used in: Report Screens, Money Request Screens */ -const getCurrentRouteReportID = () => { - const currentRoute = navigationRef.getCurrentRoute(); - return (currentRoute?.params as MoneyRequestNavigatorParamList[typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION] | ReportsSplitNavigatorParamList[typeof SCREENS.REPORT])?.reportID; -}; - /** * Extracts from the topmost report its action id. */ @@ -691,7 +685,6 @@ export default { replaceWithSplitNavigator, isTopmostRouteModalScreen, isOnboardingFlow, - getCurrentRouteReportID, }; export {navigationRef}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a522530bd514..944724c250fa 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -97,6 +97,7 @@ import getStateFromPath from './Navigation/helpers/getStateFromPath'; import {isFullScreenName} from './Navigation/helpers/isNavigatorName'; import {linkingConfig} from './Navigation/linkingConfig'; import Navigation, {navigationRef} from './Navigation/Navigation'; +import type {MoneyRequestNavigatorParamList, ReportsSplitNavigatorParamList} from './Navigation/types'; import {rand64} from './NumberUtils'; import Parser from './Parser'; import Permissions from './Permissions'; @@ -9960,7 +9961,9 @@ function isReportOutstanding( if (!iouReport || isEmptyObject(iouReport)) { return false; } - const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${Navigation.getCurrentRouteReportID()}`]; + const currentRoute = navigationRef.getCurrentRoute(); + const params = currentRoute?.params as MoneyRequestNavigatorParamList[typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION] | ReportsSplitNavigatorParamList[typeof SCREENS.REPORT]; + const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${params?.reportID}`]; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); From c59c45e5b8ed65f52f595f0aea3367c056c8ce13 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 11 Jul 2025 00:24:10 +0700 Subject: [PATCH 13/17] fix: test --- tests/unit/ReportUtilsTest.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a93aa05754c9..70a53f17b824 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -106,7 +106,13 @@ jest.mock('@libs/Permissions'); jest.mock('@libs/Navigation/Navigation', () => ({ setNavigationActionToMicrotaskQueue: jest.fn(), - getCurrentRouteReportID: jest.fn(() => '2'), + navigationRef: { + getCurrentRoute: jest.fn(() => ({ + params: { + reportID: '2', + }, + })), + }, })); const testDate = DateUtils.getDBTime(); From 9e49657cfa62ce3b95ae1fb8bb1e88f434db5ab7 Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 25 Jul 2025 16:02:31 +0700 Subject: [PATCH 14/17] fix: allow move expense to processing report --- src/libs/ReportUtils.ts | 6 ++++-- src/pages/Search/SearchTransactionsChangeReport.tsx | 1 + src/pages/iou/request/step/IOURequestEditReport.tsx | 4 +++- src/pages/iou/request/step/IOURequestEditReportCommon.tsx | 6 ++++-- src/pages/iou/request/step/IOURequestStepReport.tsx | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d9de1d6e4ee6..ebacb0483658 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9944,6 +9944,7 @@ function isReportOutstanding( iouReport: OnyxInputOrEntry, policyID: string | undefined, reportNameValuePairs: OnyxCollection = allReportNameValuePair, + allowSubmitted = false, ): boolean { if (!iouReport || isEmptyObject(iouReport)) { return false; @@ -9953,7 +9954,7 @@ function isReportOutstanding( const activeReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${params?.reportID}`]; const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const reportNameValuePair = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${iouReport.reportID}`]; - const shouldAllowSubmittedReport = isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); + const shouldAllowSubmittedReport = allowSubmitted || isInstantSubmitEnabled(policy) || isProcessingReport(activeReport); return ( isExpenseReport(iouReport) && iouReport?.stateNum !== undefined && @@ -9978,12 +9979,13 @@ function getOutstandingReportsForUser( reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports, reportNameValuePairs: OnyxCollection = allReportNameValuePair, + allowSubmitted = false, ): Array> { if (!reports) { return []; } return Object.values(reports) - .filter((report) => isReportOutstanding(report, policyID, reportNameValuePairs) && report?.ownerAccountID === reportOwnerAccountID) + .filter((report) => isReportOutstanding(report, policyID, reportNameValuePairs, allowSubmitted) && report?.ownerAccountID === reportOwnerAccountID) .sort((a, b) => localeCompare(a?.reportName?.toLowerCase() ?? '', b?.reportName?.toLowerCase() ?? '')); } diff --git a/src/pages/Search/SearchTransactionsChangeReport.tsx b/src/pages/Search/SearchTransactionsChangeReport.tsx index 757510af9ace..eda8e985c3f3 100644 --- a/src/pages/Search/SearchTransactionsChangeReport.tsx +++ b/src/pages/Search/SearchTransactionsChangeReport.tsx @@ -45,6 +45,7 @@ function SearchTransactionsChangeReport() { backTo={undefined} transactionsReports={transactionsReports} selectReport={selectReport} + isEditing /> ); } diff --git a/src/pages/iou/request/step/IOURequestEditReport.tsx b/src/pages/iou/request/step/IOURequestEditReport.tsx index 3843f711b2f2..f3c5ce4e7ffa 100644 --- a/src/pages/iou/request/step/IOURequestEditReport.tsx +++ b/src/pages/iou/request/step/IOURequestEditReport.tsx @@ -4,6 +4,7 @@ import type {ListItem} from '@components/SelectionList/types'; import useOnyx from '@hooks/useOnyx'; import {changeTransactionsReport} from '@libs/actions/Transaction'; import Navigation from '@libs/Navigation/Navigation'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import IOURequestEditReportCommon from './IOURequestEditReportCommon'; @@ -18,7 +19,7 @@ type TransactionGroupListItem = ListItem & { type IOURequestEditReportProps = WithWritableReportOrNotFoundProps; function IOURequestEditReport({route}: IOURequestEditReportProps) { - const {backTo, reportID} = route.params; + const {backTo, reportID, action} = route.params; const {selectedTransactionIDs, clearSelectedTransactions} = useSearchContext(); @@ -40,6 +41,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) { backTo={backTo} transactionsReports={transactionReport ? [transactionReport] : []} selectReport={selectReport} + isEditing={action === CONST.IOU.ACTION.EDIT} /> ); } diff --git a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx index ea4a9a6576e1..df4f47b8cd97 100644 --- a/src/pages/iou/request/step/IOURequestEditReportCommon.tsx +++ b/src/pages/iou/request/step/IOURequestEditReportCommon.tsx @@ -42,9 +42,10 @@ type Props = { transactionsReports: Report[]; policyID?: string; selectReport: (item: TransactionGroupListItem) => void; + isEditing?: boolean; }; -function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps}: Props) { +function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, policyID: policyIDFromProps, isEditing}: Props) { const {translate} = useLocalize(); const {options} = useOptionsList(); const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: (reports) => mapOnyxCollectionItems(reports, reportSelector), canBeMissing: true}); @@ -65,10 +66,11 @@ function IOURequestEditReportCommon({backTo, transactionsReports, selectReport, transactionsReports.at(0)?.ownerAccountID ?? currentUserPersonalDetails.accountID, allReports ?? {}, reportNameValuePairs, + isEditing, ); return reports; }), - [allReports, currentUserPersonalDetails.accountID, transactionsReports, allPoliciesID, reportNameValuePairs, policyIDFromProps], + [allReports, currentUserPersonalDetails.accountID, transactionsReports, isEditing, allPoliciesID, reportNameValuePairs, policyIDFromProps], ); const reportOptions: TransactionGroupListItem[] = useMemo(() => { diff --git a/src/pages/iou/request/step/IOURequestStepReport.tsx b/src/pages/iou/request/step/IOURequestStepReport.tsx index 26e8e1e4cb42..c86d4eb7c281 100644 --- a/src/pages/iou/request/step/IOURequestStepReport.tsx +++ b/src/pages/iou/request/step/IOURequestStepReport.tsx @@ -120,6 +120,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) { transactionsReports={transactionReport ? [transactionReport] : []} selectReport={selectReport} policyID={!isEditing && !isFromGlobalCreate ? reportOrDraftReport?.policyID : undefined} + isEditing={isEditing} /> ); } From 4517fd747e7154544986a1b999793278731a1721 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 28 Jul 2025 15:30:58 +0700 Subject: [PATCH 15/17] fix: update allow submission logics --- src/components/MoneyRequestConfirmationListFooter.tsx | 2 +- src/libs/ReportUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index d48245230607..7fcba94850b7 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -295,7 +295,7 @@ function MoneyRequestConfirmationListFooter({ const policyID = selectedParticipants?.at(0)?.policyID; const reportOwnerAccountID = selectedParticipants?.at(0)?.ownerAccountID; const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); - const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}).at(0); + const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, false).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { reportName = transactionReport.reportName; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 170a4e1641bb..9adbbc622e27 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9965,7 +9965,7 @@ function getOutstandingReportsForUser( reportOwnerAccountID: number | undefined, reports: OnyxCollection = allReports, reportNameValuePairs: OnyxCollection = allReportNameValuePair, - allowSubmitted = false, + allowSubmitted = true, ): Array> { if (!reports) { return []; From e3d7b176189ccf52ce38ffdec5c0119659ed0fc1 Mon Sep 17 00:00:00 2001 From: daledah Date: Mon, 28 Jul 2025 19:04:31 +0700 Subject: [PATCH 16/17] fix: change default value --- src/components/MoneyRequestConfirmationListFooter.tsx | 2 +- src/libs/ReportUtils.ts | 2 +- src/pages/iou/request/step/IOURequestStepConfirmation.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index 7fcba94850b7..8d886947d971 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -294,7 +294,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)?.ownerAccountID; - const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID); + const shouldUseTransactionReport = !!transactionReport && isReportOutstanding(transactionReport, policyID, undefined, false); const firstOutstandingReport = getOutstandingReportsForUser(policyID, reportOwnerAccountID, allReports ?? {}, undefined, false).at(0); let reportName: string | undefined; if (shouldUseTransactionReport) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9adbbc622e27..44eb6601d34c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9930,7 +9930,7 @@ function isReportOutstanding( iouReport: OnyxInputOrEntry, policyID: string | undefined, reportNameValuePairs: OnyxCollection = allReportNameValuePair, - allowSubmitted = false, + allowSubmitted = true, ): boolean { if (!iouReport || isEmptyObject(iouReport)) { return false; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 9cfa10193dd4..d4316eaae361 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -137,7 +137,7 @@ function IOURequestStepConfirmation({ */ const transactionReport = getReportOrDraftReport(transaction?.reportID); const shouldUseTransactionReport = - transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id); + transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false); const report = shouldUseTransactionReport ? transactionReport : (reportReal ?? reportDraft); const policy = policyReal ?? policyDraft; const isDraftPolicy = policy === policyDraft; From b3ff211ff792cf30003ca8e399f11bbc9e9f031e Mon Sep 17 00:00:00 2001 From: daledah Date: Tue, 29 Jul 2025 18:35:34 +0700 Subject: [PATCH 17/17] fix: test --- tests/unit/ReportUtilsTest.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 3d31ceaf15f1..6ed7e4bac85e 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3704,7 +3704,17 @@ describe('ReportUtils', () => { stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, }; - expect(isReportOutstanding(report, policy.id)).toBe(false); + expect(isReportOutstanding(report, policy.id)).toBe(true); + }); + it('should return false for submitted reports if we specify it', () => { + const report: Report = { + ...createRandomReport(1), + policyID: policy.id, + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + }; + expect(isReportOutstanding(report, policy.id, undefined, false)).toBe(false); }); it('should return true for submitted reports if top most report ID is processing', async () => { const report: Report = {