@@ -31,12 +31,6 @@ import type {WithPolicyAndFullscreenLoadingProps} from './withPolicyAndFullscree
31
31
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading' ;
32
32
import ToggleSettingOptionRow from './workflows/ToggleSettingsOptionRow' ;
33
33
34
- type ItemType = 'organize' | 'integrate' ;
35
- type ConnectionWarningModalState = {
36
- isOpen : boolean ;
37
- itemType ?: ItemType ;
38
- } ;
39
-
40
34
type WorkspaceMoreFeaturesPageProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps < FullScreenNavigatorParamList , typeof SCREENS . WORKSPACE . MORE_FEATURES > ;
41
35
42
36
type Item = {
@@ -66,7 +60,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
66
60
const isSyncTaxEnabled = ! ! policy ?. connections ?. quickbooksOnline ?. config . syncTax || ! ! policy ?. connections ?. xero ?. config . importTaxRates ;
67
61
const policyID = policy ?. id ?? '' ;
68
62
69
- const [ connectionWarningModalState , setConnectionWarningModalState ] = useState < ConnectionWarningModalState > ( { isOpen : false } ) ;
63
+ const [ isOrganizeWarningModalOpen , setIsOrganizeWarningModalOpen ] = useState < boolean > ( false ) ;
64
+ const [ isIntegrateWarningModalOpen , setIsIntegrateWarningModalOpen ] = useState < boolean > ( false ) ;
70
65
71
66
const spendItems : Item [ ] = [
72
67
{
@@ -101,10 +96,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
101
96
pendingAction : policy ?. pendingFields ?. areCategoriesEnabled ,
102
97
action : ( isEnabled : boolean ) => {
103
98
if ( hasAccountingConnection ) {
104
- setConnectionWarningModalState ( {
105
- isOpen : true ,
106
- itemType : 'organize' ,
107
- } ) ;
99
+ setIsOrganizeWarningModalOpen ( true ) ;
108
100
return ;
109
101
}
110
102
Category . enablePolicyCategories ( policy ?. id ?? '' , isEnabled ) ;
@@ -119,10 +111,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
119
111
pendingAction : policy ?. pendingFields ?. areTagsEnabled ,
120
112
action : ( isEnabled : boolean ) => {
121
113
if ( hasAccountingConnection ) {
122
- setConnectionWarningModalState ( {
123
- isOpen : true ,
124
- itemType : 'organize' ,
125
- } ) ;
114
+ setIsOrganizeWarningModalOpen ( true ) ;
126
115
return ;
127
116
}
128
117
Tag . enablePolicyTags ( policy ?. id ?? '' , isEnabled ) ;
@@ -137,10 +126,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
137
126
pendingAction : policy ?. pendingFields ?. tax ,
138
127
action : ( isEnabled : boolean ) => {
139
128
if ( hasAccountingConnection ) {
140
- setConnectionWarningModalState ( {
141
- isOpen : true ,
142
- itemType : 'organize' ,
143
- } ) ;
129
+ setIsOrganizeWarningModalOpen ( true ) ;
144
130
return ;
145
131
}
146
132
Policy . enablePolicyTaxes ( policy ?. id ?? '' , isEnabled ) ;
@@ -157,10 +143,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
157
143
pendingAction : policy ?. pendingFields ?. areConnectionsEnabled ,
158
144
action : ( isEnabled : boolean ) => {
159
145
if ( hasAccountingConnection ) {
160
- setConnectionWarningModalState ( {
161
- isOpen : true ,
162
- itemType : 'integrate' ,
163
- } ) ;
146
+ setIsIntegrateWarningModalOpen ( true ) ;
164
147
return ;
165
148
}
166
149
Policy . enablePolicyConnections ( policy ?. id ?? '' , isEnabled ) ;
@@ -247,17 +230,6 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
247
230
} , [ fetchFeatures ] ) ,
248
231
) ;
249
232
250
- const getConnectionWarningPrompt = useCallback ( ( ) => {
251
- switch ( connectionWarningModalState . itemType ) {
252
- case 'organize' :
253
- return translate ( 'workspace.moreFeatures.connectionsWarningModal.featureEnabledText' ) ;
254
- case 'integrate' :
255
- return translate ( 'workspace.moreFeatures.connectionsWarningModal.disconnectText' ) ;
256
- default :
257
- return undefined ;
258
- }
259
- } , [ connectionWarningModalState . itemType , translate ] ) ;
260
-
261
233
return (
262
234
< AccessOrNotFoundWrapper
263
235
accessVariants = { [ CONST . POLICY . ACCESS_VARIANTS . ADMIN , CONST . POLICY . ACCESS_VARIANTS . PAID ] }
@@ -280,20 +252,24 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
280
252
< ConfirmModal
281
253
title = { translate ( 'workspace.moreFeatures.connectionsWarningModal.featureEnabledTitle' ) }
282
254
onConfirm = { ( ) => {
283
- setConnectionWarningModalState ( {
284
- isOpen : false ,
285
- itemType : undefined ,
286
- } ) ;
255
+ setIsOrganizeWarningModalOpen ( false ) ;
256
+ Navigation . navigate ( ROUTES . POLICY_ACCOUNTING . getRoute ( policyID ) ) ;
257
+ } }
258
+ onCancel = { ( ) => setIsOrganizeWarningModalOpen ( false ) }
259
+ isVisible = { isOrganizeWarningModalOpen }
260
+ prompt = { translate ( 'workspace.moreFeatures.connectionsWarningModal.featureEnabledText' ) }
261
+ confirmText = { translate ( 'workspace.moreFeatures.connectionsWarningModal.manageSettings' ) }
262
+ cancelText = { translate ( 'common.cancel' ) }
263
+ />
264
+ < ConfirmModal
265
+ title = { translate ( 'workspace.moreFeatures.connectionsWarningModal.featureEnabledTitle' ) }
266
+ onConfirm = { ( ) => {
267
+ setIsIntegrateWarningModalOpen ( false ) ;
287
268
Navigation . navigate ( ROUTES . POLICY_ACCOUNTING . getRoute ( policyID ) ) ;
288
269
} }
289
- onCancel = { ( ) =>
290
- setConnectionWarningModalState ( {
291
- isOpen : false ,
292
- itemType : undefined ,
293
- } )
294
- }
295
- isVisible = { connectionWarningModalState . isOpen }
296
- prompt = { getConnectionWarningPrompt ( ) }
270
+ onCancel = { ( ) => setIsIntegrateWarningModalOpen ( false ) }
271
+ isVisible = { isIntegrateWarningModalOpen }
272
+ prompt = { translate ( 'workspace.moreFeatures.connectionsWarningModal.disconnectText' ) }
297
273
confirmText = { translate ( 'workspace.moreFeatures.connectionsWarningModal.manageSettings' ) }
298
274
cancelText = { translate ( 'common.cancel' ) }
299
275
/>
0 commit comments