Skip to content

Commit

Permalink
update selected bank account
Browse files Browse the repository at this point in the history
  • Loading branch information
hungvu193 committed May 3, 2024
1 parent 4daaa7f commit 45f2288
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/pages/workspace/accounting/xero/advanced/XeroAdvancedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand All @@ -19,9 +19,16 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();

const policyID = policy?.id ?? '';
const xeroConfig = policy?.connections?.xero?.config;
const {autoSync, pendingFields, sync} = xeroConfig ?? {};
const xeroData = policy?.connections?.xero?.data;
const xeroConfig = policy?.connections?.xero?.config;
const {autoSync, pendingFields, sync, } = xeroConfig ?? {};
const {bankAccounts} = policy?.connections?.xero?.data ?? {};

const selectedBankAccountName = useMemo(() => {
const {invoiceCollectionsAccountID} = sync ?? {};
const selectedAccount = (bankAccounts ?? []).find((bank) => bank.id === invoiceCollectionsAccountID);

return selectedAccount?.name ?? '';
}, [sync, bankAccounts]);

return (
<ConnectionLayout
Expand Down Expand Up @@ -78,7 +85,7 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) {
<OfflineWithFeedback pendingAction={pendingFields?.sync}>
<MenuItemWithTopDescription
shouldShowRightIcon
title={String(xeroData?.bankAccounts)}
title={String(bankAccounts)}
description={translate('workspace.xero.advancedConfig.xeroBillPaymentAccount')}
key={translate('workspace.xero.advancedConfig.xeroBillPaymentAccount')}
wrapperStyle={[styles.sectionMenuItemTopDescription]}
Expand All @@ -88,7 +95,7 @@ function XeroAdvancedPage({policy}: WithPolicyConnectionsProps) {
<OfflineWithFeedback pendingAction={pendingFields?.sync}>
<MenuItemWithTopDescription
shouldShowRightIcon
title={String(xeroData?.bankAccounts)}
title={String(selectedBankAccountName)}
description={translate('workspace.xero.advancedConfig.xeroInvoiceCollectionAccount')}
key={translate('workspace.xero.advancedConfig.xeroInvoiceCollectionAccount')}
wrapperStyle={[styles.sectionMenuItemTopDescription]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import RadioListItem from '@components/SelectionList/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import type {SelectorType} from '@components/SelectionScreen';
import SelectionScreen from '@components/SelectionScreen';
import Text from '@components/Text';
Expand Down

0 comments on commit 45f2288

Please sign in to comment.