11import React from 'react' ;
2- import { useSharedValue } from 'react-native-reanimated' ;
3- import Accordion from '@components/Accordion' ;
42import ConnectionLayout from '@components/ConnectionLayout' ;
53import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription' ;
64import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
@@ -9,9 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
97import * as ErrorUtils from '@libs/ErrorUtils' ;
108import Navigation from '@libs/Navigation/Navigation' ;
119import { areSettingsInErrorFields , getSageIntacctNonReimbursableActiveDefaultVendor , settingsPendingAction } from '@libs/PolicyUtils' ;
12- import type { AccordionItem , MenuItemWithSubscribedSettings , ToggleItem } from '@pages/workspace/accounting/intacct/types' ;
13- import { MenuItem } from '@pages/workspace/accounting/intacct/types' ;
14- import { shouldHideCustomFormIDOptions } from '@pages/workspace/accounting/netsuite/utils' ;
10+ import type { MenuItem , ToggleItem } from '@pages/workspace/accounting/intacct/types' ;
1511import type { WithPolicyConnectionsProps } from '@pages/workspace/withPolicyConnections' ;
1612import withPolicyConnections from '@pages/workspace/withPolicyConnections' ;
1713import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow' ;
@@ -21,6 +17,8 @@ import CONST from '@src/CONST';
2117import ROUTES from '@src/ROUTES' ;
2218import { getDefaultVendorName } from './utils' ;
2319
20+ type MenuItemWithSubscribedSettings = Pick < MenuItem , 'type' | 'description' | 'title' | 'onPress' | 'shouldHide' > & { subscribedSettings ?: string [ ] } ;
21+
2422type ToggleItemWithKey = ToggleItem & { key : string } ;
2523
2624function SageIntacctNonReimbursableExpensesPage ( { policy} : WithPolicyConnectionsProps ) {
@@ -31,31 +29,8 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
3129
3230 const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor ( policy ) ;
3331 const defaultVendorName = getDefaultVendorName ( activeDefaultVendor , intacctData ?. vendors ) ;
34- const shouldExpand = useSharedValue (
35- ! (
36- ! config ?. export . nonReimbursable ||
37- ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE && ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor )
38- ) ,
39- ) ;
4032
41- const renderDefault = ( item : MenuItemWithSubscribedSettings ) => {
42- return (
43- < OfflineWithFeedback
44- key = { item . description }
45- pendingAction = { settingsPendingAction ( item . subscribedSettings , config ?. pendingFields ) }
46- >
47- < MenuItemWithTopDescription
48- title = { item . title }
49- description = { item . description }
50- shouldShowRightIcon
51- onPress = { item ?. onPress }
52- brickRoadIndicator = { areSettingsInErrorFields ( item . subscribedSettings , config ?. errorFields ) ? CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR : undefined }
53- />
54- </ OfflineWithFeedback >
55- ) ;
56- } ;
57-
58- const menuItems : Array < MenuItemWithSubscribedSettings | ToggleItemWithKey | AccordionItem > = [
33+ const menuItems : Array < MenuItemWithSubscribedSettings | ToggleItemWithKey > = [
5934 {
6035 type : 'menuitem' ,
6136 title : config ?. export . nonReimbursable
@@ -87,36 +62,27 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
8762 onToggle : ( enabled ) => {
8863 const vendor = enabled ? policy ?. connections ?. intacct ?. data ?. vendors ?. [ 0 ] . id ?? '' : '' ;
8964 updateSageIntacctDefaultVendor ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR , vendor , config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ;
90- shouldExpand . set ( enabled ) ;
9165 } ,
9266 onCloseError : ( ) => Policy . clearSageIntacctErrorField ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
9367 pendingAction : settingsPendingAction ( [ CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ] , config ?. pendingFields ) ,
9468 errors : ErrorUtils . getLatestErrorField ( config , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
9569 shouldHide : config ?. export . nonReimbursable !== CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE ,
9670 } ,
9771 {
98- type : 'accordion' ,
99- children : [
100- {
101- type : 'menuitem' ,
102- title : defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate ( 'workspace.sageIntacct.notConfigured' ) ,
103- description : translate ( 'workspace.sageIntacct.defaultVendor' ) ,
104- onPress : ( ) => {
105- Navigation . navigate ( ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR . getRoute ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE . toLowerCase ( ) ) ) ;
106- } ,
107- subscribedSettings : [
108- config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . VENDOR_BILL
109- ? CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_VENDOR
110- : CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ,
111- ] ,
112- shouldHide :
113- ! config ?. export . nonReimbursable ||
114- ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE &&
115- ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ,
116- } ,
72+ type : 'menuitem' ,
73+ title : defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate ( 'workspace.sageIntacct.notConfigured' ) ,
74+ description : translate ( 'workspace.sageIntacct.defaultVendor' ) ,
75+ onPress : ( ) => {
76+ Navigation . navigate ( ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR . getRoute ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE . toLowerCase ( ) ) ) ;
77+ } ,
78+ subscribedSettings : [
79+ config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . VENDOR_BILL
80+ ? CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_VENDOR
81+ : CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ,
11782 ] ,
118- shouldHide : false ,
119- shouldExpand,
83+ shouldHide :
84+ ! config ?. export . nonReimbursable ||
85+ ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE && ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ,
12086 } ,
12187 ] ;
12288
@@ -148,17 +114,21 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
148114 wrapperStyle = { [ styles . mv3 , styles . ph5 ] }
149115 />
150116 ) ;
151- case 'accordion' :
117+ default :
152118 return (
153- < Accordion
154- isExpanded = { item . shouldExpand }
155- style = { styles . overflowHidden }
119+ < OfflineWithFeedback
120+ key = { item . description }
121+ pendingAction = { settingsPendingAction ( item . subscribedSettings , config ?. pendingFields ) }
156122 >
157- { item . children . map ( ( child ) => renderDefault ( child ) ) }
158- </ Accordion >
123+ < MenuItemWithTopDescription
124+ title = { item . title }
125+ description = { item . description }
126+ shouldShowRightIcon
127+ onPress = { item ?. onPress }
128+ brickRoadIndicator = { areSettingsInErrorFields ( item . subscribedSettings , config ?. errorFields ) ? CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR : undefined }
129+ />
130+ </ OfflineWithFeedback >
159131 ) ;
160- default :
161- return renderDefault ( item ) ;
162132 }
163133 } ) }
164134 </ ConnectionLayout >
0 commit comments