From 43870d51f33a682a1092e9df9dd5291986b67bd9 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sat, 7 Sep 2024 20:54:16 +0530 Subject: [PATCH 1/5] Implemented new page structure for export Sage Intacct --- src/ROUTES.ts | 8 + src/SCREENS.ts | 2 + .../ModalStackNavigators/index.tsx | 4 + .../FULL_SCREEN_TO_RHP_MAPPING.ts | 2 + src/libs/Navigation/linkingConfig/config.ts | 2 + src/libs/Navigation/types.ts | 6 + ...NonReimbursableExpensesDestinationPage.tsx | 69 ++++++ ...SageIntacctNonReimbursableExpensesPage.tsx | 220 ++++++++---------- ...cctReimbursableExpensesDestinationPage.tsx | 73 ++++++ .../SageIntacctReimbursableExpensesPage.tsx | 174 ++++++-------- .../workspace/accounting/intacct/types.ts | 30 +++ 11 files changed, 365 insertions(+), 225 deletions(-) create mode 100644 src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx create mode 100644 src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx create mode 100644 src/pages/workspace/accounting/intacct/types.ts diff --git a/src/ROUTES.ts b/src/ROUTES.ts index a28c2ef4fc57..951780c2b97c 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -1399,6 +1399,14 @@ const ROUTES = { route: 'settings/workspaces/:policyID/accounting/sage-intacct/export/nonreimbursable', getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/export/nonreimbursable` as const, }, + POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_DESTINATION: { + route: 'settings/workspaces/:policyID/accounting/sage-intacct/export/reimbursable/destination', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/export/reimbursable/destination` as const, + }, + POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION: { + route: 'settings/workspaces/:policyID/accounting/sage-intacct/export/nonreimbursable/destination', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/export/nonreimbursable/destination` as const, + }, POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR: { route: 'settings/workspaces/:policyID/accounting/sage-intacct/export/:reimbursable/default-vendor', getRoute: (policyID: string, reimbursable: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/export/${reimbursable}/default-vendor` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 67ba5b84c9ec..b59beece461c 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -354,6 +354,8 @@ const SCREENS = { SAGE_INTACCT_EXPORT_DATE: 'Policy_Accounting_Sage_Intacct_Export_Date', SAGE_INTACCT_REIMBURSABLE_EXPENSES: 'Policy_Accounting_Sage_Intacct_Reimbursable_Expenses', SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES: 'Policy_Accounting_Sage_Intacct_Non_Reimbursable_Expenses', + SAGE_INTACCT_REIMBURSABLE_DESTINATION: 'Policy_Accounting_Sage_Intacct_Reimbursable_Destination', + SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION: 'Policy_Accounting_Sage_Intacct_Non_Reimbursable_Destination', SAGE_INTACCT_DEFAULT_VENDOR: 'Policy_Accounting_Sage_Intacct_Default_Vendor', SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT: 'Policy_Accounting_Sage_Intacct_Non_Reimbursable_Credit_Card_Account', SAGE_INTACCT_ADVANCED: 'Policy_Accounting_Sage_Intacct_Advanced', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 1b2390b17c39..17e283d42bf1 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -405,6 +405,10 @@ const SettingsModalStackNavigator = createModalStackNavigator('../../../../pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage').default, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES]: () => require('../../../../pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_DESTINATION]: () => + require('../../../../pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION]: () => + require('../../../../pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage').default, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_DEFAULT_VENDOR]: () => require('../../../../pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage').default, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT]: () => diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index ef634d9cb615..6279cca48a4e 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -106,6 +106,8 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT_DATE, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_EXPENSES, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES, + SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_DESTINATION, + SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_DEFAULT_VENDOR, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_ADVANCED, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 65fb05f8d008..c209755f3348 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -456,6 +456,8 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_EXPORT_DATE]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT_DATE.route}, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_EXPENSES]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_EXPENSES.route}, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.route}, + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_DESTINATION]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_DESTINATION.route}, + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION.route}, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_DEFAULT_VENDOR]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.route}, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT]: { path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index ee46cbd238ef..1c64b9e78fe2 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -604,6 +604,12 @@ type SettingsNavigatorParamList = { [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES]: { policyID: string; }; + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_REIMBURSABLE_DESTINATION]: { + policyID: string; + }; + [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION]: { + policyID: string; + }; [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_DEFAULT_VENDOR]: { policyID: string; reimbursable: string; diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx new file mode 100644 index 000000000000..1355b07773ed --- /dev/null +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx @@ -0,0 +1,69 @@ +import React, {useCallback} from 'react'; +import type {ValueOf} from 'type-fest'; +import RadioListItem from '@components/SelectionList/RadioListItem'; +import type {ListItem} from '@components/SelectionList/types'; +import SelectionScreen from '@components/SelectionScreen'; +import type {SelectorType} from '@components/SelectionScreen'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as ErrorUtils from '@libs/ErrorUtils'; +import {settingsPendingAction} from '@libs/PolicyUtils'; +import Navigation from '@navigation/Navigation'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; +import withPolicyConnections from '@pages/workspace/withPolicyConnections'; +import {updateSageIntacctNonreimbursableExpensesExportDestination} from '@userActions/connections/SageIntacct'; +import * as Policy from '@userActions/Policy/Policy'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; + +type MenuListItem = ListItem & { + value: ValueOf; +}; + +function SageIntacctNonReimbursableExpensesDestinationPage({policy}: WithPolicyConnectionsProps) { + const {translate} = useLocalize(); + const styles = useThemeStyles(); + const policyID = policy?.id ?? '-1'; + const {config} = policy?.connections?.intacct ?? {}; + + const data: MenuListItem[] = Object.values(CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE).map((expenseType) => ({ + value: expenseType, + text: translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${expenseType}`), + keyForList: expenseType, + isSelected: config?.export.nonReimbursable === expenseType, + })); + + const selectDestination = useCallback( + (row: MenuListItem) => { + if (row.value !== config?.export.nonReimbursable) { + updateSageIntacctNonreimbursableExpensesExportDestination(policyID, row.value, config?.export.nonReimbursable); + } + Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)); + }, + [config?.export.nonReimbursable, policyID], + ); + + return ( + selectDestination(selection as MenuListItem)} + initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} + policyID={policyID} + accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} + onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID))} + connectionName={CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT} + pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE], config?.pendingFields)} + errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} + errorRowStyles={[styles.ph5, styles.pv3]} + onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} + /> + ); +} + +SageIntacctNonReimbursableExpensesDestinationPage.displayName = 'SageIntacctNonReimbursableExpensesDestinationPage'; + +export default withPolicyConnections(SageIntacctNonReimbursableExpensesDestinationPage); diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index 808c497c05da..b886ff5e43a2 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -1,173 +1,137 @@ -import React, {useCallback, useMemo} from 'react'; -import {View} from 'react-native'; -import type {ValueOf} from 'type-fest'; +import React from 'react'; import ConnectionLayout from '@components/ConnectionLayout'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import SelectionList from '@components/SelectionList'; -import RadioListItem from '@components/SelectionList/RadioListItem'; -import type {ListItem} from '@components/SelectionList/types'; -import type {SelectorType} from '@components/SelectionScreen'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ErrorUtils from '@libs/ErrorUtils'; +import Navigation from '@libs/Navigation/Navigation'; import {areSettingsInErrorFields, getSageIntacctNonReimbursableActiveDefaultVendor, settingsPendingAction} from '@libs/PolicyUtils'; -import Navigation from '@navigation/Navigation'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; +import type {MenuItem, ToggleItem} from '@pages/workspace/accounting/intacct/types'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; -import {updateSageIntacctDefaultVendor, updateSageIntacctNonreimbursableExpensesExportDestination} from '@userActions/connections/SageIntacct'; +import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntacct'; import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {SageIntacctDataElementWithValue} from '@src/types/onyx/Policy'; -type MenuListItem = ListItem & { - value: ValueOf; -}; +type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined { return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; } -function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { +function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); const {data: intacctData, config} = policy?.connections?.intacct ?? {}; - const data: MenuListItem[] = Object.values(CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE).map((expenseType) => ({ - value: expenseType, - text: translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${expenseType}`), - keyForList: expenseType, - isSelected: config?.export.nonReimbursable === expenseType, - })); + const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy); + const defaultVendorName = getDefaultVendorName(activeDefaultVendor, intacctData?.vendors); - const selectNonReimbursableExpense = useCallback( - (row: MenuListItem) => { - if (row.value === config?.export.nonReimbursable) { - return; - } - updateSageIntacctNonreimbursableExpensesExportDestination(policyID, row.value, config?.export.nonReimbursable); + const menuItems: Array = [ + { + type: 'menuitem', + title: config?.export.nonReimbursable + ? translate(`workspace.sageIntacct.nonReimbursableExpenses.values.${config?.export.nonReimbursable}`) + : translate('workspace.sageIntacct.notConfigured'), + description: translate('workspace.accounting.exportAs'), + onPress: () => { + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_DESTINATION.getRoute(policyID)); + }, + subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE], }, - [config?.export.nonReimbursable, policyID], - ); - - const defaultVendor = useMemo(() => { - const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy); - const defaultVendorName = getDefaultVendorName(activeDefaultVendor, intacctData?.vendors); - - const defaultVendorSection = { - description: translate('workspace.sageIntacct.defaultVendor'), - action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE.toLowerCase())), + { + type: 'menuitem', + title: config?.export.nonReimbursableAccount ? config.export.nonReimbursableAccount : translate('workspace.sageIntacct.notConfigured'), + description: translate('workspace.sageIntacct.creditCardAccount'), + onPress: () => { + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT.getRoute(policyID)); + }, + subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT], + shouldHide: config?.export.nonReimbursable !== CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE, + }, + { + type: 'toggle', + title: translate('workspace.sageIntacct.defaultVendor'), + subtitle: translate('workspace.sageIntacct.defaultVendorDescription', false), + isActive: !!config?.export.nonReimbursableCreditCardChargeDefaultVendor, + switchAccessibilityLabel: translate('workspace.sageIntacct.defaultVendor'), + onToggle: (enabled) => { + const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; + updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor, config?.export.nonReimbursableCreditCardChargeDefaultVendor); + }, + onCloseError: () => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR), + pendingAction: settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR], config?.pendingFields), + errors: ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR), + shouldHide: config?.export.nonReimbursable !== CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE, + }, + { + type: 'menuitem', title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'), + description: translate('workspace.sageIntacct.defaultVendor'), + onPress: () => { + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE.toLowerCase())); + }, subscribedSettings: [ config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL ? CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR : CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, ], - }; - - return ( - - - - ); - }, [config?.errorFields, config?.export.nonReimbursable, config?.pendingFields, intacctData?.vendors, policy, policyID, translate]); - - const creditCardAccount = useMemo(() => { - const creditCardAccountSection = { - description: translate('workspace.sageIntacct.creditCardAccount'), - action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_CREDIT_CARD_ACCOUNT.getRoute(policyID)), - title: config?.export.nonReimbursableAccount ? config.export.nonReimbursableAccount : translate('workspace.sageIntacct.notConfigured'), - subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT], - }; - - return ( - - - - ); - }, [config?.errorFields, config?.export.nonReimbursableAccount, config?.pendingFields, policyID, translate]); + shouldHide: + !config?.export.nonReimbursable || + (config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE && !config?.export.nonReimbursableCreditCardChargeDefaultVendor), + }, + ]; return ( Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID))} accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} - featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} - displayName={SageIntacctNonReimbursableExpensesPage.displayName} policyID={policyID} + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} + contentContainerStyle={styles.pb2} + titleStyle={styles.ph5} connectionName={CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT} - shouldUseScrollView={false} - shouldIncludeSafeAreaPaddingBottom > - Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} - style={[styles.flexGrow1, styles.flexShrink1]} - contentContainerStyle={[styles.flexGrow1, styles.flexShrink1]} - > - selectNonReimbursableExpense(selection as MenuListItem)} - sections={[{data}]} - ListItem={RadioListItem} - showScrollIndicator - shouldShowTooltips={false} - containerStyle={[styles.flexReset, styles.flexGrow1, styles.flexShrink1, styles.pb0]} - /> - - - {config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL && defaultVendor} - {config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.CREDIT_CARD_CHARGE && ( - - {creditCardAccount} - { - const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; - updateSageIntacctDefaultVendor( - policyID, - CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, - vendor, - config?.export.nonReimbursableCreditCardChargeDefaultVendor, - ); - }} - wrapperStyle={[styles.ph5, styles.pv3]} - pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR], config?.pendingFields)} - errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR)} - onCloseError={() => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR)} - /> - {!!config?.export.nonReimbursableCreditCardChargeDefaultVendor && defaultVendor} - - )} - + {menuItems + .filter((item) => !item.shouldHide) + .map((item) => { + switch (item.type) { + case 'toggle': + // eslint-disable-next-line no-case-declarations + const {type, shouldHide, ...rest} = item; + return ( + + ); + default: + return ( + + + + ); + } + })} ); } diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx new file mode 100644 index 000000000000..aad242798324 --- /dev/null +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx @@ -0,0 +1,73 @@ +import React, {useCallback} from 'react'; +import type {ValueOf} from 'type-fest'; +import RadioListItem from '@components/SelectionList/RadioListItem'; +import type {ListItem} from '@components/SelectionList/types'; +import SelectionScreen from '@components/SelectionScreen'; +import type {SelectorType} from '@components/SelectionScreen'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as ErrorUtils from '@libs/ErrorUtils'; +import {settingsPendingAction} from '@libs/PolicyUtils'; +import Navigation from '@navigation/Navigation'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; +import withPolicyConnections from '@pages/workspace/withPolicyConnections'; +import {changeMappingsValueFromDefaultToTag, updateSageIntacctReimbursableExpensesExportDestination} from '@userActions/connections/SageIntacct'; +import * as Policy from '@userActions/Policy/Policy'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; + +type MenuListItem = ListItem & { + value: ValueOf; +}; + +function SageIntacctReimbursableExpensesDestinationPage({policy}: WithPolicyConnectionsProps) { + const {translate} = useLocalize(); + const styles = useThemeStyles(); + const policyID = policy?.id ?? '-1'; + const {config} = policy?.connections?.intacct ?? {}; + + const data: MenuListItem[] = Object.values(CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE).map((expenseType) => ({ + value: expenseType, + text: translate(`workspace.sageIntacct.reimbursableExpenses.values.${expenseType}`), + keyForList: expenseType, + isSelected: config?.export.reimbursable === expenseType, + })); + + const selectDestination = useCallback( + (row: MenuListItem) => { + if (row.value !== config?.export.reimbursable) { + updateSageIntacctReimbursableExpensesExportDestination(policyID, row.value, config?.export.reimbursable); + if (row.value === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL) { + // Employee default mapping value is not allowed when expense type is VENDOR_BILL, so we have to change mapping value to Tag + changeMappingsValueFromDefaultToTag(policyID, config?.mappings); + } + } + Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)); + }, + [config?.export.reimbursable, config?.mappings, policyID], + ); + + return ( + selectDestination(selection as MenuListItem)} + initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} + policyID={policyID} + accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} + onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID))} + connectionName={CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT} + pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE], config?.pendingFields)} + errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} + errorRowStyles={[styles.ph5, styles.pv3]} + onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} + /> + ); +} + +SageIntacctReimbursableExpensesDestinationPage.displayName = 'SageIntacctReimbursableExpensesDestinationPage'; + +export default withPolicyConnections(SageIntacctReimbursableExpensesDestinationPage); diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx index 360da1ac7a2d..d09b63915402 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx @@ -1,139 +1,119 @@ -import React, {useCallback, useMemo} from 'react'; -import {View} from 'react-native'; -import type {ValueOf} from 'type-fest'; +import React from 'react'; import ConnectionLayout from '@components/ConnectionLayout'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; -import SelectionList from '@components/SelectionList'; -import RadioListItem from '@components/SelectionList/RadioListItem'; -import type {ListItem} from '@components/SelectionList/types'; -import type {SelectorType} from '@components/SelectionScreen'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ErrorUtils from '@libs/ErrorUtils'; +import Navigation from '@libs/Navigation/Navigation'; import {areSettingsInErrorFields, settingsPendingAction} from '@libs/PolicyUtils'; -import Navigation from '@navigation/Navigation'; -import type {WithPolicyProps} from '@pages/workspace/withPolicy'; +import type {MenuItem, ToggleItem} from '@pages/workspace/accounting/intacct/types'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; -import {changeMappingsValueFromDefaultToTag, updateSageIntacctDefaultVendor, updateSageIntacctReimbursableExpensesExportDestination} from '@userActions/connections/SageIntacct'; +import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntacct'; import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {SageIntacctDataElementWithValue} from '@src/types/onyx/Policy'; -type MenuListItem = ListItem & { - value: ValueOf; -}; +type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined { return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; } -function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) { +function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); const {data: intacctData, config} = policy?.connections?.intacct ?? {}; const {reimbursable, reimbursableExpenseReportDefaultVendor} = policy?.connections?.intacct?.config?.export ?? {}; - const data: MenuListItem[] = Object.values(CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE).map((expenseType) => ({ - value: expenseType, - text: translate(`workspace.sageIntacct.reimbursableExpenses.values.${expenseType}`), - keyForList: expenseType, - isSelected: reimbursable === expenseType, - })); + const defaultVendorName = getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors); - const selectReimbursableDestination = useCallback( - (row: MenuListItem) => { - if (row.value !== reimbursable) { - updateSageIntacctReimbursableExpensesExportDestination(policyID, row.value, reimbursable); - } - if (row.value === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL) { - // Employee default mapping value is not allowed when expense type is VENDOR_BILL, so we have to change mapping value to Tag - changeMappingsValueFromDefaultToTag(policyID, config?.mappings); - Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)); - } + const menuItems: Array = [ + { + type: 'menuitem', + title: reimbursable ? translate(`workspace.sageIntacct.reimbursableExpenses.values.${reimbursable}`) : translate('workspace.sageIntacct.notConfigured'), + description: translate('workspace.accounting.exportAs'), + onPress: () => { + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_REIMBURSABLE_DESTINATION.getRoute(policyID)); + }, + subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE], }, - [reimbursable, policyID, config?.mappings], - ); - - const defaultVendor = useMemo(() => { - const defaultVendorName = getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors); - const defaultVendorSection = { - description: translate('workspace.sageIntacct.defaultVendor'), - action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)), + { + type: 'toggle', + title: translate('workspace.sageIntacct.defaultVendor'), + subtitle: translate('workspace.sageIntacct.defaultVendorDescription', true), + isActive: !!config?.export.reimbursableExpenseReportDefaultVendor, + switchAccessibilityLabel: translate('workspace.sageIntacct.defaultVendor'), + onToggle: (enabled) => { + const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; + updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor, config?.export.reimbursableExpenseReportDefaultVendor); + }, + onCloseError: () => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR), + pendingAction: settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR], config?.pendingFields), + errors: ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR), + shouldHide: reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT, + }, + { + type: 'menuitem', title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'), + description: translate('workspace.sageIntacct.defaultVendor'), + onPress: () => { + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)); + }, subscribedSettings: [CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR], - }; - - return ( - - - - ); - }, [config?.errorFields, config?.pendingFields, intacctData?.vendors, policyID, reimbursableExpenseReportDefaultVendor, translate]); + shouldHide: reimbursable !== CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT || !reimbursableExpenseReportDefaultVendor, + }, + ]; return ( Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID))} accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]} - featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} - displayName={SageIntacctReimbursableExpensesPage.displayName} policyID={policyID} + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} + contentContainerStyle={styles.pb2} + titleStyle={styles.ph5} connectionName={CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT} - shouldUseScrollView={false} - shouldIncludeSafeAreaPaddingBottom > - Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} - style={[styles.flexGrow1, styles.flexShrink1]} - contentContainerStyle={[styles.flexGrow1, styles.flexShrink1]} - > - selectReimbursableDestination(selection as MenuListItem)} - sections={[{data}]} - ListItem={RadioListItem} - showScrollIndicator - shouldShowTooltips={false} - containerStyle={[styles.flexReset, styles.flexGrow1, styles.flexShrink1, styles.pb0]} - /> - - {reimbursable === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.EXPENSE_REPORT && ( - - { - const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; - updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor, reimbursableExpenseReportDefaultVendor); - }} - pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR], config?.pendingFields)} - errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR)} - wrapperStyle={[styles.ph5, styles.pv3]} - onCloseError={() => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR)} - /> - {!!reimbursableExpenseReportDefaultVendor && defaultVendor} - - )} + {menuItems + .filter((item) => !item.shouldHide) + .map((item) => { + switch (item.type) { + case 'toggle': + // eslint-disable-next-line no-case-declarations + const {type, shouldHide, ...rest} = item; + return ( + + ); + default: + return ( + + + + ); + } + })} ); } diff --git a/src/pages/workspace/accounting/intacct/types.ts b/src/pages/workspace/accounting/intacct/types.ts new file mode 100644 index 000000000000..79883a0c9104 --- /dev/null +++ b/src/pages/workspace/accounting/intacct/types.ts @@ -0,0 +1,30 @@ +import type {MenuItemProps} from '@components/MenuItem'; +import type {OfflineWithFeedbackProps} from '@components/OfflineWithFeedback'; +import type {ToggleSettingOptionRowProps} from '@pages/workspace/workflows/ToggleSettingsOptionRow'; + +type MenuItem = MenuItemProps & { + /** Type of the item */ + type: 'menuitem'; + + /** The type of action that's pending */ + pendingAction: OfflineWithFeedbackProps['pendingAction']; + + /** Whether the item should be hidden */ + shouldHide?: boolean; + + /** Any error message to show */ + errors: OfflineWithFeedbackProps['errors']; + + /** Callback to close the error messages */ + onCloseError: OfflineWithFeedbackProps['onClose']; +}; + +type ToggleItem = ToggleSettingOptionRowProps & { + /** Type of the item */ + type: 'toggle'; + + /** Whether the item should be hidden */ + shouldHide?: boolean; +}; + +export type {MenuItem, ToggleItem}; From 21b7a1f16601110d4db13a1e660be64032f0db41 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Thu, 12 Sep 2024 23:23:44 +0530 Subject: [PATCH 2/5] Fix clear error function --- .../SageIntacctNonReimbursableExpensesDestinationPage.tsx | 2 +- .../export/SageIntacctReimbursableExpensesDestinationPage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx index 1355b07773ed..51a80c57599b 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesDestinationPage.tsx @@ -59,7 +59,7 @@ function SageIntacctNonReimbursableExpensesDestinationPage({policy}: WithPolicyC pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE], config?.pendingFields)} errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} errorRowStyles={[styles.ph5, styles.pv3]} - onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} + onClose={() => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE)} /> ); } diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx index aad242798324..2517d1d6843e 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesDestinationPage.tsx @@ -63,7 +63,7 @@ function SageIntacctReimbursableExpensesDestinationPage({policy}: WithPolicyConn pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE], config?.pendingFields)} errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} errorRowStyles={[styles.ph5, styles.pv3]} - onClose={() => Policy.clearNetSuiteErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} + onClose={() => Policy.clearSageIntacctErrorField(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)} /> ); } From 613e74ba8adc055f3b942bae3787172e8537bb08 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sun, 15 Sep 2024 18:40:32 +0530 Subject: [PATCH 3/5] Fix lint --- .../export/SageIntacctNonReimbursableExpensesPage.tsx | 2 +- .../intacct/export/SageIntacctReimbursableExpensesPage.tsx | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index a6a175098812..a3eae2ad8aaa 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -19,7 +19,7 @@ import {getDefaultVendorName} from './utils'; type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; -function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { +function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx index d09b63915402..bbe90414309a 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx @@ -15,14 +15,10 @@ import {updateSageIntacctDefaultVendor} from '@userActions/connections/SageIntac import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import type {SageIntacctDataElementWithValue} from '@src/types/onyx/Policy'; +import {getDefaultVendorName} from './utils'; type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; -function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined { - return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; -} - function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; From 6aaea8cc219daa4b40063a9961b7c2ca7754f2c2 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Sun, 15 Sep 2024 19:14:15 +0530 Subject: [PATCH 4/5] Fix duplicating options --- .../export/SageIntacctNonReimbursableExpensesPage.tsx | 6 ++++-- .../intacct/export/SageIntacctReimbursableExpensesPage.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index a3eae2ad8aaa..a248bbfcb481 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -19,6 +19,8 @@ import {getDefaultVendorName} from './utils'; type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; +type ToggleItemWithKey = ToggleItem & {key: string}; + function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; @@ -28,7 +30,7 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP const activeDefaultVendor = getSageIntacctNonReimbursableActiveDefaultVendor(policy); const defaultVendorName = getDefaultVendorName(activeDefaultVendor, intacctData?.vendors); - const menuItems: Array = [ + const menuItems: Array = [ { type: 'menuitem', title: config?.export.nonReimbursable @@ -53,6 +55,7 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP { type: 'toggle', title: translate('workspace.sageIntacct.defaultVendor'), + key: 'Default vendor toggle', subtitle: translate('workspace.sageIntacct.defaultVendorDescription', false), isActive: !!config?.export.nonReimbursableCreditCardChargeDefaultVendor, switchAccessibilityLabel: translate('workspace.sageIntacct.defaultVendor'), @@ -105,7 +108,6 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP const {type, shouldHide, ...rest} = item; return ( & {subscribedSettings?: string[]}; +type ToggleItemWithKey = ToggleItem & {key: string}; + function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; @@ -28,7 +30,7 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp const defaultVendorName = getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors); - const menuItems: Array = [ + const menuItems: Array = [ { type: 'menuitem', title: reimbursable ? translate(`workspace.sageIntacct.reimbursableExpenses.values.${reimbursable}`) : translate('workspace.sageIntacct.notConfigured'), @@ -41,6 +43,7 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp { type: 'toggle', title: translate('workspace.sageIntacct.defaultVendor'), + key: 'Default vendor toggle', subtitle: translate('workspace.sageIntacct.defaultVendorDescription', true), isActive: !!config?.export.reimbursableExpenseReportDefaultVendor, switchAccessibilityLabel: translate('workspace.sageIntacct.defaultVendor'), @@ -87,7 +90,6 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyConnectionsProp const {type, shouldHide, ...rest} = item; return ( Date: Thu, 19 Sep 2024 11:31:47 +0530 Subject: [PATCH 5/5] Fix warnings --- .../intacct/export/SageIntacctNonReimbursableExpensesPage.tsx | 3 ++- .../intacct/export/SageIntacctReimbursableExpensesPage.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index a248bbfcb481..354111de1489 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -105,9 +105,10 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyConnectionsP switch (item.type) { case 'toggle': // eslint-disable-next-line no-case-declarations - const {type, shouldHide, ...rest} = item; + const {type, shouldHide, key, ...rest} = item; return (