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

Offline and errors pattern in Quickbooks Online integration #46511

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
263743b
Initial refactor of import pages
zfurtak Jul 30, 2024
362d521
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Jul 30, 2024
ab278cb
Adjusted import pages and refactored advanced page
zfurtak Jul 30, 2024
2f73caa
Further refactor
zfurtak Jul 31, 2024
a98872e
Export pages refactor
zfurtak Aug 1, 2024
cabe722
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 1, 2024
4a2c570
Add error/offline patterns and refactor advanced pages
zfurtak Aug 2, 2024
5de6c69
Adding missing patterns
zfurtak Aug 2, 2024
ee86a23
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 5, 2024
93c42d1
Revert max_request_retry value
zfurtak Aug 5, 2024
def4201
Adjustments
zfurtak Aug 6, 2024
0cff3d9
Adjustments
zfurtak Aug 6, 2024
c109a1d
Adjusted to review
zfurtak Aug 7, 2024
e609478
Added needed conditions
zfurtak Aug 7, 2024
0b181b3
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 7, 2024
26a9448
Adjust error patterns
zfurtak Aug 7, 2024
a5e667a
Fix console errors
zfurtak Aug 7, 2024
0ca45ed
Adjusted to review
zfurtak Aug 7, 2024
1600fe6
Style fix
zfurtak Aug 7, 2024
f95c601
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 8, 2024
21d34d0
Rerun the checks
zfurtak Aug 8, 2024
893c8b1
Added missing setting
zfurtak Aug 8, 2024
a765f9b
Adjust code to react compiler
zfurtak Aug 8, 2024
12c81e2
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 13, 2024
3c54077
Fix react compiler errors
zfurtak Aug 13, 2024
ce308ed
Remove opacity from empty list
zfurtak Aug 14, 2024
ee8a820
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 14, 2024
650192a
Remove opacity from empty list
zfurtak Aug 14, 2024
1449d8a
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 26, 2024
e5faeb4
Merge branch 'main' into @zfurtak/qbo-error-messages
zfurtak Aug 27, 2024
9664819
Merge main
zfurtak Sep 4, 2024
14875d2
Merge main
zfurtak Sep 4, 2024
5e556ff
Added generic types for oldSettingValue
zfurtak Sep 4, 2024
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
4 changes: 2 additions & 2 deletions src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function updatePolicyConnectionConfig<TConnectionName extends ConnectionNameExce
connectionName: TConnectionName,
settingName: TSettingName,
settingValue: Partial<Connections[TConnectionName]['config'][TSettingName]>,
oldSettingValue?: Partial<Connections[TConnectionName]['config'][TSettingName]>,
) {
const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -100,7 +101,7 @@ function updatePolicyConnectionConfig<TConnectionName extends ConnectionNameExce
connections: {
[connectionName]: {
config: {
[settingName]: settingValue ?? null,
[settingName]: oldSettingValue ?? null,
pendingFields: createPendingFields(settingName, settingValue, null),
errorFields: createErrorFields(settingName, settingValue, ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')),
},
Expand All @@ -118,7 +119,6 @@ function updatePolicyConnectionConfig<TConnectionName extends ConnectionNameExce
connections: {
[connectionName]: {
config: {
[settingName]: settingValue ?? null,
pendingFields: createPendingFields(settingName, settingValue, null),
errorFields: createErrorFields(settingName, settingValue, null),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function QuickbooksAccountSelectPage({policy}: WithPolicyConnectionsProps) {

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

const listEmptyContent = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,41 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) {
switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.autoSyncDescription'),
isActive: !!qboConfig?.autoSync?.enabled,
onToggle: () =>
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.AUTO_SYNC, {
enabled: !qboConfig?.autoSync?.enabled,
}),
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.AUTO_SYNC,
{
enabled: !qboConfig?.autoSync?.enabled,
},
{
enabled: qboConfig?.autoSync?.enabled,
},
),
subscribedSetting: CONST.QUICKBOOKS_CONFIG.ENABLED,
},
{
title: translate('workspace.qbo.advancedConfig.inviteEmployees'),
subtitle: translate('workspace.qbo.advancedConfig.inviteEmployeesDescription'),
switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.inviteEmployeesDescription'),
isActive: !!qboConfig?.syncPeople,
onToggle: () => Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.SYNC_PEOPLE, !qboConfig?.syncPeople),
onToggle: () =>
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.SYNC_PEOPLE, !qboConfig?.syncPeople, qboConfig?.syncPeople),
subscribedSetting: CONST.QUICKBOOKS_CONFIG.SYNC_PEOPLE,
},
{
title: translate('workspace.qbo.advancedConfig.createEntities'),
subtitle: translate('workspace.qbo.advancedConfig.createEntitiesDescription'),
switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.createEntitiesDescription'),
isActive: !!qboConfig?.autoCreateVendor,
onToggle: () => Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR, !qboConfig?.autoCreateVendor),
onToggle: () =>
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR,
!qboConfig?.autoCreateVendor,
qboConfig?.autoCreateVendor,
),
subscribedSetting: CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR,
},
{
Expand All @@ -109,6 +125,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) {
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID,
isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id,
qboConfig?.collectionAccountID,
),
subscribedSetting: CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ function QuickbooksInvoiceAccountSelectPage({policy}: WithPolicyConnectionsProps

const updateAccount = useCallback(
({value}: SelectorType) => {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID, value);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID, value, qboConfig?.collectionAccountID);
Navigation.goBack(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID));
},
[policyID],
[policyID, qboConfig?.collectionAccountID],
);

const listEmptyContent = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ function QuickbooksCompanyCardExpenseAccountSelectPage({policy}: WithPolicyConne
const selectExportAccount = useCallback(
(row: CardListItem) => {
if (row.value.id !== qboConfig?.nonReimbursableExpensesAccount?.id) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT, row.value);
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT,
row.value,
qboConfig?.nonReimbursableExpensesAccount,
);
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT.getRoute(policyID));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function QuickbooksExportDateSelectPage({policy}: WithPolicyConnectionsProps) {
const selectExportDate = useCallback(
(row: CardListItem) => {
if (row.value !== qboConfig?.exportDate) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.EXPORT_DATE, row.value);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.EXPORT_DATE, row.value, qboConfig?.exportDate);
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_DATE_SELECT.getRoute(policyID));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function QuickbooksExportInvoiceAccountSelectPage({policy}: WithPolicyConnection
const selectExportInvoice = useCallback(
(row: CardListItem) => {
if (row.value.id !== qboConfig?.receivableAccount?.id) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.RECEIVABLE_ACCOUNT, row.value);
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.RECEIVABLE_ACCOUNT, row.value, qboConfig?.receivableAccount);
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_INVOICE_ACCOUNT_SELECT.getRoute(policyID));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ function QuickbooksNonReimbursableDefaultVendorSelectPage({policy}: WithPolicyCo
const selectVendor = useCallback(
(row: CardListItem) => {
if (row.value !== qboConfig?.nonReimbursableBillDefaultVendor) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, row.value);
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR,
row.value,
qboConfig?.nonReimbursableBillDefaultVendor,
);
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT.getRoute(policyID));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ function QuickbooksOutOfPocketExpenseAccountSelectPage({policy}: WithPolicyConne
const selectExportAccount = useCallback(
(row: CardListItem) => {
if (row.value.id !== qboConfig?.reimbursableExpensesAccount?.id) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, row.value);
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT,
row.value,
qboConfig?.reimbursableExpensesAccount,
);
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES.getRoute(policyID));
},
[qboConfig?.reimbursableExpensesAccount?.id, policyID],
[qboConfig?.reimbursableExpensesAccount, policyID],
);

const listEmptyContent = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec
const selectExporter = useCallback(
(row: CardListItem) => {
if (row.value !== qboConfig?.export?.exporter) {
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.EXPORT, {exporter: row.value});
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.EXPORT, {exporter: row.value}, qboConfig?.export);
zfurtak marked this conversation as resolved.
Show resolved Hide resolved
}
Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_PREFERRED_EXPORTER.getRoute(policyID));
},
[qboConfig?.export?.exporter, policyID],
[qboConfig?.export, policyID],
);

const headerContent = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ function QuickbooksChartOfAccountsPage({policy}: WithPolicyProps) {
shouldPlaceSubtitleBelowSwitch
isActive={!!qboConfig?.enableNewCategories}
onToggle={() =>
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES, !qboConfig?.enableNewCategories)
Connections.updatePolicyConnectionConfig(
policyID,
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES,
!qboConfig?.enableNewCategories,
qboConfig?.enableNewCategories,
)
}
pendingAction={settingsPendingAction([CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES], qboConfig?.pendingFields)}
errors={ErrorUtils.getLatestErrorField(qboConfig, CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function QuickbooksClassesPage({policy}: WithPolicyProps) {
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.SYNC_CLASSES,
isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG,
qboConfig?.syncClasses,
)
}
pendingAction={settingsPendingAction([CONST.QUICKBOOKS_CONFIG.SYNC_CLASSES], qboConfig?.pendingFields)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function QuickbooksCustomersPage({policy}: WithPolicyProps) {
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.SYNC_CUSTOMERS,
isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG,
qboConfig?.syncCustomers,
)
}
pendingAction={settingsPendingAction([CONST.QUICKBOOKS_CONFIG.SYNC_CUSTOMERS], qboConfig?.pendingFields)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function QuickbooksLocationsPage({policy}: WithPolicyProps) {
CONST.POLICY.CONNECTIONS.NAME.QBO,
CONST.QUICKBOOKS_CONFIG.SYNC_LOCATIONS,
isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG,
qboConfig?.syncLocations,
)
}
errors={ErrorUtils.getLatestErrorField(qboConfig, CONST.QUICKBOOKS_CONFIG.SYNC_LOCATIONS)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function QuickbooksTaxesPage({policy}: WithPolicyProps) {
title={translate('workspace.accounting.import')}
switchAccessibilityLabel={translate('workspace.accounting.taxes')}
isActive={!!qboConfig?.syncTax}
onToggle={() => Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.SYNC_TAX, !qboConfig?.syncTax)}
onToggle={() =>
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICKBOOKS_CONFIG.SYNC_TAX, !qboConfig?.syncTax, qboConfig?.syncTax)
}
pendingAction={settingsPendingAction([CONST.QUICKBOOKS_CONFIG.SYNC_TAX], qboConfig?.pendingFields)}
errors={ErrorUtils.getLatestErrorField(qboConfig, CONST.QUICKBOOKS_CONFIG.SYNC_TAX)}
onCloseError={() => clearQBOErrorField(policyID, CONST.QUICKBOOKS_CONFIG.SYNC_TAX)}
Expand Down
Loading