Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define type definition for the connections property #37806

Merged
merged 17 commits into from
Mar 11, 2024
114 changes: 106 additions & 8 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/naming-convention */
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type * as OnyxCommon from './OnyxCommon';
Expand Down Expand Up @@ -68,18 +69,115 @@ type TaxRatesWithDefault = {
taxes: TaxRates;
};

// These types are for the Integration connections for a policy (eg. Quickbooks, Xero, etc).
// This data is not yet used in the codebase which is why it is given a very generic type, but the data is being put into Onyx for future use.
// Once the data is being used, these types should be defined appropriately.
type ConnectionLastSync = Record<string, unknown>;
type ConnectionData = Record<string, unknown>;
type ConnectionConfig = Record<string, unknown>;
type Connection = {
type ConnectionLastSync = {
successfulDate?: string;
errorDate?: string;
isSuccessful: boolean;
source: 'DIRECT' | 'EXPENSIFYWEB' | 'EXPENSIFYAPI' | 'AUTOSYNC' | 'AUTOAPPROVE';
};

type Account = {
glCode?: string;
name: string;
currency: string;
id: string;
};

type Employee = {
id: string;
firstName?: string;
lastName?: string;
name: string;
email: string;
};

type Vendor = {
id: string;
name: string;
currency: string;
email: string;
};

type TaxCode = {
totalTaxRateVal: string;
simpleName: string;
taxCodeRef: string;
taxRateRefs: Record<string, string>;
name: string;
};

type QuickBooksOnlineConnectionData = {
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
country: string;
edition: string;
homeCurrency: string;
isMultiCurrencyEnabled: boolean;

journalEntryAccounts: Account[];
bankAccounts: Account[];
creditCards: Account[];
accountsReceivable: Account[];
accountsPayable: Account[];
otherCurrentAssetAccounts: Account[];

taxCodes: TaxCode[];
employees: Employee[];
vendors: Vendor[];
};

type IntegrationEntityMap = 'NONE' | 'DEFAULT' | 'TAG' | 'REPORT_FIELD';

type ConnectionConfig = {
realmId: string;
credentials: {
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
access_token: string;
refresh_token: string;
expires: number;
companyID: string;
readlmId: string;
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
scope: string;
companyName: string;
token_type: string;
};
companyName: string;
autoSync: {
jobID: string;
enabled: boolean;
};
syncPeople: boolean;
syncItems: boolean;
markChecksToBePrinted: boolean;
reimbursableExpensesExportDestination: IntegrationEntityMap;
nonReimbursableExpensesExportDestination: IntegrationEntityMap;

reimbursableExpensesAccount?: string;
nonReimbursableExpensesAccount?: string;
autoCreateVendor: boolean;
hasChosenAutoSyncOption: boolean;
syncClasses: IntegrationEntityMap;
syncCustomers: IntegrationEntityMap;
syncLocations: IntegrationEntityMap;
exportDate: string;
lastConfigurationTime: number;
syncTax: boolean;
enableNewCategories: boolean;
export: {
exporter: string;
};
};
type Connection<ConnectionData> = {
lastSync?: ConnectionLastSync;
data: ConnectionData;
config: ConnectionConfig;
};

type Connections = {
quickbooksOnline: {
lastSync?: ConnectionLastSync;
data: Connection<QuickBooksOnlineConnectionData>;
config: ConnectionConfig;
};
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
};

type AutoReportingOffset = number | ValueOf<typeof CONST.POLICY.AUTO_REPORTING_OFFSET>;

type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
Expand Down Expand Up @@ -225,7 +323,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
chatReportIDAnnounce?: number;

/** All the integration connections attached to the policy */
connections?: Record<string, Connection>;
connections?: Connections;

/** Whether the Categories feature is enabled */
areCategoriesEnabled?: boolean;
Expand Down
Loading