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

Fix Preferred exporter page + country crash #41530

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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]>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this here because settingValue is NOT optional. This was causing backend server errors.

) {
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(
Comment on lines -37 to -43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was calling updatePolicyConnectionConfig with an invalid value, which did nothing and is an anti-pattern in our app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix this as part 1. of this issue: https://github.com/Expensify/Expensify/issues/390731

() => [
{
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) {
Copy link
Contributor

@hayata-suenaga hayata-suenaga May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: should we also mark these fields optional in the TS definition (Policy.ts)?

Screenshot 2024-05-02 at 1 08 04 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm that is probably a good idea, then we wouldn't get a random crash because our types would catch it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but it breaks all calls to updatePolicyConnectionConfig because something goes wrong with the parameter types:

image

I'll leave investigating this for another occasion

sections.push({
description: translate('workspace.accounting.taxes'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_TAXES.getRoute(policyID)),
Expand Down
Loading