From 0aa35266cf99a16778aaf6786125e6ce7b5f0e53 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Thu, 4 Apr 2024 20:40:44 +0100 Subject: [PATCH 1/4] make transaction in getDefaultTaxName optional --- src/libs/TransactionUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/TransactionUtils.ts b/src/libs/TransactionUtils.ts index 430100e84b2f..af28133ecf3f 100644 --- a/src/libs/TransactionUtils.ts +++ b/src/libs/TransactionUtils.ts @@ -623,7 +623,7 @@ function getEnabledTaxRateCount(options: TaxRates) { /** * Gets the default tax name */ -function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction: Transaction) { +function getDefaultTaxName(taxRates: TaxRatesWithDefault, transaction?: Transaction) { const defaultTaxKey = taxRates.defaultExternalID; const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${Localize.translateLocal('common.default')}`) || ''; return transaction?.taxRate?.text ?? defaultTaxName; From be564603f77f30bf5812f92a8a965659ffce6418 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Thu, 4 Apr 2024 20:40:59 +0100 Subject: [PATCH 2/4] fix taxPicker selection for WorkspaceTaxesSettingsForeignCurrency --- .../WorkspaceTaxesSettingsForeignCurrency.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx b/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx index dbe94ba802ef..5fd92310874c 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx @@ -3,13 +3,13 @@ import React from 'react'; import {View} from 'react-native'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; -import type {ListItem} from '@components/SelectionList/types'; import TaxPicker from '@components/TaxPicker'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {setForeignCurrencyDefault} from '@libs/actions/Policy'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; +import type * as OptionsListUtils from '@libs/OptionsListUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper'; @@ -22,7 +22,6 @@ import type SCREENS from '@src/SCREENS'; type WorkspaceTaxesSettingsForeignCurrencyProps = WithPolicyAndFullscreenLoadingProps & StackScreenProps; - function WorkspaceTaxesSettingsForeignCurrency({ route: { params: {policyID}, @@ -32,10 +31,15 @@ function WorkspaceTaxesSettingsForeignCurrency({ const {translate} = useLocalize(); const styles = useThemeStyles(); - const selectedTaxRate = TransactionUtils.getTaxName(policy?.taxRates?.taxes ?? {}, policy?.taxRates?.foreignTaxDefault ?? ''); + const taxRates = policy?.taxRates; + const taxes = taxRates?.taxes ?? {}; + const defaultTaxKey = taxRates?.foreignTaxDefault ?? ''; + const defaultExternalID = taxRates?.defaultExternalID ?? ''; + + const selectedTaxRate = defaultTaxKey === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : TransactionUtils.getTaxName(taxes, defaultTaxKey); - const submit = ({keyForList}: ListItem) => { - setForeignCurrencyDefault(policyID, keyForList ?? ''); + const submit = (taxes: OptionsListUtils.TaxRatesOption) => { + setForeignCurrencyDefault(policyID, taxes.data.code ?? ''); Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID)); }; @@ -59,6 +63,7 @@ function WorkspaceTaxesSettingsForeignCurrency({ From bd3788fa2fe55586fa53dbb71cac7f54394cfdf3 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Thu, 4 Apr 2024 20:41:08 +0100 Subject: [PATCH 3/4] fix taxPicker selection for WorkspaceTaxesSettingsWorkspaceCurrency --- .../taxes/WorkspaceTaxesSettingsWorkspaceCurrency.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/taxes/WorkspaceTaxesSettingsWorkspaceCurrency.tsx b/src/pages/workspace/taxes/WorkspaceTaxesSettingsWorkspaceCurrency.tsx index c6de23069837..630560f864b4 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesSettingsWorkspaceCurrency.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesSettingsWorkspaceCurrency.tsx @@ -3,13 +3,13 @@ import React from 'react'; import {View} from 'react-native'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; -import type {ListItem} from '@components/SelectionList/types'; import TaxPicker from '@components/TaxPicker'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {setWorkspaceCurrencyDefault} from '@libs/actions/Policy'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; +import type * as OptionsListUtils from '@libs/OptionsListUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper'; import FeatureEnabledAccessOrNotFoundWrapper from '@pages/workspace/FeatureEnabledAccessOrNotFoundWrapper'; @@ -32,9 +32,10 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({ const {translate} = useLocalize(); const styles = useThemeStyles(); - const selectedTaxRate = TransactionUtils.getTaxName(policy?.taxRates?.taxes ?? {}, policy?.taxRates?.foreignTaxDefault ?? ''); - const submit = ({keyForList}: ListItem) => { - setWorkspaceCurrencyDefault(policyID, keyForList ?? ''); + const selectedTaxRate = policy?.taxRates && TransactionUtils.getDefaultTaxName(policy?.taxRates); + + const submit = (taxes: OptionsListUtils.TaxRatesOption) => { + setWorkspaceCurrencyDefault(policyID, taxes.data.code ?? ''); Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID)); }; @@ -58,6 +59,7 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({ From 4fc604ddddc15b87421f32d13ba9a7686ea0bfbd Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Thu, 4 Apr 2024 21:13:09 +0100 Subject: [PATCH 4/4] fix review comment --- .../taxes/WorkspaceTaxesSettingsForeignCurrency.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx b/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx index 5fd92310874c..3081df55fe69 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx @@ -32,11 +32,11 @@ function WorkspaceTaxesSettingsForeignCurrency({ const styles = useThemeStyles(); const taxRates = policy?.taxRates; - const taxes = taxRates?.taxes ?? {}; - const defaultTaxKey = taxRates?.foreignTaxDefault ?? ''; + const foreignTaxDefault = taxRates?.foreignTaxDefault ?? ''; const defaultExternalID = taxRates?.defaultExternalID ?? ''; - const selectedTaxRate = defaultTaxKey === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : TransactionUtils.getTaxName(taxes, defaultTaxKey); + const selectedTaxRate = + foreignTaxDefault === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : TransactionUtils.getTaxName(taxRates?.taxes ?? {}, foreignTaxDefault); const submit = (taxes: OptionsListUtils.TaxRatesOption) => { setForeignCurrencyDefault(policyID, taxes.data.code ?? '');