Skip to content

Commit

Permalink
use xero utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lakchote committed May 1, 2024
1 parent 89f9373 commit 5f33ba7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, PolicyConnectionSyncProgress} from '@src/types/onyx';
import type {PolicyConnectionName, Tenant} from '@src/types/onyx/Policy';
import type {PolicyConnectionName} from '@src/types/onyx/Policy';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';
import { findCurrentXeroOrganization, getXeroTenants } from '@libs/PolicyUtils';

type PolicyAccountingPageOnyxProps = {
connectionSyncProgress: OnyxEntry<PolicyConnectionSyncProgress>;
Expand Down Expand Up @@ -116,15 +117,9 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting

const policyConnectedToXero = connectedIntegration === CONST.POLICY.CONNECTIONS.NAME.XERO;

const tenants = useMemo<Tenant[]>(() => {
// Due to the way optional chain is being handled in this useMemo we are forced to use this approach to properly handle undefined values
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
if (!policy || !policy.connections || !policy.connections.xero || !policy.connections.xero.data) {
return [];
}
return policy?.connections?.xero?.data?.tenants ?? [];
}, [policy]);
const currentXeroOrganization = tenants.find((tenant) => tenant.id === policy?.connections?.xero.config.tenantID);
const tenants = useMemo(() => getXeroTenants(policy), [policy]);

const currentXeroOrganization = findCurrentXeroOrganization(tenants, policy?.connections?.xero?.config?.tenantID);

const overflowMenu: ThreeDotsMenuProps['menuItems'] = useMemo(
() => [
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/accounting/xero/XeroImportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import withPolicy from '@pages/workspace/withPolicy';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Tenant} from '@src/types/onyx/Policy';
import { getXeroTenants } from '@libs/PolicyUtils';

function XeroImportPage({policy}: WithPolicyProps) {
const {translate} = useLocalize();
Expand All @@ -22,7 +22,7 @@ function XeroImportPage({policy}: WithPolicyProps) {
const policyID = policy?.id ?? '';
const {importCustomers, importTaxRates, importTrackingCategories, pendingFields} = policy?.connections?.xero?.config ?? {};

const tenants = useMemo<Tenant[]>(() => policy?.connections?.xero?.data?.tenants ?? [], [policy?.connections?.xero.data.tenants]);
const tenants = useMemo(() => getXeroTenants(policy ?? undefined), [policy]);
const currentXeroOrganization = tenants.find((tenant) => tenant.id === policy?.connections?.xero.config.tenantID);

const sections = useMemo(
Expand Down

0 comments on commit 5f33ba7

Please sign in to comment.