diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index fe53a7bcd5ce..eeb5ed5c1889 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -778,6 +778,13 @@ function isDeletedPolicyEmployee(policyEmployee: PolicyEmployee, isOffline: bool return !isOffline && policyEmployee.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isEmptyObject(policyEmployee.errors); } +function hasNoPolicyOtherThanPersonalType() { + return ( + Object.values(allPolicies ?? {}).filter((policy) => policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) + .length === 0 + ); +} + export { canEditTaxRate, extractPolicyIDFromPath, @@ -861,6 +868,7 @@ export { getNameFromNetSuiteCustomField, isNetSuiteCustomFieldPropertyEditable, getCurrentSageIntacctEntityName, + hasNoPolicyOtherThanPersonalType, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index a2f7d96c6043..a3b05e06f274 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -145,6 +145,7 @@ function IOURequestStepCategory({ IOU.setMoneyRequestCategory(transactionID, updatedCategory); if (action === CONST.IOU.ACTION.CATEGORIZE) { + Navigation.goBack(); Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CONFIRMATION.getRoute(action, iouType, transactionID, report?.reportID ?? '-1')); return; } diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index af808f4a3040..88c6a675e3d1 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -21,6 +21,7 @@ import * as IOUUtils from '@libs/IOUUtils'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportUtils from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; import * as TransactionUtils from '@libs/TransactionUtils'; @@ -36,8 +37,8 @@ import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; import type {Receipt} from '@src/types/onyx/Transaction'; import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; -import withWritableReportOrNotFound from './withWritableReportOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; +import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepConfirmationOnyxProps = { /** The policy of the report */ @@ -192,6 +193,12 @@ function IOURequestStepConfirmation({ }, [transactionID, requestType, defaultCategory]); const navigateBack = useCallback(() => { + // If the action is categorize and there's no policies other than personal one, we simply call goBack(), i.e: dismiss the whole flow together + // We don't need to subscribe to policy_ collection as we only need to check on the latest collection value + if (action === CONST.IOU.ACTION.CATEGORIZE && PolicyUtils.hasNoPolicyOtherThanPersonalType()) { + Navigation.goBack(); + return; + } // If there is not a report attached to the IOU with a reportID, then the participants were manually selected and the user needs taken // back to the participants step if (!transaction?.participantsAutoAssigned) {