From 64b4d99766629925e447a516880a9733f40450e0 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Fri, 5 Dec 2025 22:15:57 +0700 Subject: [PATCH 1/2] fix: user is not redirected to report details --- src/pages/iou/request/step/IOURequestStepCategory.tsx | 8 ++++---- .../iou/request/step/IOURequestStepConfirmation.tsx | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index 775218051a8a6..c8f4a90b9f506 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -27,7 +27,7 @@ import {isCategoryMissing} from '@libs/CategoryUtils'; import Navigation from '@libs/Navigation/Navigation'; import {hasEnabledOptions} from '@libs/OptionsListUtils'; import {isPolicyAdmin} from '@libs/PolicyUtils'; -import {getTransactionDetails, isGroupPolicy, isReportInGroupPolicy} from '@libs/ReportUtils'; +import {getReportOrDraftReport, getTransactionDetails, isGroupPolicy, isReportInGroupPolicy} from '@libs/ReportUtils'; import {isExpenseUnreported} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -57,8 +57,9 @@ function IOURequestStepCategory({ const isUnreportedExpense = isExpenseUnreported(transaction); const {policyForMovingExpenses, policyForMovingExpensesID} = usePolicyForMovingExpenses(); const isCreatingTrackExpense = action === CONST.IOU.ACTION.CREATE && iouType === CONST.IOU.TYPE.TRACK; - - const policyIdReal = getIOURequestPolicyID(transaction, reportReal); + const transactionReport = getReportOrDraftReport(transaction?.reportID); + const report = reportReal ?? reportDraft ?? transactionReport; + const policyIdReal = getIOURequestPolicyID(transaction, reportReal ?? transactionReport); const policyIdDraft = getIOURequestPolicyID(transaction, reportDraft); const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyIdReal}`, {canBeMissing: true}); const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyIdDraft}`, {canBeMissing: true}); @@ -71,7 +72,6 @@ function IOURequestStepCategory({ const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {canBeMissing: true}); const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, {canBeMissing: true}); - const report = reportReal ?? reportDraft; const policyCategories = policyCategoriesReal ?? policyCategoriesDraft; const policyData = usePolicyData(policy?.id); const {currentSearchHash} = useSearchContext(); diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 803ffed597ae9..e7bb69b185734 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -173,8 +173,11 @@ function IOURequestStepConfirmation({ * Also if the report was submitted and delayed submission is on, then we should use an initial report */ const transactionReport = getReportOrDraftReport(transaction?.reportID); + const reportWithDraftFallback = useMemo(() => reportReal ?? reportDraft, [reportDraft, reportReal]); const shouldUseTransactionReport = - transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false); + transactionReport && + ((!(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false)) || + !reportWithDraftFallback); const report = useMemo(() => { if (isUnreported) { return undefined; @@ -182,8 +185,8 @@ function IOURequestStepConfirmation({ if (shouldUseTransactionReport) { return transactionReport; } - return reportReal ?? reportDraft; - }, [isUnreported, shouldUseTransactionReport, transactionReport, reportReal, reportDraft]); + return reportWithDraftFallback; + }, [isUnreported, shouldUseTransactionReport, transactionReport, reportWithDraftFallback]); const policy = isCreatingTrackExpense || isUnreported ? policyForMovingExpenses : (policyReal ?? policyDraft); const policyID = isCreatingTrackExpense || isUnreported ? policyForMovingExpensesID : getIOURequestPolicyID(transaction, report); From d2a26ccfe73548a5cf3b9b60c1e557db5a9a9840 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Tue, 9 Dec 2025 22:39:05 +0700 Subject: [PATCH 2/2] apply suggestions --- .../iou/request/step/IOURequestStepConfirmation.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 39fd05ab74828..40b74084dcc6d 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -170,13 +170,15 @@ function IOURequestStepConfirmation({ /* * We want to use a report from the transaction if it exists * Also if the report was submitted and delayed submission is on, then we should use an initial report + * Additionally, if neither reportReal nor reportDraft exist, we fallback to the transactionReport + * to ensure proper navigation after expense creation. */ const transactionReport = getReportOrDraftReport(transaction?.reportID); const reportWithDraftFallback = useMemo(() => reportReal ?? reportDraft, [reportDraft, reportReal]); - const shouldUseTransactionReport = - transactionReport && - ((!(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false)) || - !reportWithDraftFallback); + const canUseReport = !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false); + + const shouldUseTransactionReport = !!transactionReport && (canUseReport || !reportWithDraftFallback); + const report = useMemo(() => { if (isUnreported) { return undefined;