Skip to content

Commit

Permalink
Merge pull request #41530 from Expensify/aldo_fix-preferred-exporter
Browse files Browse the repository at this point in the history
Fix Preferred exporter page + country crash
  • Loading branch information
aldo-expensify authored May 2, 2024
2 parents d0513b9 + 55a5cb4 commit 5808670
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ const ROUTES = {
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_PREFERRED_EXPORTER: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/preferred-exporter',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/export/quickbooks-online/preferred-exporter` as const,
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/preferred-exporter` as const,
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_OUT_OF_POCKET_EXPENSES: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/out-of-pocket-expense',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function updatePolicyConnectionConfig<TConnectionName extends ConnectionName, TS
policyID: string,
connectionName: TConnectionName,
settingName: TSettingName,
settingValue?: Partial<Connections[TConnectionName]['config'][TSettingName]>,
settingValue: Partial<Connections[TConnectionName]['config'][TSettingName]>,
) {
const optimisticData: OnyxUpdate[] = [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect, useMemo} from 'react';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import type {SectionListData} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -30,17 +30,8 @@ function QuickbooksOutOfPocketExpenseEntitySelectPage({policy}: WithPolicyConnec
const {reimbursableExpensesExportDestination, syncTax, syncLocations} = policy?.connections?.quickbooksOnline?.config ?? {};
const isLocationsEnabled = Boolean(syncLocations && syncLocations !== CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE);
const isTaxesEnabled = Boolean(syncTax);
const isTaxError = isTaxesEnabled && reimbursableExpensesExportDestination === CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.JOURNAL_ENTRY;
const isLocationError = isLocationsEnabled && reimbursableExpensesExportDestination !== CONST.QUICKBOOKS_REIMBURSABLE_ACCOUNT_TYPE.JOURNAL_ENTRY;
const policyID = policy?.id ?? '';

useEffect(() => {
if (!isTaxError && !isLocationError) {
return;
}
Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION);
}, [policyID, isTaxError, isLocationError]);

const data: CardListItem[] = useMemo(
() => [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CardListItem = ListItem & {
value: string;
};

function QuickBooksExportPreferredExporterPage({policy}: WithPolicyConnectionsProps) {
function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const {export: exportConfiguration} = policy?.connections?.quickbooksOnline?.config ?? {};
Expand Down Expand Up @@ -59,7 +59,7 @@ function QuickBooksExportPreferredExporterPage({policy}: WithPolicyConnectionsPr
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
>
<ScreenWrapper testID={QuickBooksExportPreferredExporterPage.displayName}>
<ScreenWrapper testID={QuickbooksPreferredExporterConfigurationPage.displayName}>
<HeaderWithBackButton title={translate('workspace.qbo.preferredExporter')} />
<SelectionList
headerContent={
Expand All @@ -78,6 +78,6 @@ function QuickBooksExportPreferredExporterPage({policy}: WithPolicyConnectionsPr
);
}

QuickBooksExportPreferredExporterPage.displayName = 'QuickBooksExportPreferredExporterPage';
QuickbooksPreferredExporterConfigurationPage.displayName = 'QuickbooksPreferredExporterConfigurationPage';

export default withPolicyConnections(QuickBooksExportPreferredExporterPage);
export default withPolicyConnections(QuickbooksPreferredExporterConfigurationPage);
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function QuickbooksImportPage({policy}: WithPolicyProps) {
},
];

if (policy?.connections?.quickbooksOnline.data.country !== CONST.COUNTRY.US) {
if (policy?.connections?.quickbooksOnline?.data?.country !== CONST.COUNTRY.US) {
sections.push({
description: translate('workspace.accounting.taxes'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_TAXES.getRoute(policyID)),
Expand Down

0 comments on commit 5808670

Please sign in to comment.