From 4f62db53c27aeed10292fd01df35927bac591b5c Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 9 Jul 2024 15:36:54 +0200 Subject: [PATCH] polish endpoints usages --- ...editCardChargeExportDefaultVendorParams.ts | 2 +- ...reimbursableExpensesExportAccountParams.ts | 2 +- ...nreimbursableExpensesExportVendorParams.ts | 2 +- ...ExpensesReportExportDefaultVendorParams.ts | 2 +- src/libs/PolicyUtils.ts | 7 +-- src/libs/actions/connections/SageIntacct.ts | 10 +-- ...SageIntacctNonReimbursableExpensesPage.tsx | 10 +-- .../SageIntacctReimbursableExpensesPage.tsx | 62 +++++++++++-------- src/types/onyx/Policy.ts | 6 +- 9 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams.ts b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams.ts index 09e2ad2dfc41..76ff4820fc3b 100644 --- a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams.ts +++ b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams.ts @@ -1,6 +1,6 @@ type UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams = { policyID: string; - vendorID: string | null; + vendorID: string; }; export default UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams; diff --git a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportAccountParams.ts b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportAccountParams.ts index 316308cbf67c..2a260ad267b3 100644 --- a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportAccountParams.ts +++ b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportAccountParams.ts @@ -1,6 +1,6 @@ type UpdateSageIntacctNonreimbursableExpensesExportAccountParams = { policyID: string; - bankAccountID: string; + creditCardAccountID: string; }; export default UpdateSageIntacctNonreimbursableExpensesExportAccountParams; diff --git a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportVendorParams.ts b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportVendorParams.ts index de2fc8c2f574..97ae85a26a2c 100644 --- a/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportVendorParams.ts +++ b/src/libs/API/parameters/UpdateSageIntacctNonreimbursableExpensesExportVendorParams.ts @@ -1,6 +1,6 @@ type UpdateSageIntacctNonreimbursableExpensesExportVendorParams = { policyID: string; - vendorID: string | null; + vendorID: string; }; export default UpdateSageIntacctNonreimbursableExpensesExportVendorParams; diff --git a/src/libs/API/parameters/UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams.ts b/src/libs/API/parameters/UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams.ts index 64d9c312a4b5..c4973515d561 100644 --- a/src/libs/API/parameters/UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams.ts +++ b/src/libs/API/parameters/UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams.ts @@ -1,6 +1,6 @@ type UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams = { policyID: string; - vendorID: string | null; + vendorID: string; }; export default UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index d5570eb7c478..9f8f2dc9690f 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -617,19 +617,18 @@ function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connect return (connection as ConnectionWithLastSyncData)?.lastSync?.successfulDate; } -function getSageIntacctVendors(policy?: Policy, selectedVendorId?: string | null): SelectorType[] { +function getSageIntacctVendors(policy?: Policy, selectedVendorId?: string): SelectorType[] { const vendors = policy?.connections?.intacct?.data?.vendors ?? []; - const isMatchFound = vendors?.some(({id}) => id === selectedVendorId); return vendors.map(({id, value}) => ({ value: id, text: value, keyForList: id, - isSelected: isMatchFound && selectedVendorId === id, + isSelected: selectedVendorId === id, })); } -function getSageIntacctNonReimbursableActiveDefaultVendor(policy?: Policy): string | null | undefined { +function getSageIntacctNonReimbursableActiveDefaultVendor(policy?: Policy): string | undefined { const { nonReimbursableCreditCardChargeDefaultVendor: creditCardDefaultVendor, nonReimbursableVendor: expenseReportDefaultVendor, diff --git a/src/libs/actions/connections/SageIntacct.ts b/src/libs/actions/connections/SageIntacct.ts index ce3cfdc69ec9..383323e356d1 100644 --- a/src/libs/actions/connections/SageIntacct.ts +++ b/src/libs/actions/connections/SageIntacct.ts @@ -147,7 +147,7 @@ function updateSageIntacctNonreimbursableExpensesExportDestination(policyID: str API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID: string, vendor: string | null) { +function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID: string, vendor: string) { const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor); const parameters: UpdateSageIntacctReimbursableExpensesReportExportDefaultVendorParams = { policyID, @@ -157,7 +157,7 @@ function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_REIMBURSABLE_EXPENSES_REPORT_EXPORT_DEFAULT_VENDOR, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID: string, vendor: string | null) { +function updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID: string, vendor: string) { const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor); const parameters: UpdateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendorParams = { policyID, @@ -171,13 +171,13 @@ function updateSageIntacctNonreimbursableExpensesExportAccount(policyID: string, const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, nonReimbursableAccount); const parameters: UpdateSageIntacctNonreimbursableExpensesExportAccountParams = { policyID, - bankAccountID: nonReimbursableAccount, + creditCardAccountID: nonReimbursableAccount, }; API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_ACCOUNT, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, vendor: string | null) { +function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, vendor: string) { const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR, vendor); const parameters: UpdateSageIntacctNonreimbursableExpensesExportVendorParams = { policyID, @@ -187,7 +187,7 @@ function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_VENDOR, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctDefaultVendor(policyID: string, settingName: keyof Connections['intacct']['config']['export'], vendor: string | null) { +function updateSageIntacctDefaultVendor(policyID: string, settingName: keyof Connections['intacct']['config']['export'], vendor: string) { if (settingName === CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR) { updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID, vendor); } else if (settingName === CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR) { diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index 3badf3e5d400..ba977cbba238 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -24,8 +24,8 @@ type MenuListItem = ListItem & { value: ValueOf; }; -function getDefaultVendorName(defaultVendor: string, vendors: SageIntacctDataElementWithValue[]): string { - return vendors.find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; +function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined { + return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; } function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { @@ -53,10 +53,12 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { 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())), - title: activeDefaultVendor ? getDefaultVendorName(activeDefaultVendor, intacctData?.vendors ?? []) : translate('workspace.sageIntacct.notConfigured'), + title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'), hasError: config?.export.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL ? !!config?.export?.errorFields?.nonReimbursableVendor @@ -151,7 +153,7 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { switchAccessibilityLabel={translate('workspace.sageIntacct.defaultVendor')} isActive={!!config?.export.nonReimbursableCreditCardChargeDefaultVendor} onToggle={(enabled) => { - const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? null : null; + const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor); }} wrapperStyle={[styles.ph5, styles.pv3]} diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx index 83e901c9433f..b3a4a04a5582 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx @@ -1,4 +1,4 @@ -import React, {useCallback} from 'react'; +import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {ValueOf} from 'type-fest'; import ConnectionLayout from '@components/ConnectionLayout'; @@ -23,8 +23,8 @@ type MenuListItem = ListItem & { value: ValueOf; }; -function getDefaultVendorName(defaultVendor: string, vendors: SageIntacctDataElementWithValue[]): string { - return vendors.find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; +function getDefaultVendorName(defaultVendor?: string, vendors?: SageIntacctDataElementWithValue[]): string | undefined { + return (vendors ?? []).find((vendor) => vendor.id === defaultVendor)?.value ?? defaultVendor; } function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) { @@ -53,30 +53,38 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) { [reimbursable, policyID], ); - const defaultVendorSection = { - description: translate('workspace.sageIntacct.defaultVendor'), - action: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_DEFAULT_VENDOR.getRoute(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE)), - title: reimbursableExpenseReportDefaultVendor - ? getDefaultVendorName(reimbursableExpenseReportDefaultVendor, intacctData?.vendors ?? []) - : translate('workspace.sageIntacct.notConfigured'), - hasError: !!config?.export?.errorFields?.reimbursableExpenseReportDefaultVendor, - pendingAction: config?.export?.pendingFields?.reimbursableExpenseReportDefaultVendor, - }; + 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)), + title: defaultVendorName && defaultVendorName !== '' ? defaultVendorName : translate('workspace.sageIntacct.notConfigured'), + hasError: !!config?.export?.errorFields?.reimbursableExpenseReportDefaultVendor, + pendingAction: config?.export?.pendingFields?.reimbursableExpenseReportDefaultVendor, + }; - const defaultVendor = ( - - - - ); + return ( + + + + ); + }, [ + config?.export?.errorFields?.reimbursableExpenseReportDefaultVendor, + config?.export?.pendingFields?.reimbursableExpenseReportDefaultVendor, + intacctData?.vendors, + policyID, + reimbursableExpenseReportDefaultVendor, + translate, + ]); return ( { - const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? null : null; + const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor); }} wrapperStyle={[styles.ph5, styles.pv3]} diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index d89155f430e4..8e9cfe97a43d 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1015,16 +1015,16 @@ type SageIntacctConnectiosConfig = OnyxCommon.OnyxValueWithOfflineFeedback<{ nonReimbursableAccount: string; /** Default vendor used for credit card transactions of non-reimbursable bill */ - nonReimbursableCreditCardChargeDefaultVendor: string | null; + nonReimbursableCreditCardChargeDefaultVendor: string; /** Default vendor of non-reimbursable bill */ - nonReimbursableVendor: string | null; + nonReimbursableVendor: string; /** Defines how reimbursable expenses are exported */ reimbursable: ValueOf; /** Default vendor of reimbursable bill */ - reimbursableExpenseReportDefaultVendor: string | null; + reimbursableExpenseReportDefaultVendor: string; /** Collection of mapping field errors, which will be triggered when update action fails */ errorFields?: OnyxCommon.ErrorFields;