Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] fix: taxpicker selection for tax settings #39646

Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/libs/TransactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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';
Expand All @@ -22,7 +22,6 @@

type WorkspaceTaxesSettingsForeignCurrencyProps = WithPolicyAndFullscreenLoadingProps &
StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.TAXES_SETTINGS_FOREIGN_CURRENCY_DEFAULT>;

function WorkspaceTaxesSettingsForeignCurrency({
route: {
params: {policyID},
Expand All @@ -32,10 +31,15 @@
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 ?? '';
teneeto marked this conversation as resolved.
Show resolved Hide resolved
const defaultExternalID = taxRates?.defaultExternalID ?? '';

const selectedTaxRate = defaultTaxKey === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : TransactionUtils.getTaxName(taxes, defaultTaxKey);
teneeto marked this conversation as resolved.
Show resolved Hide resolved

const submit = ({keyForList}: ListItem) => {
setForeignCurrencyDefault(policyID, keyForList ?? '');
const submit = (taxes: OptionsListUtils.TaxRatesOption) => {

Check failure on line 41 in src/pages/workspace/taxes/WorkspaceTaxesSettingsForeignCurrency.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'taxes' is already declared in the upper scope on line 35 column 11
setForeignCurrencyDefault(policyID, taxes.data.code ?? '');
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

Expand All @@ -59,6 +63,7 @@
<View style={[styles.mb4, styles.flex1]}>
<TaxPicker
selectedTaxRate={selectedTaxRate}
policyID={policyID}
insets={insets}
onSubmit={submit}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved

const submit = (taxes: OptionsListUtils.TaxRatesOption) => {
setWorkspaceCurrencyDefault(policyID, taxes.data.code ?? '');
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

Expand All @@ -58,6 +59,7 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({
<View style={[styles.mb4, styles.flex1]}>
<TaxPicker
selectedTaxRate={selectedTaxRate}
policyID={policyID}
insets={insets}
onSubmit={submit}
/>
Expand Down
Loading