From 876f2a9049dbfb0ebbcf2be49a45f2da77ea4c8d Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 6 Aug 2024 16:43:57 +0200 Subject: [PATCH 1/6] update advanced page --- src/libs/actions/connections/index.ts | 4 ++-- .../xero/advanced/XeroAdvancedPage.tsx | 24 ++++++++++++++----- .../XeroBillPaymentAccountSelectorPage.tsx | 12 +++++++--- .../XeroInvoiceAccountSelectorPage.tsx | 12 +++++++--- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index b611a37faf64..921c1d0a2ed5 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -73,6 +73,7 @@ function updatePolicyXeroConnectionConfig, + oldSettingValue?: Partial, ) { const optimisticData: OnyxUpdate[] = [ { @@ -100,7 +101,7 @@ function updatePolicyXeroConnectionConfig - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.AUTO_SYNC, { - enabled: !autoSync?.enabled, - }) + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.AUTO_SYNC, + { + enabled: !autoSync?.enabled, + }, + {enabled: autoSync?.enabled}, + ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.ENABLED], pendingFields)} errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.ENABLED)} @@ -76,9 +82,15 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) { wrapperStyle={styles.mv3} isActive={!!sync?.syncReimbursedReports} onToggle={() => - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.SYNC, { - syncReimbursedReports: !sync?.syncReimbursedReports, - }) + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.SYNC, + { + syncReimbursedReports: !sync?.syncReimbursedReports, + }, + {syncReimbursedReports: sync?.syncReimbursedReports}, + ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.SYNC_REIMBURSED_REPORTS], pendingFields)} errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.SYNC_REIMBURSED_REPORTS)} diff --git a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx index f255e55bb1d9..c8f6595d6f4a 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx @@ -42,9 +42,15 @@ function XeroBillPaymentAccountSelectorPage({policy}: WithPolicyConnectionsProps const updateAccount = useCallback( ({value}: SelectorType) => { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.SYNC, { - reimbursementAccountID: value, - }); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.SYNC, + { + reimbursementAccountID: value, + }, + {reimbursementAccountID}, + ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, [policyID], diff --git a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx index 866a4ea5e2c0..330294a82d1c 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx @@ -42,9 +42,15 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) { const updateAccount = useCallback( ({value}: SelectorType) => { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.SYNC, { - invoiceCollectionsAccountID: value, - }); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.SYNC, + { + invoiceCollectionsAccountID: value, + }, + {invoiceCollectionsAccountID}, + ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, [policyID], From f8074f3d04f1527a8ed53428925a385cf081112b Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 6 Aug 2024 16:50:29 +0200 Subject: [PATCH 2/6] update export page --- .../xero/export/XeroBankAccountSelectPage.tsx | 12 +++++++++--- .../xero/export/XeroPreferredExporterSelectPage.tsx | 8 +++++++- .../xero/export/XeroPurchaseBillDateSelectPage.tsx | 8 +++++++- .../export/XeroPurchaseBillStatusSelectorPage.tsx | 12 +++++++++--- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx index 457872770b86..449e9a12c4a7 100644 --- a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx @@ -46,9 +46,15 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { const updateBankAccount = useCallback( ({value}: SelectorType) => { if (initiallyFocusedOptionKey !== value) { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, { - nonReimbursableAccount: value, - }); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.EXPORT, + { + nonReimbursableAccount: value, + }, + {nonReimbursableAccount: config?.export?.nonReimbursableAccount}, + ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx index 56593df406c2..0bdac1c6786e 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx @@ -67,7 +67,13 @@ function XeroPreferredExporterSelectPage({policy}: WithPolicyConnectionsProps) { const selectExporter = useCallback( (row: CardListItem) => { if (row.value !== config?.export?.exporter) { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {exporter: row.value}); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.EXPORT, + {exporter: row.value}, + {exporter: config?.export?.exporter}, + ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx index ae8270b6907d..fd103edad1b0 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx @@ -47,7 +47,13 @@ function XeroPurchaseBillDateSelectPage({policy}: WithPolicyConnectionsProps) { const selectExportDate = useCallback( (row: MenuListItem) => { if (row.value !== config?.export?.billDate) { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {billDate: row.value}); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.EXPORT, + {billDate: row.value}, + {billDate: config?.export?.billDate}, + ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_PURCHASE_BILL_DATE_SELECT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx index 303cbafa22d7..5f907f08bdf4 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx @@ -52,9 +52,15 @@ function XeroPurchaseBillStatusSelectorPage({policy}: WithPolicyConnectionsProps return; } if (row.value !== invoiceStatus) { - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, { - billStatus: {...config?.export?.billStatus, purchase: row.value}, - }); + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.EXPORT, + { + billStatus: {...config?.export?.billStatus, purchase: row.value}, + }, + {billStatus: config?.export?.billStatus}, + ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.getRoute(policyID)); }, From dc881c6708cf25973a17cb784da045cea88b8121 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 6 Aug 2024 16:58:37 +0200 Subject: [PATCH 3/6] update import page --- .../xero/XeroMapTrackingCategoryConfigurationPage.tsx | 5 ++--- .../accounting/xero/XeroTaxesConfigurationPage.tsx | 10 +++++++++- .../xero/XeroTrackingCategoryConfigurationPage.tsx | 1 + .../accounting/xero/import/XeroChartOfAccountsPage.tsx | 8 +++++++- .../xero/import/XeroCustomerConfigurationPage.tsx | 10 +++++++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx index 2befbebeb0d2..6e7b8b50f58e 100644 --- a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx @@ -22,8 +22,6 @@ type RouteParams = { categoryName?: string; }; -const TRACKING_CATEGORIES_KEY = 'trackingCategory_'; - function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { const {translate} = useLocalize(); const route = useRoute(); @@ -37,7 +35,7 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { const {mappings} = policy?.connections?.xero?.config ?? {}; const currentTrackingCategory = trackingCategories?.find((category) => category.id === categoryId); - const currentTrackingCategoryValue = currentTrackingCategory ? mappings?.[`${TRACKING_CATEGORIES_KEY}${currentTrackingCategory.id}`] ?? '' : ''; + const currentTrackingCategoryValue = currentTrackingCategory ? mappings?.[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${currentTrackingCategory.id}`] ?? '' : ''; const optionsList = useMemo( () => @@ -67,6 +65,7 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.MAPPINGS, categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: option.value} : {}, + categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: currentTrackingCategoryValue} : {}, ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES.getRoute(policyID)); diff --git a/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx index 1abdc90064b2..57053cb30808 100644 --- a/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx @@ -33,7 +33,15 @@ function XeroTaxesConfigurationPage({policy}: WithPolicyProps) { title={translate('workspace.accounting.import')} switchAccessibilityLabel={translate('workspace.xero.customers')} isActive={isSwitchOn} - onToggle={() => Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.IMPORT_TAX_RATES, !xeroConfig?.importTaxRates)} + onToggle={() => + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.IMPORT_TAX_RATES, + !xeroConfig?.importTaxRates, + xeroConfig?.importTaxRates, + ) + } errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.IMPORT_TAX_RATES)} onCloseError={() => Policy.clearXeroErrorField(policyID, CONST.XERO_CONFIG.IMPORT_TAX_RATES)} pendingAction={PolicyUtils.settingsPendingAction([CONST.XERO_CONFIG.IMPORT_TAX_RATES], xeroConfig?.pendingFields)} diff --git a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx index 47bc37f688ef..9d27c8887e6e 100644 --- a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx @@ -59,6 +59,7 @@ function XeroTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES, !xeroConfig?.importTrackingCategories, + xeroConfig?.importTrackingCategories, ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES], xeroConfig?.pendingFields)} diff --git a/src/pages/workspace/accounting/xero/import/XeroChartOfAccountsPage.tsx b/src/pages/workspace/accounting/xero/import/XeroChartOfAccountsPage.tsx index 924d18264b7b..20a6e24eb105 100644 --- a/src/pages/workspace/accounting/xero/import/XeroChartOfAccountsPage.tsx +++ b/src/pages/workspace/accounting/xero/import/XeroChartOfAccountsPage.tsx @@ -60,7 +60,13 @@ function XeroChartOfAccountsPage({policy}: WithPolicyProps) { shouldPlaceSubtitleBelowSwitch isActive={!!xeroConfig?.enableNewCategories} onToggle={() => - Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES, !xeroConfig?.enableNewCategories) + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES, + !xeroConfig?.enableNewCategories, + xeroConfig?.enableNewCategories, + ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES], xeroConfig?.pendingFields)} errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES)} diff --git a/src/pages/workspace/accounting/xero/import/XeroCustomerConfigurationPage.tsx b/src/pages/workspace/accounting/xero/import/XeroCustomerConfigurationPage.tsx index c1ab8c82ba95..29c7125213d1 100644 --- a/src/pages/workspace/accounting/xero/import/XeroCustomerConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/import/XeroCustomerConfigurationPage.tsx @@ -42,7 +42,15 @@ function XeroCustomerConfigurationPage({policy}: WithPolicyProps) { /> } isActive={isSwitchOn} - onToggle={() => Connections.updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.IMPORT_CUSTOMERS, !xeroConfig?.importCustomers)} + onToggle={() => + Connections.updatePolicyXeroConnectionConfig( + policyID, + CONST.POLICY.CONNECTIONS.NAME.XERO, + CONST.XERO_CONFIG.IMPORT_CUSTOMERS, + !xeroConfig?.importCustomers, + xeroConfig?.importCustomers, + ) + } errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.IMPORT_CUSTOMERS)} onCloseError={() => Policy.clearXeroErrorField(policyID, CONST.XERO_CONFIG.IMPORT_CUSTOMERS)} pendingAction={PolicyUtils.settingsPendingAction([CONST.XERO_CONFIG.IMPORT_CUSTOMERS], xeroConfig?.pendingFields)} From 44dd8586c5db8447fd3aafdaa345058f44b52ed9 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 6 Aug 2024 16:58:51 +0200 Subject: [PATCH 4/6] update organization selection page --- .../accounting/xero/XeroOrganizationConfigurationPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx index 1a0f92f4cbbf..df777bdb8b12 100644 --- a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx @@ -59,7 +59,7 @@ function XeroOrganizationConfigurationPage({ return; } - updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.TENANT_ID, keyForList); + updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.TENANT_ID, keyForList, xeroConfig?.tenantID); Navigation.goBack(); }; From a24753ab465da402bb4166e6ac22946b8bc7be82 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 6 Aug 2024 17:35:45 +0200 Subject: [PATCH 5/6] do not mark first account as selected --- src/components/SelectionScreen.tsx | 2 +- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/libs/PolicyUtils.ts | 9 ++++----- .../xero/XeroMapTrackingCategoryConfigurationPage.tsx | 2 +- .../accounting/xero/advanced/XeroAdvancedPage.tsx | 4 ++-- .../xero/advanced/XeroBillPaymentAccountSelectorPage.tsx | 6 +++--- .../xero/advanced/XeroInvoiceAccountSelectorPage.tsx | 6 +++--- .../accounting/xero/export/XeroBankAccountSelectPage.tsx | 6 +++--- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/components/SelectionScreen.tsx b/src/components/SelectionScreen.tsx index 45492c77ec98..ae110d754b6a 100644 --- a/src/components/SelectionScreen.tsx +++ b/src/components/SelectionScreen.tsx @@ -151,7 +151,7 @@ function SelectionScreen({ initiallyFocusedOptionKey={initiallyFocusedOptionKey} listEmptyContent={listEmptyContent} listFooterContent={listFooterContent} - sectionListStyle={[styles.flexGrow0]} + sectionListStyle={!!sections.length && [styles.flexGrow0]} shouldDebounceRowSelect={shouldDebounceRowSelect} > id === selectedBankAccountId); - return (bankAccounts ?? []).map(({id, name}, index) => ({ + return (bankAccounts ?? []).map(({id, name}) => ({ value: id, text: name, keyForList: id, - isSelected: isMatchFound ? selectedBankAccountId === id : index === 0, + isSelected: selectedBankAccountId === id, })); } @@ -945,7 +944,7 @@ export { getXeroTenants, findCurrentXeroOrganization, getCurrentXeroOrganizationName, - getXeroBankAccountsWithDefaultSelect, + getXeroBankAccounts, findSelectedVendorWithDefaultSelect, findSelectedBankAccountWithDefaultSelect, findSelectedInvoiceItemWithDefaultSelect, diff --git a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx index 6e7b8b50f58e..d4fb1f77a52b 100644 --- a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx @@ -70,7 +70,7 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_TRACKING_CATEGORIES.getRoute(policyID)); }, - [categoryId, categoryName, policyID], + [categoryId, categoryName, currentTrackingCategoryValue, policyID], ); return ( diff --git a/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx index e96d161c7956..e7977497684f 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx @@ -29,9 +29,9 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) { const getSelectedAccountName = useMemo( () => (accountID: string) => { const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === accountID); - return selectedAccount?.name ?? bankAccounts?.[0]?.name ?? ''; + return selectedAccount?.name ?? translate('workspace.xero.notConfigured'); }, - [bankAccounts], + [bankAccounts, translate], ); const selectedBankAccountName = getSelectedAccountName(invoiceCollectionsAccountID ?? '-1'); diff --git a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx index c8f6595d6f4a..dc9217738b7a 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getXeroBankAccountsWithDefaultSelect, settingsPendingAction} from '@libs/PolicyUtils'; +import {getXeroBankAccounts, settingsPendingAction} from '@libs/PolicyUtils'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import variables from '@styles/variables'; @@ -27,7 +27,7 @@ function XeroBillPaymentAccountSelectorPage({policy}: WithPolicyConnectionsProps const {config} = policy?.connections?.xero ?? {}; const {reimbursementAccountID, syncReimbursedReports} = policy?.connections?.xero?.config.sync ?? {}; - const xeroSelectorOptions = useMemo(() => getXeroBankAccountsWithDefaultSelect(policy ?? undefined, reimbursementAccountID), [reimbursementAccountID, policy]); + const xeroSelectorOptions = useMemo(() => getXeroBankAccounts(policy ?? undefined, reimbursementAccountID), [reimbursementAccountID, policy]); const listHeaderComponent = useMemo( () => ( @@ -53,7 +53,7 @@ function XeroBillPaymentAccountSelectorPage({policy}: WithPolicyConnectionsProps ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, - [policyID], + [policyID, reimbursementAccountID], ); const listEmptyContent = useMemo( diff --git a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx index 330294a82d1c..ae541705d403 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getXeroBankAccountsWithDefaultSelect, settingsPendingAction} from '@libs/PolicyUtils'; +import {getXeroBankAccounts, settingsPendingAction} from '@libs/PolicyUtils'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import variables from '@styles/variables'; @@ -27,7 +27,7 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) { const {config} = policy?.connections?.xero ?? {}; const {invoiceCollectionsAccountID, syncReimbursedReports} = policy?.connections?.xero?.config.sync ?? {}; - const xeroSelectorOptions = useMemo(() => getXeroBankAccountsWithDefaultSelect(policy ?? undefined, invoiceCollectionsAccountID), [invoiceCollectionsAccountID, policy]); + const xeroSelectorOptions = useMemo(() => getXeroBankAccounts(policy ?? undefined, invoiceCollectionsAccountID), [invoiceCollectionsAccountID, policy]); const listHeaderComponent = useMemo( () => ( @@ -53,7 +53,7 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) { ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, - [policyID], + [policyID, invoiceCollectionsAccountID], ); const listEmptyContent = useMemo( diff --git a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx index 449e9a12c4a7..8531acf8f9c2 100644 --- a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx @@ -11,7 +11,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; -import {getXeroBankAccountsWithDefaultSelect} from '@libs/PolicyUtils'; +import {getXeroBankAccounts} from '@libs/PolicyUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -28,7 +28,7 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { const {config} = policy?.connections?.xero ?? {}; const xeroSelectorOptions = useMemo( - () => getXeroBankAccountsWithDefaultSelect(policy ?? undefined, config?.export?.nonReimbursableAccount), + () => getXeroBankAccounts(policy ?? undefined, config?.export?.nonReimbursableAccount), [config?.export?.nonReimbursableAccount, policy], ); @@ -58,7 +58,7 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); }, - [policyID, initiallyFocusedOptionKey], + [initiallyFocusedOptionKey, policyID, config?.export?.nonReimbursableAccount], ); const listEmptyContent = useMemo( From a881d6aabbac72216b75c1065f563407deb538fb Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 12 Aug 2024 15:41:21 +0200 Subject: [PATCH 6/6] add nullable --- src/libs/actions/connections/index.ts | 6 +++++- .../workspace/accounting/xero/advanced/XeroAdvancedPage.tsx | 4 ++-- .../xero/advanced/XeroBillPaymentAccountSelectorPage.tsx | 2 +- .../xero/advanced/XeroInvoiceAccountSelectorPage.tsx | 2 +- .../accounting/xero/export/XeroBankAccountSelectPage.tsx | 2 +- .../xero/export/XeroPreferredExporterSelectPage.tsx | 2 +- .../xero/export/XeroPurchaseBillDateSelectPage.tsx | 2 +- .../xero/export/XeroPurchaseBillStatusSelectorPage.tsx | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 921c1d0a2ed5..47a0e3a7ec0f 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -13,6 +13,10 @@ import type Policy from '@src/types/onyx/Policy'; type ConnectionNameExceptNetSuite = Exclude; +type Nullable = { + [P in keyof T]: T[P] | null; +}; + function removePolicyConnection(policyID: string, connectionName: PolicyConnectionName) { const optimisticData: OnyxUpdate[] = [ { @@ -73,7 +77,7 @@ function updatePolicyXeroConnectionConfig, - oldSettingValue?: Partial, + oldSettingValue?: Nullable>, ) { const optimisticData: OnyxUpdate[] = [ { diff --git a/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx index e7977497684f..287163ae69cc 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx @@ -66,7 +66,7 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) { { enabled: !autoSync?.enabled, }, - {enabled: autoSync?.enabled}, + {enabled: autoSync?.enabled ?? null}, ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.ENABLED], pendingFields)} @@ -89,7 +89,7 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) { { syncReimbursedReports: !sync?.syncReimbursedReports, }, - {syncReimbursedReports: sync?.syncReimbursedReports}, + {syncReimbursedReports: sync?.syncReimbursedReports ?? null}, ) } pendingAction={settingsPendingAction([CONST.XERO_CONFIG.SYNC_REIMBURSED_REPORTS], pendingFields)} diff --git a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx index dc9217738b7a..0e940435816a 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroBillPaymentAccountSelectorPage.tsx @@ -49,7 +49,7 @@ function XeroBillPaymentAccountSelectorPage({policy}: WithPolicyConnectionsProps { reimbursementAccountID: value, }, - {reimbursementAccountID}, + {reimbursementAccountID: reimbursementAccountID ?? null}, ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx index ae541705d403..de3b4be0b656 100644 --- a/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/advanced/XeroInvoiceAccountSelectorPage.tsx @@ -49,7 +49,7 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) { { invoiceCollectionsAccountID: value, }, - {invoiceCollectionsAccountID}, + {invoiceCollectionsAccountID: invoiceCollectionsAccountID ?? null}, ); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx index 8531acf8f9c2..4dfd2e92bd0c 100644 --- a/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroBankAccountSelectPage.tsx @@ -53,7 +53,7 @@ function XeroBankAccountSelectPage({policy}: WithPolicyConnectionsProps) { { nonReimbursableAccount: value, }, - {nonReimbursableAccount: config?.export?.nonReimbursableAccount}, + {nonReimbursableAccount: config?.export?.nonReimbursableAccount ?? null}, ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); diff --git a/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx index 0bdac1c6786e..1dd51f845d8a 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPreferredExporterSelectPage.tsx @@ -72,7 +72,7 @@ function XeroPreferredExporterSelectPage({policy}: WithPolicyConnectionsProps) { CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {exporter: row.value}, - {exporter: config?.export?.exporter}, + {exporter: config?.export?.exporter ?? null}, ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)); diff --git a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx index fd103edad1b0..57b37f13d648 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillDateSelectPage.tsx @@ -52,7 +52,7 @@ function XeroPurchaseBillDateSelectPage({policy}: WithPolicyConnectionsProps) { CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.EXPORT, {billDate: row.value}, - {billDate: config?.export?.billDate}, + {billDate: config?.export?.billDate ?? null}, ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT_PURCHASE_BILL_DATE_SELECT.getRoute(policyID)); diff --git a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx index 5f907f08bdf4..d1902f8a3c46 100644 --- a/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx +++ b/src/pages/workspace/accounting/xero/export/XeroPurchaseBillStatusSelectorPage.tsx @@ -59,7 +59,7 @@ function XeroPurchaseBillStatusSelectorPage({policy}: WithPolicyConnectionsProps { billStatus: {...config?.export?.billStatus, purchase: row.value}, }, - {billStatus: config?.export?.billStatus}, + {billStatus: config?.export?.billStatus ?? null}, ); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_XERO_BILL_STATUS_SELECTOR.getRoute(policyID));