diff --git a/src/components/TaxPicker.tsx b/src/components/TaxPicker.tsx index c62b84911835..fb7ab9ce53c1 100644 --- a/src/components/TaxPicker.tsx +++ b/src/components/TaxPicker.tsx @@ -131,7 +131,7 @@ export default withOnyx({ }, transaction: { key: ({transactionID, action}) => { - if (action === CONST.IOU.ACTION.CREATE || IOUUtils.isMovingTransactionFromTrackExpense(action)) { + if (IOUUtils.shouldUseTransactionDraft(action)) { return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}` as `${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`; } return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`; diff --git a/src/libs/IOUUtils.ts b/src/libs/IOUUtils.ts index d1bf8fcd8c8c..55ac4ba2ac36 100644 --- a/src/libs/IOUUtils.ts +++ b/src/libs/IOUUtils.ts @@ -156,11 +156,16 @@ function isMovingTransactionFromTrackExpense(action?: IOUAction) { return false; } +function shouldUseTransactionDraft(action: IOUAction | undefined) { + return action === CONST.IOU.ACTION.CREATE || isMovingTransactionFromTrackExpense(action); +} + export { calculateAmount, insertTagIntoTransactionTagsString, isIOUReportPendingCurrencyConversion, isMovingTransactionFromTrackExpense, + shouldUseTransactionDraft, isValidMoneyRequestType, navigateToStartMoneyRequestStep, updateIOUOwnerAndTotal, diff --git a/src/pages/iou/request/step/IOURequestStepDate.tsx b/src/pages/iou/request/step/IOURequestStepDate.tsx index fbeec4e97f1f..b5b7b1d02cea 100644 --- a/src/pages/iou/request/step/IOURequestStepDate.tsx +++ b/src/pages/iou/request/step/IOURequestStepDate.tsx @@ -99,7 +99,7 @@ function IOURequestStepDate({ return; } - const isTransactionDraft = action === CONST.IOU.ACTION.CREATE || IOUUtils.isMovingTransactionFromTrackExpense(action); + const isTransactionDraft = IOUUtils.shouldUseTransactionDraft(action); IOU.setMoneyRequestCreated(transaction?.transactionID ?? '-1', newCreated, isTransactionDraft); diff --git a/src/pages/iou/request/step/IOURequestStepDescription.tsx b/src/pages/iou/request/step/IOURequestStepDescription.tsx index 993bf580f038..9b4cb97beba6 100644 --- a/src/pages/iou/request/step/IOURequestStepDescription.tsx +++ b/src/pages/iou/request/step/IOURequestStepDescription.tsx @@ -131,7 +131,7 @@ function IOURequestStepDescription({ navigateBack(); return; } - const isTransactionDraft = action === CONST.IOU.ACTION.CREATE || IOUUtils.isMovingTransactionFromTrackExpense(action); + const isTransactionDraft = IOUUtils.shouldUseTransactionDraft(action); IOU.setMoneyRequestDescription(transaction?.transactionID ?? '-1', newComment, isTransactionDraft); diff --git a/src/pages/iou/request/step/IOURequestStepDistance.tsx b/src/pages/iou/request/step/IOURequestStepDistance.tsx index 868f1752dbbf..9131bc4b3d39 100644 --- a/src/pages/iou/request/step/IOURequestStepDistance.tsx +++ b/src/pages/iou/request/step/IOURequestStepDistance.tsx @@ -20,6 +20,7 @@ import usePrevious from '@hooks/usePrevious'; import useThemeStyles from '@hooks/useThemeStyles'; import DistanceRequestUtils from '@libs/DistanceRequestUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; +import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; @@ -188,7 +189,7 @@ function IOURequestStepDistance({ TransactionEdit.removeBackupTransaction(transaction?.transactionID ?? '-1'); return; } - TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', action === CONST.IOU.ACTION.CREATE); + TransactionEdit.restoreOriginalTransactionFromBackup(transaction?.transactionID ?? '-1', IOUUtils.shouldUseTransactionDraft(action)); }; // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); @@ -383,8 +384,8 @@ function IOURequestStepDistance({ setOptimisticWaypoints(newWaypoints); Promise.all([ - TransactionAction.removeWaypoint(transaction, emptyWaypointIndex.toString(), action === CONST.IOU.ACTION.CREATE), - TransactionAction.updateWaypoints(transactionID, newWaypoints, action === CONST.IOU.ACTION.CREATE), + TransactionAction.removeWaypoint(transaction, emptyWaypointIndex.toString(), IOUUtils.shouldUseTransactionDraft(action)), + TransactionAction.updateWaypoints(transactionID, newWaypoints, IOUUtils.shouldUseTransactionDraft(action)), ]).then(() => { setOptimisticWaypoints(null); }); diff --git a/src/pages/iou/request/step/IOURequestStepWaypoint.tsx b/src/pages/iou/request/step/IOURequestStepWaypoint.tsx index 71c42acefdaa..28dcbfd3094f 100644 --- a/src/pages/iou/request/step/IOURequestStepWaypoint.tsx +++ b/src/pages/iou/request/step/IOURequestStepWaypoint.tsx @@ -21,6 +21,7 @@ import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as ErrorUtils from '@libs/ErrorUtils'; +import * as IOUUtils from '@libs/IOUUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as ValidationUtils from '@libs/ValidationUtils'; import * as Modal from '@userActions/Modal'; @@ -113,13 +114,13 @@ function IOURequestStepWaypoint({ return errors; }; - const saveWaypoint = (waypoint: FormOnyxValues<'waypointForm'>) => Transaction.saveWaypoint(transactionID, pageIndex, waypoint, action === CONST.IOU.ACTION.CREATE); + const saveWaypoint = (waypoint: FormOnyxValues<'waypointForm'>) => Transaction.saveWaypoint(transactionID, pageIndex, waypoint, IOUUtils.shouldUseTransactionDraft(action)); const submit = (values: FormOnyxValues<'waypointForm'>) => { const waypointValue = values[`waypoint${pageIndex}`] ?? ''; // Allows letting you set a waypoint to an empty value if (waypointValue === '') { - Transaction.removeWaypoint(transaction, pageIndex, action === CONST.IOU.ACTION.CREATE); + Transaction.removeWaypoint(transaction, pageIndex, IOUUtils.shouldUseTransactionDraft(action)); } // While the user is offline, the auto-complete address search will not work @@ -140,7 +141,7 @@ function IOURequestStepWaypoint({ }; const deleteStopAndHideModal = () => { - Transaction.removeWaypoint(transaction, pageIndex, action === CONST.IOU.ACTION.CREATE); + Transaction.removeWaypoint(transaction, pageIndex, IOUUtils.shouldUseTransactionDraft(action)); setRestoreFocusType(CONST.MODAL.RESTORE_FOCUS_TYPE.DELETE); setIsDeleteStopModalOpen(false); goBack(); @@ -155,7 +156,7 @@ function IOURequestStepWaypoint({ keyForList: `${values.name ?? 'waypoint'}_${Date.now()}`, }; - Transaction.saveWaypoint(transactionID, pageIndex, waypoint, action === CONST.IOU.ACTION.CREATE); + Transaction.saveWaypoint(transactionID, pageIndex, waypoint, IOUUtils.shouldUseTransactionDraft(action)); goBack(); }; diff --git a/src/pages/iou/request/step/withFullTransactionOrNotFound.tsx b/src/pages/iou/request/step/withFullTransactionOrNotFound.tsx index 9bf454b2c27d..491c37c9a402 100644 --- a/src/pages/iou/request/step/withFullTransactionOrNotFound.tsx +++ b/src/pages/iou/request/step/withFullTransactionOrNotFound.tsx @@ -73,7 +73,7 @@ export default function