Skip to content

Commit

Permalink
create xero utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lakchote committed May 1, 2024
1 parent 33a496e commit 89f9373
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, PolicyCategories, PolicyEmployeeList, PolicyTagList, PolicyTags, TaxRate} from '@src/types/onyx';
import type {PolicyFeatureName, Rate} from '@src/types/onyx/Policy';
import type {PolicyFeatureName, Rate, Tenant} from '@src/types/onyx/Policy';
import type PolicyEmployee from '@src/types/onyx/PolicyEmployee';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -390,6 +390,20 @@ function canSendInvoice(policies: OnyxCollection<Policy>): boolean {
return getActiveAdminWorkspaces(policies).length > 0;
}

/** Get the Xero organizations connected to the policy */
function getXeroTenants(policy: Policy | undefined): 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 ?? [];
};

function findCurrentXeroOrganization(tenants: Tenant[] | undefined, organizationID: string | undefined): Tenant | undefined {
return tenants?.find((tenant) => tenant.id === organizationID);
}

export {
getActivePolicies,
hasAccountingConnections,
Expand Down Expand Up @@ -435,6 +449,8 @@ export {
getPolicy,
getActiveAdminWorkspaces,
canSendInvoice,
getXeroTenants,
findCurrentXeroOrganization,
};

export type {MemberEmailsToAccountIDs};

0 comments on commit 89f9373

Please sign in to comment.