diff --git a/src/libs/actions/Policy/Category.ts b/src/libs/actions/Policy/Category.ts index 186cd4672d03..e15ff94326dd 100644 --- a/src/libs/actions/Policy/Category.ts +++ b/src/libs/actions/Policy/Category.ts @@ -946,7 +946,7 @@ function deleteWorkspaceCategories(policyID: string, categoryNamesToDelete: stri API.write(WRITE_COMMANDS.DELETE_WORKSPACE_CATEGORIES, parameters, onyxData); } -function enablePolicyCategories(policyID: string, enabled: boolean) { +function enablePolicyCategories(policyID: string, enabled: boolean, shouldNavigate = true) { const onyxUpdatesToDisableCategories: OnyxUpdate[] = []; if (!enabled) { onyxUpdatesToDisableCategories.push( @@ -1017,7 +1017,7 @@ function enablePolicyCategories(policyID: string, enabled: boolean) { API.write(WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, parameters, onyxData); - if (enabled && getIsNarrowLayout()) { + if (enabled && getIsNarrowLayout() && shouldNavigate) { navigateWhenEnableFeature(policyID); } } diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index 10c10f932aee..6f81d6ea3443 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -1,6 +1,6 @@ import lodashIsEmpty from 'lodash/isEmpty'; import React, {useEffect} from 'react'; -import {ActivityIndicator, View} from 'react-native'; +import {ActivityIndicator, InteractionManager, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; import Button from '@components/Button'; @@ -167,14 +167,19 @@ function IOURequestStepCategory({ large success style={[styles.w100]} - onPress={() => - Navigation.navigate( - ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute( - policy?.id ?? '-1', - ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, report?.reportID ?? '-1', backTo, reportActionID), - ), - ) - } + onPress={() => { + if (!policy?.areCategoriesEnabled) { + Category.enablePolicyCategories(policy?.id ?? '-1', true, false); + } + InteractionManager.runAfterInteractions(() => { + Navigation.navigate( + ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute( + policy?.id ?? '-1', + ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, iouType, transactionID, report?.reportID ?? '-1', backTo, reportActionID), + ), + ); + }); + }} text={translate('workspace.categories.editCategories')} pressOnEnter /> diff --git a/src/pages/iou/request/step/IOURequestStepUpgrade.tsx b/src/pages/iou/request/step/IOURequestStepUpgrade.tsx index 0bf0b679998e..9b93036f1786 100644 --- a/src/pages/iou/request/step/IOURequestStepUpgrade.tsx +++ b/src/pages/iou/request/step/IOURequestStepUpgrade.tsx @@ -56,6 +56,7 @@ function IOURequestStepUpgrade({ searchText: policyDataRef.current?.policyName, }, ]); + Navigation.goBack(); Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_CATEGORY.getRoute(action, CONST.IOU.TYPE.SUBMIT, transactionID, policyDataRef.current?.expenseChatReportID ?? '-1')); }} policyName=""