@@ -4,30 +4,24 @@ import React, {useCallback, useMemo, useRef, useState} from 'react';
44import { View } from 'react-native' ;
55import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
66import Button from '@components/Button' ;
7- import { ModalActions } from '@components/Modal/Global/ModalContext' ;
87import type { PopoverMenuItem } from '@components/PopoverMenu' ;
98import PopoverMenu from '@components/PopoverMenu' ;
10- import useConfirmModal from '@hooks/useConfirmModal' ;
11- import useCreateEmptyReportConfirmation from '@hooks/useCreateEmptyReportConfirmation' ;
9+ import useCreateReportAction from '@hooks/useCreateReportAction' ;
1210import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
13- import useHasEmptyReportsForPolicy from '@hooks/useHasEmptyReportsForPolicy' ;
1411import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
1512import useLocalize from '@hooks/useLocalize' ;
1613import useOnyx from '@hooks/useOnyx' ;
1714import usePermissions from '@hooks/usePermissions' ;
18- import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses' ;
1915import usePopoverPosition from '@hooks/usePopoverPosition' ;
2016import useThemeStyles from '@hooks/useThemeStyles' ;
2117import { startDistanceRequest , startMoneyRequest } from '@libs/actions/IOU' ;
22- import { openOldDotLink } from '@libs/actions/Link' ;
2318import { createNewReport } from '@libs/actions/Report' ;
2419import getIconForAction from '@libs/getIconForAction' ;
2520import interceptAnonymousUser from '@libs/interceptAnonymousUser' ;
2621import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute' ;
2722import Navigation from '@libs/Navigation/Navigation' ;
28- import { areAllGroupPoliciesExpenseChatDisabled , getDefaultChatEnabledPolicy } from '@libs/PolicyUtils' ;
23+ import { getDefaultChatEnabledPolicy } from '@libs/PolicyUtils' ;
2924import { generateReportID , hasViolations as hasViolationsReportUtils } from '@libs/ReportUtils' ;
30- import { shouldRestrictUserBillableActions } from '@libs/SubscriptionUtils' ;
3125import CONST from '@src/CONST' ;
3226import ONYXKEYS from '@src/ONYXKEYS' ;
3327import ROUTES from '@src/ROUTES' ;
@@ -47,7 +41,6 @@ function SearchActionsBarCreateButton() {
4741 const [ session ] = useOnyx ( ONYXKEYS . SESSION ) ;
4842 const [ email ] = useOnyx ( ONYXKEYS . SESSION , { selector : emailSelector } ) ;
4943 const [ allBetas ] = useOnyx ( ONYXKEYS . BETAS ) ;
50- const [ allPolicies ] = useOnyx ( ONYXKEYS . COLLECTION . POLICY ) ;
5144 const [ transactionViolations ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS ) ;
5245 const [ draftTransactionIDs ] = useOnyx ( ONYXKEYS . COLLECTION . TRANSACTION_DRAFT , { selector : validTransactionDraftIDsSelector } ) ;
5346 const groupPaidPoliciesWithChatEnabledSelector = useCallback ( ( policies : OnyxCollection < OnyxTypes . Policy > ) => groupPaidPoliciesWithExpenseChatEnabledSelector ( policies , email ) , [ email ] ) ;
@@ -58,37 +51,11 @@ function SearchActionsBarCreateButton() {
5851 const hasViolations = hasViolationsReportUtils ( undefined , transactionViolations , session ?. accountID ?? CONST . DEFAULT_NUMBER_ID , session ?. email ?? '' ) ;
5952 const [ activePolicyID ] = useOnyx ( ONYXKEYS . NVP_ACTIVE_POLICY_ID ) ;
6053 const [ activePolicy ] = useOnyx ( `${ ONYXKEYS . COLLECTION . POLICY } ${ activePolicyID } ` ) ;
61- const [ ownerBillingGraceEndPeriod ] = useOnyx ( ONYXKEYS . NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END ) ;
62- const [ userBillingGraceEndPeriods ] = useOnyx ( ONYXKEYS . COLLECTION . SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END ) ;
63- const { policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses ( ) ;
64- const shouldNavigateToUpgradePath = ! policyForMovingExpensesID && ! shouldSelectPolicy ;
65- const { showConfirmModal} = useConfirmModal ( ) ;
66-
67- const shouldRedirectToExpensifyClassic = useMemo ( ( ) => {
68- return areAllGroupPoliciesExpenseChatDisabled ( ( allPolicies as OnyxCollection < OnyxTypes . Policy > ) ?? { } ) ;
69- } , [ allPolicies ] ) ;
7054
7155 const defaultChatEnabledPolicy = useMemo (
7256 ( ) => getDefaultChatEnabledPolicy ( groupPoliciesWithChatEnabled as Array < OnyxEntry < OnyxTypes . Policy > > , activePolicy ) ,
7357 [ activePolicy , groupPoliciesWithChatEnabled ] ,
7458 ) ;
75- const defaultChatEnabledPolicyID = defaultChatEnabledPolicy ?. id ;
76-
77- const hasEmptyReport = useHasEmptyReportsForPolicy ( defaultChatEnabledPolicyID ) ;
78- const [ hasDismissedEmptyReportsConfirmation ] = useOnyx ( ONYXKEYS . NVP_EMPTY_REPORTS_CONFIRMATION_DISMISSED ) ;
79- const shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy = hasEmptyReport && hasDismissedEmptyReportsConfirmation !== true ;
80-
81- const showRedirectToExpensifyClassicModal = useCallback ( async ( ) => {
82- const { action} = await showConfirmModal ( {
83- title : translate ( 'sidebarScreen.redirectToExpensifyClassicModal.title' ) ,
84- prompt : translate ( 'sidebarScreen.redirectToExpensifyClassicModal.description' ) ,
85- confirmText : translate ( 'exitSurvey.goToExpensifyClassic' ) ,
86- cancelText : translate ( 'common.cancel' ) ,
87- } ) ;
88- if ( action === ModalActions . CONFIRM ) {
89- openOldDotLink ( CONST . OLDDOT_URLS . INBOX ) ;
90- }
91- } , [ showConfirmModal , translate ] ) ;
9259
9360 const handleCreateWorkspaceReport = useCallback (
9461 ( shouldDismissEmptyReportsConfirmation ?: boolean ) => {
@@ -116,10 +83,9 @@ function SearchActionsBarCreateButton() {
11683 [ currentUserPersonalDetails , hasViolations , defaultChatEnabledPolicy , isASAPSubmitBetaEnabled , allBetas ] ,
11784 ) ;
11885
119- const { openCreateReportConfirmation} = useCreateEmptyReportConfirmation ( {
120- policyID : defaultChatEnabledPolicyID ,
121- policyName : defaultChatEnabledPolicy ?. name ?? '' ,
122- onConfirm : handleCreateWorkspaceReport ,
86+ const { createReportAction} = useCreateReportAction ( {
87+ onCreateReport : handleCreateWorkspaceReport ,
88+ groupPoliciesWithChatEnabled,
12389 } ) ;
12490
12591 const hideCreateMenu = useCallback ( ( ) => setIsCreateMenuActive ( false ) , [ ] ) ;
@@ -157,71 +123,10 @@ function SearchActionsBarCreateButton() {
157123 {
158124 icon : expensifyIcons . Document ,
159125 text : translate ( 'report.newReport.createReport' ) ,
160- onSelected : ( ) =>
161- interceptAnonymousUser ( ( ) => {
162- if ( shouldRedirectToExpensifyClassic ) {
163- showRedirectToExpensifyClassicModal ( ) ;
164- return ;
165- }
166-
167- // No valid policy at all → upgrade + create workspace flow
168- if ( shouldNavigateToUpgradePath ) {
169- const freshReportID = generateReportID ( ) ;
170- const freshTransactionID = generateReportID ( ) ;
171- Navigation . navigate (
172- ROUTES . MONEY_REQUEST_UPGRADE . getRoute ( {
173- action : CONST . IOU . ACTION . CREATE ,
174- iouType : CONST . IOU . TYPE . CREATE ,
175- transactionID : freshTransactionID ,
176- reportID : freshReportID ,
177- upgradePath : CONST . UPGRADE_PATHS . REPORTS ,
178- } ) ,
179- ) ;
180- return ;
181- }
182-
183- const workspaceIDForReportCreation = defaultChatEnabledPolicyID ;
184-
185- // No default or restricted with multiple workspaces → workspace selector
186- if (
187- ! workspaceIDForReportCreation ||
188- ( shouldRestrictUserBillableActions ( workspaceIDForReportCreation , userBillingGraceEndPeriods , undefined , ownerBillingGraceEndPeriod ) &&
189- groupPoliciesWithChatEnabled . length > 1 )
190- ) {
191- Navigation . navigate ( ROUTES . NEW_REPORT_WORKSPACE_SELECTION . getRoute ( ) ) ;
192- return ;
193- }
194-
195- // Default workspace is not restricted → create report directly
196- if ( ! shouldRestrictUserBillableActions ( workspaceIDForReportCreation , userBillingGraceEndPeriods , undefined , ownerBillingGraceEndPeriod ) ) {
197- // Check if empty report confirmation should be shown
198- if ( shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy ) {
199- openCreateReportConfirmation ( ) ;
200- } else {
201- handleCreateWorkspaceReport ( false ) ;
202- }
203- return ;
204- }
205-
206- Navigation . navigate ( ROUTES . RESTRICTED_ACTION . getRoute ( workspaceIDForReportCreation ) ) ;
207- } ) ,
126+ onSelected : createReportAction ,
208127 } ,
209128 ] ,
210- [
211- translate ,
212- expensifyIcons ,
213- draftTransactionIDs ,
214- shouldRedirectToExpensifyClassic ,
215- showRedirectToExpensifyClassicModal ,
216- shouldNavigateToUpgradePath ,
217- groupPoliciesWithChatEnabled . length ,
218- defaultChatEnabledPolicyID ,
219- shouldShowEmptyReportConfirmationForDefaultChatEnabledPolicy ,
220- ownerBillingGraceEndPeriod ,
221- userBillingGraceEndPeriods ,
222- openCreateReportConfirmation ,
223- handleCreateWorkspaceReport ,
224- ] ,
129+ [ translate , expensifyIcons , draftTransactionIDs , createReportAction ] ,
225130 ) ;
226131
227132 return (
0 commit comments