@@ -12,15 +12,19 @@ import useHasActiveAdminPolicies from '@hooks/useHasActiveAdminPolicies';
1212import useLocalize from '@hooks/useLocalize' ;
1313import useNetwork from '@hooks/useNetwork' ;
1414import useOnyx from '@hooks/useOnyx' ;
15+ import usePermissions from '@hooks/usePermissions' ;
1516import usePreferredPolicy from '@hooks/usePreferredPolicy' ;
1617import useThemeStyles from '@hooks/useThemeStyles' ;
18+ import { createNewReport } from '@libs/actions/Report' ;
1719import { setTransactionReport } from '@libs/actions/Transaction' ;
1820import type CreateWorkspaceParams from '@libs/API/parameters/CreateWorkspaceParams' ;
1921import getPlatform from '@libs/getPlatform' ;
22+ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute' ;
2023import Navigation from '@libs/Navigation/Navigation' ;
2124import type { PlatformStackScreenProps } from '@libs/Navigation/PlatformStackNavigation/types' ;
2225import type { MoneyRequestNavigatorParamList } from '@libs/Navigation/types' ;
2326import { getParticipantsOption } from '@libs/OptionsListUtils' ;
27+ import { hasViolations as hasViolationsReportUtils } from '@libs/ReportUtils' ;
2428import UpgradeConfirmation from '@pages/workspace/upgrade/UpgradeConfirmation' ;
2529import UpgradeIntro from '@pages/workspace/upgrade/UpgradeIntro' ;
2630import { setCustomUnitRateID , setMoneyRequestParticipants } from '@userActions/IOU' ;
@@ -64,14 +68,21 @@ function IOURequestStepUpgrade({
6468 const [ betas ] = useOnyx ( ONYXKEYS . BETAS ) ;
6569 const [ activePolicyID ] = useOnyx ( ONYXKEYS . NVP_ACTIVE_POLICY_ID ) ;
6670 const [ isSelfTourViewed ] = useOnyx ( ONYXKEYS . NVP_ONBOARDING , { selector : hasSeenTourSelector } ) ;
71+ const [ session ] = useOnyx ( ONYXKEYS . SESSION ) ;
72+ const [ transactionViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS ) ;
73+ const [ createdPolicyID , setCreatedPolicyID ] = useState < string | undefined > ( ) ;
74+ const [ createdPolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ createdPolicyID } ` ) ;
75+ const { isBetaEnabled} = usePermissions ( ) ;
76+ const isASAPSubmitBetaEnabled = isBetaEnabled ( CONST . BETAS . ASAP_SUBMIT ) ;
77+ const hasViolations = hasViolationsReportUtils ( undefined , transactionViolations , session ?. accountID ?? CONST . DEFAULT_NUMBER_ID , session ?. email ?? '' ) ;
6778
6879 const feature = Object . values ( CONST . UPGRADE_FEATURE_INTRO_MAPPING )
6980 . filter ( ( value ) => value . id !== CONST . UPGRADE_FEATURE_INTRO_MAPPING . policyPreventMemberChangingTitle . id )
7081 . find ( ( f ) => f . alias === upgradePath ) ;
7182
7283 const navigateWithMicrotask = ( route : Route ) => {
7384 if ( isWeb ) {
74- Navigation . setNavigationActionToMicrotaskQueue ( ( ) => Navigation . navigate ( route ) ) ;
85+ Navigation . setNavigationActionToMicrotaskQueue ( ( ) => Navigation . navigate ( route ) ) ;
7586 } else {
7687 Navigation . navigate ( route ) ;
7788 }
@@ -114,16 +125,25 @@ function IOURequestStepUpgrade({
114125 navigateWithMicrotask ( ROUTES . WORKSPACE_CREATE_DISTANCE_RATE_UPGRADE . getRoute ( policyID , transactionID , expenseReportID ) ) ;
115126 break ;
116127 }
117- case CONST . UPGRADE_PATHS . REPORTS :
128+ case CONST . UPGRADE_PATHS . REPORTS : {
118129 Navigation . goBack ( ) ;
119- if ( action === CONST . IOU . ACTION . CREATE ) {
120- // Coming from "Create report" button (no workspace) → go to workspace selection which creates the report
130+ if ( action === CONST . IOU . ACTION . CREATE && policyID ) {
131+ // Create the report directly using the just-created workspace instead of
132+ // navigating to workspace selection (which would redundantly ask the user
133+ // to pick the single workspace they just created).
134+ const { reportID : createdReportID } = createNewReport ( currentUserPersonalDetails , hasViolations , isASAPSubmitBetaEnabled , createdPolicy , betas ) ;
135+ navigateWithMicrotask (
136+ isSearchTopmostFullScreenRoute ( )
137+ ? ROUTES . SEARCH_MONEY_REQUEST_REPORT . getRoute ( { reportID : createdReportID , backTo : Navigation . getActiveRoute ( ) } )
138+ : ROUTES . REPORT_WITH_ID . getRoute ( createdReportID , undefined , undefined , Navigation . getActiveRoute ( ) ) ,
139+ ) ;
140+ } else if ( action === CONST . IOU . ACTION . CREATE ) {
121141 navigateWithMicrotask ( ROUTES . NEW_REPORT_WORKSPACE_SELECTION . getRoute ( ) ) ;
122142 } else {
123143 navigateWithMicrotask ( ROUTES . MONEY_REQUEST_STEP_REPORT . getRoute ( action , CONST . IOU . TYPE . SUBMIT , transactionID , reportID ) ) ;
124144 }
125-
126145 break ;
146+ }
127147 case CONST . UPGRADE_PATHS . CATEGORIES :
128148 Navigation . goBack ( ) ;
129149 navigateWithMicrotask ( backTo ?? ROUTES . MONEY_REQUEST_STEP_CATEGORY . getRoute ( action , CONST . IOU . TYPE . SUBMIT , transactionID , reportID ) ) ;
@@ -172,11 +192,10 @@ function IOURequestStepUpgrade({
172192 hasActiveAdminPolicies,
173193 } ) ;
174194 setIsUpgraded ( true ) ;
195+ setCreatedPolicyID ( policyData . policyID ) ;
175196 policyDataRef . current = policyData ;
176197 } ;
177198
178- const [ session ] = useOnyx ( ONYXKEYS . SESSION ) ;
179-
180199 const handleConfirmUpgradeWarning = ( ) => {
181200 setIsUpgradeWarningModalOpen ( false ) ;
182201 } ;
@@ -200,6 +219,7 @@ function IOURequestStepUpgrade({
200219 hasActiveAdminPolicies,
201220 } ) ;
202221 policyDataRef . current = policyData ;
222+ setCreatedPolicyID ( policyData . policyID ) ;
203223 setCreatedPolicyName ( params . name ) ;
204224 setShowConfirmationForm ( false ) ;
205225 setIsUpgraded ( true ) ;
0 commit comments