Skip to content
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
56 changes: 43 additions & 13 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,25 +1042,25 @@ const ROUTES = {
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/company-card-expense-account/account-select',
getRoute: (policyID: string | undefined) => {
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account/account-select` as const;
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account/account-select` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/company-card-expense-account/card-select',
getRoute: (policyID: string | undefined) => {
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_SELECT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account/card-select` as const;
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account/card-select` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/company-card-expense-account/default-vendor-select',
getRoute: (policyID: string | undefined) => {
getRoute: (policyID?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT route');
}
Expand All @@ -1069,39 +1069,69 @@ const ROUTES = {
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/company-card-expense-account',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/company-card-expense-account` as const, backTo);
},
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_DESKTOP_ADVANCED: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/advanced',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/advanced` as const,
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_DATE_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/date-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/date-select` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_DATE_SELECT route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/date-select` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_PREFERRED_EXPORTER: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/preferred-exporter',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/preferred-exporter` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_PREFERRED_EXPORTER route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/preferred-exporter` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense/account-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/account-select` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/account-select` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense/entity-select',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/entity-select` as const,
getRoute: (policyID?: string, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT route');
}
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/entity-select` as const, backTo);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export',
getRoute: (policyID: string | undefined) => {
getRoute: (policyID: string | undefined, backTo?: string) => {
if (!policyID) {
Log.warn('Invalid policyID is used to build the POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT route');
}
return `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export` as const;
return getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-desktop/export` as const, backTo, false);
},
},
POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_MODAL: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {QBDNonReimbursableExportAccountType} from '@src/types/onyx/Policy';
type UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams = {
policyID: string;
nonReimbursableExpensesExportDestination: QBDNonReimbursableExportAccountType;
nonReimbursableExpensesAccount: string;
nonReimbursableExpensesAccount?: string;
nonReimbursableBillDefaultVendor: string;
idempotencyKey: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {QBDReimbursableExportAccountType} from '@src/types/onyx/Policy';
type UpdateQuickbooksDesktopExpensesExportDestinationTypeParams = {
policyID: string;
reimbursableExpensesExportDestination: QBDReimbursableExportAccountType;
reimbursableExpensesAccount: string;
reimbursableExpensesAccount?: string;
idempotencyKey: string;
};

Expand Down
19 changes: 19 additions & 0 deletions src/libs/Navigation/helpers/goBackFromExportConnection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import replaceCompanyCardsRoute from './replaceCompanyCardsRoute';

/**
* If export company card value is changed to unsupported - we should redirect user directly to card details view
* If not, just regular go back
*/
function goBackFromExportConnection(shouldGoBackToSpecificRoute: boolean, backTo?: string) {
const feature = CONST.UPGRADE_FEATURE_INTRO_MAPPING.companyCards;

if (!(shouldGoBackToSpecificRoute && backTo?.includes(feature.alias))) {
return Navigation.goBack();
}
const companyCardDetailsPage = replaceCompanyCardsRoute(backTo);
return Navigation.goBack(companyCardDetailsPage);
}

export default goBackFromExportConnection;
6 changes: 6 additions & 0 deletions src/libs/Navigation/helpers/replaceCompanyCardsRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {Route as Routes} from '@src/ROUTES';

const replaceCompanyCardsRoute = (route: string): Routes => {
return route?.replace(/\/edit\/export$/, '') as Routes;
};
export default replaceCompanyCardsRoute;
9 changes: 9 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,36 +458,45 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_SELECT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT_COMPANY_CARD_SELECT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_DEFAULT_VENDOR_SELECT]: {
policyID: string;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_COMPANY_CARD_EXPENSE_ACCOUNT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_ADVANCED]: {
policyID: string;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_DATE_SELECT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_PREFERRED_EXPORTER]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_EXPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_DESKTOP_SETUP_MODAL]: {
policyID: string;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/actions/connections/QuickbooksDesktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function getQuickbooksDesktopCodatSetupLink(policyID: string) {
return API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_DESKTOP, params);
}

function updateQuickbooksDesktopExpensesExportDestination<TConfigUpdate extends {reimbursable: QBDReimbursableExportAccountType; reimbursableAccount: string}>(
function updateQuickbooksDesktopExpensesExportDestination<TConfigUpdate extends {reimbursable: QBDReimbursableExportAccountType; reimbursableAccount?: string}>(
policyID: string,
configUpdate: TConfigUpdate,
configCurrentData: Partial<TConfigUpdate>,
Expand All @@ -339,22 +339,22 @@ function updateQuickbooksDesktopExpensesExportDestination<TConfigUpdate extends
const parameters: UpdateQuickbooksDesktopExpensesExportDestinationTypeParams = {
policyID,
reimbursableExpensesExportDestination: configUpdate.reimbursable,
reimbursableExpensesAccount: configUpdate.reimbursableAccount,
reimbursableExpensesAccount: configUpdate?.reimbursableAccount,
idempotencyKey: String(CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE),
};

API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_DESKTOP_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, parameters, onyxData);
}

function updateQuickbooksCompanyCardExpenseAccount<
TConfigUpdate extends {nonReimbursable: QBDNonReimbursableExportAccountType; nonReimbursableAccount: string; nonReimbursableBillDefaultVendor: string},
TConfigUpdate extends {nonReimbursable: QBDNonReimbursableExportAccountType; nonReimbursableAccount: string | undefined; nonReimbursableBillDefaultVendor: string},
>(policyID: string, configUpdate: TConfigUpdate, configCurrentData: Partial<TConfigUpdate>) {
const onyxData = buildOnyxDataForMultipleQuickbooksExportConfigurations(policyID, configUpdate, configCurrentData);

const parameters: UpdateQuickbooksDesktopCompanyCardExpenseAccountTypeParams = {
policyID,
nonReimbursableExpensesExportDestination: configUpdate.nonReimbursable,
nonReimbursableExpensesAccount: configUpdate.nonReimbursableAccount,
nonReimbursableExpensesAccount: configUpdate?.nonReimbursableAccount,
nonReimbursableBillDefaultVendor: configUpdate.nonReimbursableBillDefaultVendor,
idempotencyKey: String(CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {useRoute} from '@react-navigation/native';
import React, {useMemo} from 'react';
import React, {useCallback, useMemo} from 'react';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import {areSettingsInErrorFields, getCurrentSageIntacctEntityName, settingsPendingAction} from '@libs/PolicyUtils';
import goBackFromExportConnection from '@navigation/helpers/goBackFromExportConnection';
import type {PlatformStackRouteProp} from '@navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@navigation/types';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
Expand All @@ -22,7 +23,11 @@ function SageIntacctExportPage({policy}: WithPolicyProps) {
const route = useRoute<PlatformStackRouteProp<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT>>();
const backTo = route?.params?.backTo;
const {export: exportConfig, pendingFields, errorFields} = policy?.connections?.intacct?.config ?? {};
const shouldGoBackToSpecificRoute = exportConfig?.reimbursable === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT && backTo;
const shouldGoBackToSpecificRoute = exportConfig?.reimbursable === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT;

const goBack = useCallback(() => {
return goBackFromExportConnection(shouldGoBackToSpecificRoute, backTo);
}, [backTo, shouldGoBackToSpecificRoute]);

const sections = useMemo(
() => [
Expand Down Expand Up @@ -72,7 +77,7 @@ function SageIntacctExportPage({policy}: WithPolicyProps) {
title="workspace.sageIntacct.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
policyID={policyID}
onBackButtonPress={shouldGoBackToSpecificRoute ? () => Navigation.goBack(backTo) : undefined}
onBackButtonPress={goBack}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useRoute} from '@react-navigation/native';
import React, {useMemo} from 'react';
import React, {useCallback, useMemo} from 'react';
import {View} from 'react-native';
import ConnectionLayout from '@components/ConnectionLayout';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
Expand All @@ -17,6 +17,7 @@ import {
findSelectedTaxAccountWithDefaultSelect,
settingsPendingAction,
} from '@libs/PolicyUtils';
import goBackFromExportConnection from '@navigation/helpers/goBackFromExportConnection';
import type {PlatformStackRouteProp} from '@navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@navigation/types';
import type {DividerLineItem, MenuItem, ToggleItem} from '@pages/workspace/accounting/netsuite/types';
Expand Down Expand Up @@ -52,9 +53,12 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
const config = policy?.connections?.netsuite?.options.config;
const shouldGoBackToSpecificRoute =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT ||
config?.nonreimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT) &&
backTo;
config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT ||
config?.nonreimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT;

const goBack = useCallback(() => {
return goBackFromExportConnection(shouldGoBackToSpecificRoute, backTo);
}, [backTo, shouldGoBackToSpecificRoute]);

const {subsidiaryList, receivableList, taxAccountsList, items} = policy?.connections?.netsuite?.options?.data ?? {};
const selectedSubsidiary = useMemo(() => (subsidiaryList ?? []).find((subsidiary) => subsidiary.internalID === config?.subsidiaryID), [subsidiaryList, config?.subsidiaryID]);
Expand Down Expand Up @@ -209,7 +213,7 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title="workspace.netsuite.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
onBackButtonPress={shouldGoBackToSpecificRoute ? () => Navigation.goBack(backTo) : undefined}
onBackButtonPress={goBack}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Loading
Loading