Skip to content

Commit

Permalink
Merge pull request #41044 from Expensify/aldo_sync-command
Browse files Browse the repository at this point in the history
Add QBO Sync functionality
  • Loading branch information
aldo-expensify authored Apr 26, 2024
2 parents 6acc903 + fa1e861 commit 42d4ed7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,8 @@ export default {
return 'Checking QuickBooks Online connection';
case 'quickbooksOnlineImportMain':
return 'Importing your QuickBooks Online data';
case 'startingImport':
return 'Importing your QuickBooks Online data';
default: {
return `Translation missing for stage: ${stage}`;
}
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,8 @@ export default {
return 'Revisando conexión a QuickBooks Online';
case 'quickbooksOnlineImportMain':
return 'Importando datos desde QuickBooks Online';
case 'startingImport':
return 'Importando datos desde QuickBooks Online';
default: {
return `Translation missing for stage: ${stage}`;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libs/API/parameters/SyncPolicyToQuickbooksOnlineParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type SyncPolicyToQuickbooksOnlineParams = {
policyID: string;
idempotencyKey: string;
};

export default SyncPolicyToQuickbooksOnlineParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type {default as BeginSignInParams} from './BeginSignInParams';
export type {default as CloseAccountParams} from './CloseAccountParams';
export type {default as ConnectBankAccountParams} from './ConnectBankAccountParams';
export type {default as ConnectPolicyToQuickbooksOnlineParams} from './ConnectPolicyToQuickbooksOnlineParams';
export type {default as SyncPolicyToQuickbooksOnlineParams} from './SyncPolicyToQuickbooksOnlineParams';
export type {default as DeleteContactMethodParams} from './DeleteContactMethodParams';
export type {default as DeletePaymentBankAccountParams} from './DeletePaymentBankAccountParams';
export type {default as DeletePaymentCardParams} from './DeletePaymentCardParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ type WriteCommandParameters = {

const READ_COMMANDS = {
CONNECT_POLICY_TO_QUICKBOOKS_ONLINE: 'ConnectPolicyToQuickbooksOnline',
SYNC_POLICY_TO_QUICKBOOKS_ONLINE: 'SyncPolicyToQuickbooksOnline',
OPEN_REIMBURSEMENT_ACCOUNT_PAGE: 'OpenReimbursementAccountPage',
OPEN_WORKSPACE_VIEW: 'OpenWorkspaceView',
GET_MAPBOX_ACCESS_TOKEN: 'GetMapboxAccessToken',
Expand Down Expand Up @@ -471,6 +472,7 @@ type ReadCommand = ValueOf<typeof READ_COMMANDS>;

type ReadCommandParameters = {
[READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE]: Parameters.ConnectPolicyToQuickbooksOnlineParams;
[READ_COMMANDS.SYNC_POLICY_TO_QUICKBOOKS_ONLINE]: Parameters.SyncPolicyToQuickbooksOnlineParams;
[READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE]: Parameters.OpenReimbursementAccountPageParams;
[READ_COMMANDS.OPEN_WORKSPACE_VIEW]: Parameters.OpenWorkspaceViewParams;
[READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN]: EmptyObject;
Expand Down
36 changes: 32 additions & 4 deletions src/libs/actions/connections/QuickBooksOnline.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
import type {ConnectPolicyToQuickbooksOnlineParams} from '@libs/API/parameters';
import type {OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import type {ConnectPolicyToQuickbooksOnlineParams, SyncPolicyToQuickbooksOnlineParams} from '@libs/API/parameters';
import {READ_COMMANDS} from '@libs/API/types';
import {getCommandURL} from '@libs/ApiUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

function getQuickBooksOnlineSetupLink(policyID: string) {
const params: ConnectPolicyToQuickbooksOnlineParams = {policyID};
const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE, shouldSkipWebProxy: true});
return commandURL + new URLSearchParams(params).toString();
}

// More action functions will be added later
// eslint-disable-next-line import/prefer-default-export
export {getQuickBooksOnlineSetupLink};
function syncConnection(policyID: string) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`,
value: {
stageInProgress: CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT,
connectionName: CONST.POLICY.CONNECTIONS.NAME.QBO,
},
},
];
const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`,
value: null,
},
];
const parameters: SyncPolicyToQuickbooksOnlineParams = {
policyID,
idempotencyKey: policyID,
};
API.read(READ_COMMANDS.SYNC_POLICY_TO_QUICKBOOKS_ONLINE, parameters, {optimisticData, failureData});
}

export {getQuickBooksOnlineSetupLink, syncConnection};
8 changes: 6 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import Section from '@components/Section';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import type ThreeDotsMenuProps from '@components/ThreeDotsMenu/types';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import {removePolicyConnection} from '@libs/actions/connections';
import {syncConnection} from '@libs/actions/connections/QuickBooksOnline';
import Navigation from '@navigation/Navigation';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper';
Expand All @@ -45,6 +47,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {isSmallScreenWidth, windowWidth} = useWindowDimensions();
const [threeDotsMenuPosition, setThreeDotsMenuPosition] = useState<AnchorPosition>({horizontal: 0, vertical: 0});
const [isDisconnectModalOpen, setIsDisconnectModalOpen] = useState(false);
Expand All @@ -58,15 +61,16 @@ function PolicyAccountingPage({policy, connectionSyncProgress}: PolicyAccounting
{
icon: Expensicons.Sync,
text: translate('workspace.accounting.syncNow'),
onSelected: () => {},
onSelected: () => syncConnection(policyID),
disabled: isOffline,
},
{
icon: Expensicons.Trashcan,
text: translate('workspace.accounting.disconnect'),
onSelected: () => setIsDisconnectModalOpen(true),
},
],
[translate],
[translate, policyID, isOffline],
);

const menuItems: MenuItemProps[] = useMemo(() => {
Expand Down

0 comments on commit 42d4ed7

Please sign in to comment.