Skip to content

Commit

Permalink
add changes for routes support
Browse files Browse the repository at this point in the history
  • Loading branch information
narefyev91 committed Dec 30, 2024
1 parent 322a2dd commit d89e603
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ const ROUTES = {
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export` as const,
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/quickbooks-online/export` as const, backTo),
},
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/company-card-expense-account',
Expand Down Expand Up @@ -1504,7 +1504,7 @@ const ROUTES = {
},
POLICY_ACCOUNTING_XERO_EXPORT: {
route: 'settings/workspaces/:policyID/accounting/xero/export',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/xero/export` as const,
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/accounting/xero/export` as const, backTo),
},
POLICY_ACCOUNTING_XERO_PREFERRED_EXPORTER_SELECT: {
route: 'settings/workspaces/:policyID/connections/xero/export/preferred-exporter/select',
Expand Down Expand Up @@ -1629,7 +1629,7 @@ const ROUTES = {
},
POLICY_ACCOUNTING_NETSUITE_EXPORT: {
route: 'settings/workspaces/:policyID/connections/netsuite/export/',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/export/` as const,
getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/connections/netsuite/export/` as const, backTo),
},
POLICY_ACCOUNTING_NETSUITE_PREFERRED_EXPORTER_SELECT: {
route: 'settings/workspaces/:policyID/connections/netsuite/export/preferred-exporter/select',
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConnectionLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ConnectionLayoutProps = {
title?: TranslationPaths;

/** The current policyID */
policyID: string;
policyID?: string;

/** Defines which types of access should be verified */
accessVariants?: AccessVariant[];
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.QUICKBOOKS_ONLINE_EXPORT_DATE_SELECT]: {
policyID: string;
Expand Down Expand Up @@ -544,6 +545,7 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.XERO_EXPORT_PURCHASE_BILL_DATE_SELECT]: {
policyID: string;
Expand Down Expand Up @@ -620,6 +622,7 @@ type SettingsNavigatorParamList = {
};
[SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_PREFERRED_EXPORTER_SELECT]: {
policyID: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type SCREENS from '@src/SCREENS';
function SageIntacctExportPage({policy}: WithPolicyProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const policyID = policy?.id ?? '-1';
const policyID = policy?.id;
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 ?? {};
Expand All @@ -28,27 +28,27 @@ function SageIntacctExportPage({policy}: WithPolicyProps) {
() => [
{
description: translate('workspace.sageIntacct.preferredExporter'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREFERRED_EXPORTER.getRoute(policyID)),
action: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREFERRED_EXPORTER.getRoute(policyID)),
title: exportConfig?.exporter ?? translate('workspace.sageIntacct.notConfigured'),
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.EXPORTER],
},
{
description: translate('workspace.sageIntacct.exportDate.label'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT_DATE.getRoute(policyID)),
action: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT_DATE.getRoute(policyID)),
title: exportConfig?.exportDate ? translate(`workspace.sageIntacct.exportDate.values.${exportConfig.exportDate}.label`) : translate(`workspace.sageIntacct.notConfigured`),
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.EXPORT_DATE],
},
{
description: translate('workspace.accounting.exportOutOfPocket'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_EXPENSES.getRoute(policyID)),
action: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_EXPENSES.getRoute(policyID)),
title: exportConfig?.reimbursable
? translate(`workspace.sageIntacct.reimbursableExpenses.values.${exportConfig.reimbursable}`)
: translate('workspace.sageIntacct.notConfigured'),
subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR],
},
{
description: translate('workspace.accounting.exportCompanyCard'),
action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)),
action: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)),
title: exportConfig?.nonReimbursable
? translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${exportConfig.nonReimbursable}`)
: translate('workspace.sageIntacct.notConfigured'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useRoute} from '@react-navigation/native';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import ConnectionLayout from '@components/ConnectionLayout';
Expand All @@ -16,6 +17,8 @@ import {
findSelectedTaxAccountWithDefaultSelect,
settingsPendingAction,
} from '@libs/PolicyUtils';
import type {PlatformStackRouteProp} from '@navigation/PlatformStackNavigation/types';
import type {SettingsNavigatorParamList} from '@navigation/types';
import type {DividerLineItem, MenuItem, ToggleItem} from '@pages/workspace/accounting/netsuite/types';
import {
shouldHideExportForeignCurrencyAmount,
Expand All @@ -33,13 +36,16 @@ import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOpt
import * as Policy from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';

type MenuItemWithSubscribedSettings = Pick<MenuItem, 'type' | 'description' | 'title' | 'onPress' | 'shouldHide'> & {subscribedSettings?: string[]};

function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const policyID = policy?.id ?? '-1';
const route = useRoute<PlatformStackRouteProp<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_EXPORT>>();
const backTo = route?.params?.backTo;
const policyID = policy?.id;
const policyOwner = policy?.owner ?? '';
const {canUseNetSuiteUSATax} = usePermissions();

Expand Down Expand Up @@ -77,9 +83,11 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
type: 'menuitem',
title: config?.exporter ?? policyOwner,
description: translate('workspace.accounting.preferredExporter'),
onPress: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_PREFERRED_EXPORTER_SELECT.getRoute(policyID));
},
onPress: !policyID
? undefined
: () => {
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_PREFERRED_EXPORTER_SELECT.getRoute(policyID));
},
subscribedSettings: [CONST.NETSUITE_CONFIG.EXPORTER],
},
{
Expand All @@ -92,14 +100,14 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
? translate(`workspace.netsuite.exportDate.values.${config.exportDate}.label`)
: translate(`workspace.netsuite.exportDate.values.${CONST.NETSUITE_EXPORT_DATE.LAST_EXPENSE}.label`),
description: translate('workspace.accounting.exportDate'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_DATE_SELECT.getRoute(policyID)),
onPress: () => (!policyID ? undefined : Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_DATE_SELECT.getRoute(policyID))),
subscribedSettings: [CONST.NETSUITE_CONFIG.EXPORT_DATE],
},
{
type: 'menuitem',
title: config?.reimbursableExpensesExportDestination ? translate(`workspace.netsuite.exportDestination.values.${config.reimbursableExpensesExportDestination}.label`) : undefined,
description: translate('workspace.accounting.exportOutOfPocket'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT_EXPENSES.getRoute(policyID, CONST.NETSUITE_EXPENSE_TYPE.REIMBURSABLE)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT_EXPENSES.getRoute(policyID, CONST.NETSUITE_EXPENSE_TYPE.REIMBURSABLE)),
subscribedSettings: [
CONST.NETSUITE_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION,
...(!shouldHideReimbursableDefaultVendor(true, config) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []),
Expand All @@ -114,7 +122,7 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
? translate(`workspace.netsuite.exportDestination.values.${config.nonreimbursableExpensesExportDestination}.label`)
: undefined,
description: translate('workspace.accounting.exportCompanyCard'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT_EXPENSES.getRoute(policyID, CONST.NETSUITE_EXPENSE_TYPE.NON_REIMBURSABLE)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT_EXPENSES.getRoute(policyID, CONST.NETSUITE_EXPENSE_TYPE.NON_REIMBURSABLE)),
subscribedSettings: [
CONST.NETSUITE_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION,
...(!shouldHideReimbursableDefaultVendor(false, config) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []),
Expand All @@ -131,14 +139,14 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
type: 'menuitem',
title: selectedReceivable ? selectedReceivable.name : undefined,
description: translate('workspace.netsuite.exportInvoices'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_RECEIVABLE_ACCOUNT_SELECT.getRoute(policyID)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_RECEIVABLE_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: [CONST.NETSUITE_CONFIG.RECEIVABLE_ACCOUNT],
},
{
type: 'menuitem',
title: invoiceItemValue,
description: translate('workspace.netsuite.invoiceItem.label'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_INVOICE_ITEM_PREFERENCE_SELECT.getRoute(policyID)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_INVOICE_ITEM_PREFERENCE_SELECT.getRoute(policyID)),
subscribedSettings: [CONST.NETSUITE_CONFIG.INVOICE_ITEM_PREFERENCE, ...(shouldShowInvoiceItemMenuItem(config) ? [CONST.NETSUITE_CONFIG.INVOICE_ITEM] : [])],
},
{
Expand All @@ -149,15 +157,15 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
type: 'menuitem',
title: selectedProvTaxPostingAccount ? selectedProvTaxPostingAccount.name : undefined,
description: translate('workspace.netsuite.journalEntriesProvTaxPostingAccount'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_PROVINCIAL_TAX_POSTING_ACCOUNT_SELECT.getRoute(policyID)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_PROVINCIAL_TAX_POSTING_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: [CONST.NETSUITE_CONFIG.PROVINCIAL_TAX_POSTING_ACCOUNT],
shouldHide: shouldHideProvincialTaxPostingAccountSelect(selectedSubsidiary, config),
},
{
type: 'menuitem',
title: selectedTaxPostingAccount ? selectedTaxPostingAccount.name : undefined,
description: translate('workspace.netsuite.journalEntriesTaxPostingAccount'),
onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_TAX_POSTING_ACCOUNT_SELECT.getRoute(policyID)),
onPress: !policyID ? undefined : () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_TAX_POSTING_ACCOUNT_SELECT.getRoute(policyID)),
subscribedSettings: [CONST.NETSUITE_CONFIG.TAX_POSTING_ACCOUNT],
shouldHide: shouldHideTaxPostingAccountSelect(canUseNetSuiteUSATax, selectedSubsidiary, config),
},
Expand All @@ -166,8 +174,8 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title: translate('workspace.netsuite.foreignCurrencyAmount'),
isActive: !!config?.allowForeignCurrency,
switchAccessibilityLabel: translate('workspace.netsuite.foreignCurrencyAmount'),
onToggle: () => Connections.updateNetSuiteAllowForeignCurrency(policyID, !config?.allowForeignCurrency, config?.allowForeignCurrency),
onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY),
onToggle: () => (!policyID ? null : Connections.updateNetSuiteAllowForeignCurrency(policyID, !config?.allowForeignCurrency, config?.allowForeignCurrency)),
onCloseError: !policyID ? undefined : () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY),
pendingAction: settingsPendingAction([CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY], config?.pendingFields),
errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY),
shouldHide: shouldHideExportForeignCurrencyAmount(config),
Expand All @@ -177,8 +185,8 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title: translate('workspace.netsuite.exportToNextOpenPeriod'),
isActive: !!config?.exportToNextOpenPeriod,
switchAccessibilityLabel: translate('workspace.netsuite.exportToNextOpenPeriod'),
onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD),
onToggle: () => Connections.updateNetSuiteExportToNextOpenPeriod(policyID, !config?.exportToNextOpenPeriod, config?.exportToNextOpenPeriod ?? false),
onCloseError: !policyID ? undefined : () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD),
onToggle: () => (!policyID ? null : Connections.updateNetSuiteExportToNextOpenPeriod(policyID, !config?.exportToNextOpenPeriod, config?.exportToNextOpenPeriod ?? false)),
pendingAction: settingsPendingAction([CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD], config?.pendingFields),
errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD),
},
Expand All @@ -192,6 +200,7 @@ function NetSuiteExportConfigurationPage({policy}: WithPolicyConnectionsProps) {
title="workspace.netsuite.exportDescription"
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]}
policyID={policyID}
onBackButtonPress={!backTo ? undefined : () => Navigation.navigate(backTo)}
featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED}
contentContainerStyle={styles.pb2}
titleStyle={styles.ph5}
Expand Down
Loading

0 comments on commit d89e603

Please sign in to comment.