11import React from 'react' ;
2+ import Accordion from '@components/Accordion' ;
23import ConnectionLayout from '@components/ConnectionLayout' ;
34import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription' ;
45import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
6+ import useAccordionAnimation from '@hooks/useAccordionAnimation' ;
57import useLocalize from '@hooks/useLocalize' ;
68import useThemeStyles from '@hooks/useThemeStyles' ;
7- import * as ErrorUtils from '@libs/ErrorUtils' ;
9+ import { getLatestErrorField } from '@libs/ErrorUtils' ;
810import Navigation from '@libs/Navigation/Navigation' ;
911import { areSettingsInErrorFields , getSageIntacctNonReimbursableActiveDefaultVendor , settingsPendingAction } from '@libs/PolicyUtils' ;
10- import type { MenuItem , ToggleItem } from '@pages/workspace/accounting/intacct/types' ;
12+ import type { ExtendedMenuItemWithSubscribedSettings , MenuItemToRender } from '@pages/workspace/accounting/intacct/types' ;
1113import type { WithPolicyConnectionsProps } from '@pages/workspace/withPolicyConnections' ;
1214import withPolicyConnections from '@pages/workspace/withPolicyConnections' ;
1315import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow' ;
1416import { updateSageIntacctDefaultVendor } from '@userActions/connections/SageIntacct' ;
15- import * as Policy from '@userActions/Policy/Policy' ;
17+ import { clearSageIntacctErrorField } from '@userActions/Policy/Policy' ;
1618import CONST from '@src/CONST' ;
1719import ROUTES from '@src/ROUTES' ;
1820import { getDefaultVendorName } from './utils' ;
1921
20- type MenuItemWithSubscribedSettings = Pick < MenuItem , 'type' | 'description' | 'title' | 'onPress' | 'shouldHide' > & { subscribedSettings ?: string [ ] } ;
21-
22- type ToggleItemWithKey = ToggleItem & { key : string } ;
23-
2422function SageIntacctNonReimbursableExpensesPage ( { policy} : WithPolicyConnectionsProps ) {
2523 const { translate} = useLocalize ( ) ;
2624 const policyID = policy ?. id ?? '-1' ;
@@ -29,8 +27,31 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
2927
3028 const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor ( policy ) ;
3129 const defaultVendorName = getDefaultVendorName ( activeDefaultVendor , intacctData ?. vendors ) ;
30+ const expandedCondition = ! (
31+ ! config ?. export . nonReimbursable ||
32+ ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE && ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor )
33+ ) ;
34+
35+ const { isAccordionExpanded, shouldAnimateAccordionSection} = useAccordionAnimation ( expandedCondition ) ;
36+
37+ const renderDefault = ( item : MenuItemToRender ) => {
38+ return (
39+ < OfflineWithFeedback
40+ key = { item . description }
41+ pendingAction = { settingsPendingAction ( item . subscribedSettings , config ?. pendingFields ) }
42+ >
43+ < MenuItemWithTopDescription
44+ title = { item . title }
45+ description = { item . description }
46+ shouldShowRightIcon
47+ onPress = { item ?. onPress }
48+ brickRoadIndicator = { areSettingsInErrorFields ( item . subscribedSettings , config ?. errorFields ) ? CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR : undefined }
49+ />
50+ </ OfflineWithFeedback >
51+ ) ;
52+ } ;
3253
33- const menuItems : Array < MenuItemWithSubscribedSettings | ToggleItemWithKey > = [
54+ const menuItems : ExtendedMenuItemWithSubscribedSettings [ ] = [
3455 {
3556 type : 'menuitem' ,
3657 title : config ?. export . nonReimbursable
@@ -62,27 +83,38 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
6283 onToggle : ( enabled ) => {
6384 const vendor = enabled ? policy ?. connections ?. intacct ?. data ?. vendors ?. [ 0 ] . id ?? '' : '' ;
6485 updateSageIntacctDefaultVendor ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR , vendor , config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ;
86+ isAccordionExpanded . set ( enabled ) ;
87+ shouldAnimateAccordionSection . set ( true ) ;
6588 } ,
66- onCloseError : ( ) => Policy . clearSageIntacctErrorField ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
89+ onCloseError : ( ) => clearSageIntacctErrorField ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
6790 pendingAction : settingsPendingAction ( [ CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ] , config ?. pendingFields ) ,
68- errors : ErrorUtils . getLatestErrorField ( config , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
91+ errors : getLatestErrorField ( config , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ) ,
6992 shouldHide : config ?. export . nonReimbursable !== CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE ,
7093 } ,
7194 {
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 ,
95+ type : 'accordion' ,
96+ children : [
97+ {
98+ type : 'menuitem' ,
99+ title : defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate ( 'workspace.sageIntacct.notConfigured' ) ,
100+ description : translate ( 'workspace.sageIntacct.defaultVendor' ) ,
101+ onPress : ( ) => {
102+ Navigation . navigate ( ROUTES . POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR . getRoute ( policyID , CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE . toLowerCase ( ) ) ) ;
103+ } ,
104+ subscribedSettings : [
105+ config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . VENDOR_BILL
106+ ? CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_VENDOR
107+ : CONST . SAGE_INTACCT_CONFIG . NON_REIMBURSABLE_CREDIT_CARD_VENDOR ,
108+ ] ,
109+ shouldHide :
110+ ! config ?. export . nonReimbursable ||
111+ ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE &&
112+ ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ,
113+ } ,
82114 ] ,
83- shouldHide :
84- ! config ?. export . nonReimbursable ||
85- ( config ?. export . nonReimbursable === CONST . SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE . CREDIT_CARD_CHARGE && ! config ?. export . nonReimbursableCreditCardChargeDefaultVendor ) ,
115+ shouldHide : false ,
116+ shouldExpand : isAccordionExpanded ,
117+ shouldAnimateSection : shouldAnimateAccordionSection ,
86118 } ,
87119 ] ;
88120
@@ -114,21 +146,17 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP
114146 wrapperStyle = { [ styles . mv3 , styles . ph5 ] }
115147 />
116148 ) ;
117- default :
149+ case 'accordion' :
118150 return (
119- < OfflineWithFeedback
120- key = { item . description }
121- pendingAction = { settingsPendingAction ( item . subscribedSettings , config ?. pendingFields ) }
151+ < Accordion
152+ isExpanded = { item . shouldExpand }
153+ isToggleTriggered = { item . shouldAnimateSection }
122154 >
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 >
155+ { item . children . map ( ( child ) => renderDefault ( child ) ) }
156+ </ Accordion >
131157 ) ;
158+ default :
159+ return renderDefault ( item ) ;
132160 }
133161 } ) }
134162 </ ConnectionLayout >
0 commit comments