@@ -36,6 +36,9 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) {
3636
3737 const currentTrackingCategory = trackingCategories ?. find ( ( category ) => category . id === categoryId ) ;
3838 const currentTrackingCategoryValue = currentTrackingCategory ? ( mappings ?. [ `${ CONST . XERO_CONFIG . TRACKING_CATEGORY_PREFIX } ${ currentTrackingCategory . id } ` ] ?? '' ) : '' ;
39+ const reportFieldTrackingCategories = Object . entries ( mappings ?? { } ) . filter (
40+ ( [ key , value ] ) => key . startsWith ( CONST . XERO_CONFIG . TRACKING_CATEGORY_PREFIX ) && value === CONST . XERO_CONFIG . TRACKING_CATEGORY_OPTIONS . REPORT_FIELD ,
41+ ) ;
3942
4043 const optionsList = useMemo (
4144 ( ) =>
@@ -77,16 +80,16 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) {
7780 categoryId ? { [ `${ CONST . XERO_CONFIG . TRACKING_CATEGORY_PREFIX } ${ categoryId } ` ] : option . value } : { } ,
7881 categoryId ? { [ `${ CONST . XERO_CONFIG . TRACKING_CATEGORY_PREFIX } ${ categoryId } ` ] : currentTrackingCategoryValue } : { } ,
7982 ) ;
80- if ( option . value === CONST . XERO_CONFIG . TRACKING_CATEGORY_OPTIONS . REPORT_FIELD ) {
83+ if ( ! reportFieldTrackingCategories . length && option . value === CONST . XERO_CONFIG . TRACKING_CATEGORY_OPTIONS . REPORT_FIELD ) {
8184 enablePolicyReportFields ( policyID , true ) ;
8285 }
83- if ( currentTrackingCategoryValue === CONST . XERO_CONFIG . TRACKING_CATEGORY_OPTIONS . REPORT_FIELD ) {
86+ if ( reportFieldTrackingCategories . length === 1 && currentTrackingCategoryValue === CONST . XERO_CONFIG . TRACKING_CATEGORY_OPTIONS . REPORT_FIELD ) {
8487 enablePolicyReportFields ( policyID , false ) ;
8588 }
8689 }
8790 Navigation . goBack ( ROUTES . POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES . getRoute ( policyID ) ) ;
8891 } ,
89- [ categoryId , currentTrackingCategoryValue , policy , policyID ] ,
92+ [ categoryId , currentTrackingCategoryValue , reportFieldTrackingCategories , policy , policyID ] ,
9093 ) ;
9194
9295 return (
0 commit comments