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

QBO operations 1:1 Part 4 #48080

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ const WRITE_COMMANDS = {
UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES: 'UpdateQuickbooksOnlineEnableNewCategories',
UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR: 'UpdateQuickbooksOnlineAutoCreateVendor',
UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount',
UPDATE_QUICKBOOKS_ONLINE_AUTO_SYNC: 'UpdateQuickbooksOnlineAutoSync',
UPDATE_QUICKBOOKS_ONLINE_SYNC_PEOPLE: 'UpdateQuickbooksOnlineSyncPeople',
UPDATE_QUICKBOOKS_ONLINE_REIMBURSEMENT_ACCOUNT_ID: 'UpdateQuickbooksOnlineReimbursementAccountID',
UPDATE_QUICKBOOKS_ONLINE_EXPORT: 'UpdateQuickbooksOnlineExport',
UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations',
REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection',
SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled',
Expand Down Expand Up @@ -575,6 +579,10 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_SYNC]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_PEOPLE]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSEMENT_ACCOUNT_ID]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams;
[WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams;
[WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams;
[WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams;
Expand Down
323 changes: 322 additions & 1 deletion src/libs/actions/connections/QuickbooksOnline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,87 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES, parameters, {optimisticData, failureData, successData});
}

function updateQuickbooksOnlineAutoSync(policyID: string, settingValue: boolean) {
const optimisticData: OnyxUpdate[] = [
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
autoSync: {
enabled: settingValue ?? null,
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: null,
},
},
},
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
autoSync: {
enabled: !settingValue ?? null,
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
},
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
autoSync: {
enabled: settingValue ?? null,
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC]: null,
},
},
},
},
},
},
];

const parameters: UpdateQuickbooksOnlineGenericTypeParams = {
policyID,
settingValue: JSON.stringify(settingValue),
idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.AUTO_SYNC),
};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_SYNC, parameters, {optimisticData, failureData, successData});
}

function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: boolean) {
const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -171,6 +252,81 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue:
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR, parameters, {optimisticData, failureData, successData});
}

function updateQuickbooksOnlineSyncPeople(policyID: string, settingValue: boolean) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: settingValue ?? null,
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: null,
},
},
},
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: settingValue ?? null,
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
},
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: settingValue ?? null,
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE]: null,
},
},
},
},
},
},
];

const parameters: UpdateQuickbooksOnlineGenericTypeParams = {
policyID,
settingValue: JSON.stringify(settingValue),
idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_PEOPLE),
};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_PEOPLE, parameters, {optimisticData, failureData, successData});
}

function updateQuickbooksOnlineReimbursableExpensesAccount<TConnectionName extends ConnectionNameExceptNetSuite, TSettingName extends keyof Connections[TConnectionName]['config']>(
policyID: string,
settingValue: Partial<Connections[TConnectionName]['config'][TSettingName]>,
Expand Down Expand Up @@ -249,4 +405,169 @@ function updateQuickbooksOnlineReimbursableExpensesAccount<TConnectionName exten
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData});
}

export {getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, updateQuickbooksOnlineAutoCreateVendor, updateQuickbooksOnlineReimbursableExpensesAccount};
function updateQuickbooksOnlineReimbursementAccountID(policyID: string, currentValue: string | undefined, settingValue: string) {
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: settingValue ?? null,
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: null,
},
},
},
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: currentValue ?? null,
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
},
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: settingValue ?? null,
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: null,
},
errorFields: {
[CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID]: null,
},
},
},
},
},
},
];

const parameters: UpdateQuickbooksOnlineGenericTypeParams = {
policyID,
settingValue,
idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID),
};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSEMENT_ACCOUNT_ID, parameters, {optimisticData, failureData, successData});
}

function updateQuickbooksOnlinePreferredExporter(policyID: string, currentValue: string | undefined, settingValue: string) {
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
export: {
exporter: settingValue ?? null,
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.EXPORT]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
errorFields: {
exporter: null,
},
},
},
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
export: {
exporter: currentValue ?? null,
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.EXPORT]: null,
},
errorFields: {
exporter: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
},
},
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
[CONST.POLICY.CONNECTIONS.NAME.QBO]: {
config: {
export: {
exporter: settingValue ?? null,
shubham1206agra marked this conversation as resolved.
Show resolved Hide resolved
},
pendingFields: {
[CONST.QUICK_BOOKS_CONFIG.EXPORT]: null,
},
errorFields: {
exporter: null,
},
},
},
},
},
},
];

const parameters: UpdateQuickbooksOnlineGenericTypeParams = {
policyID,
settingValue: JSON.stringify({exporter: settingValue}),
idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.EXPORT),
};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT, parameters, {optimisticData, failureData, successData});
}

export {
getQuickbooksOnlineSetupLink,
updateQuickbooksOnlineEnableNewCategories,
updateQuickbooksOnlineAutoCreateVendor,
updateQuickbooksOnlineReimbursableExpensesAccount,
updateQuickbooksOnlineAutoSync,
updateQuickbooksOnlineSyncPeople,
updateQuickbooksOnlineReimbursementAccountID,
updateQuickbooksOnlinePreferredExporter,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {ListItem} from '@components/SelectionList/types';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Connections from '@libs/actions/connections';
import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline';
import Navigation from '@libs/Navigation/Navigation';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
Expand Down Expand Up @@ -55,10 +55,12 @@ function QuickbooksAccountSelectPage({policy}: WithPolicyConnectionsProps) {

const saveSelection = useCallback(
({value}: SelectorType) => {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID, value);
if (value !== reimbursementAccountID) {
QuickbooksOnline.updateQuickbooksOnlineReimbursementAccountID(policyID, reimbursementAccountID, value);
}
Navigation.goBack(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID));
},
[policyID],
[policyID, reimbursementAccountID],
);

const listEmptyContent = useMemo(
Expand Down
Loading
Loading