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
8 changes: 4 additions & 4 deletions src/pages/iou/request/step/IOURequestStepCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

@mkzie2 I noticed 2 potential issues:

  • you memoized this below in IOURequestStepConfirmation.tsx but didn't memoize it here
  • you used transactionReport as 3rd fallback here while not using it in IOURequestStepConfirmation.tsx

mind clarifying / updating (if needed) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ikevin127 In IOURequestStepConfirmation we used it in 2 places so I created reportWithDraftFallback, actually for report, we still use transactionReport as the fallback if reportWithDraftFallback is undefined

https://github.com/Expensify/App/pull/76827/files#diff-5e5fc302dd5db871d26e30f810bc0606beccb7f50ae6ed6535cd93aaee98c280R180

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});
Expand All @@ -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();
Expand Down
13 changes: 9 additions & 4 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,24 @@ 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 shouldUseTransactionReport =
transactionReport && !(isProcessingReport(transactionReport) && !policyReal?.harvesting?.enabled) && isReportOutstanding(transactionReport, policyReal?.id, undefined, false);
const reportWithDraftFallback = useMemo(() => reportReal ?? reportDraft, [reportDraft, reportReal]);
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;
}
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);
Expand Down
Loading