Skip to content

Commit

Permalink
Merge pull request #44046 from Krishna2323/krishna2323/issue/43613
Browse files Browse the repository at this point in the history
fix: [Track tax] Disabled tax rate can be selected.
  • Loading branch information
MonilBhavsar authored Jun 26, 2024
2 parents 4d7c5e9 + 46c0a51 commit 9862fdb
Showing 1 changed file with 27 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import React from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import TaxPicker from '@components/TaxPicker';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type * as OptionsListUtils from '@libs/OptionsListUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import type {WithPolicyOnyxProps} from '@pages/workspace/withPolicy';
Expand All @@ -15,15 +16,6 @@ import * as DistanceRate from '@userActions/Policy/DistanceRate';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {PendingAction} from '@src/types/onyx/OnyxCommon';

type ListItemType = {
value: string;
text: string;
isSelected: boolean;
keyForList: string;
pendingAction?: PendingAction;
};

type PolicyDistanceRateTaxRateEditPageProps = WithPolicyOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DISTANCE_RATE_TAX_RATE_EDIT>;

Expand All @@ -36,21 +28,10 @@ function PolicyDistanceRateTaxRateEditPage({route, policy}: PolicyDistanceRateTa
const customUnit = customUnits[Object.keys(customUnits)[0]];
const rate = customUnit?.rates[rateID];
const taxRateExternalID = rate.attributes?.taxRateExternalID;
const taxRateItems: ListItemType[] = useMemo(() => {
const taxes = policy?.taxRates?.taxes;
const result = Object.entries(taxes ?? {}).map(([key, value]) => ({
value: key,
text: `${value.name} (${value.value})`,
isSelected: taxRateExternalID === key,
keyForList: key,
pendingAction: value.pendingAction,
isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
}));
return result;
}, [policy, taxRateExternalID]);
const selectedTaxRate = TransactionUtils.getWorkspaceTaxesSettingsName(policy, taxRateExternalID ?? '');

const onTaxRateChange = (newTaxRate: ListItemType) => {
if (taxRateExternalID === newTaxRate.value) {
const onTaxRateChange = (newTaxRate: OptionsListUtils.TaxRatesOption) => {
if (taxRateExternalID === newTaxRate.code) {
Navigation.goBack();
return;
}
Expand All @@ -59,13 +40,17 @@ function PolicyDistanceRateTaxRateEditPage({route, policy}: PolicyDistanceRateTa
...rate,
attributes: {
...rate.attributes,
taxRateExternalID: newTaxRate.value,
taxRateExternalID: newTaxRate.code,
},
},
]);
Navigation.navigate(ROUTES.WORKSPACE_DISTANCE_RATE_DETAILS.getRoute(policyID, rateID));
};

const dismiss = () => {
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.PAID]}
Expand All @@ -78,16 +63,21 @@ function PolicyDistanceRateTaxRateEditPage({route, policy}: PolicyDistanceRateTa
shouldEnableMaxHeight
testID={PolicyDistanceRateTaxRateEditPage.displayName}
>
<HeaderWithBackButton
title={translate('workspace.taxes.taxRate')}
shouldShowBackButton
/>
<SelectionList
sections={[{data: taxRateItems}]}
ListItem={RadioListItem}
onSelectRow={onTaxRateChange}
initiallyFocusedOptionKey={taxRateItems.find((item) => item.isSelected)?.keyForList}
/>
{({insets}) => (
<>
<HeaderWithBackButton
title={translate('workspace.taxes.taxRate')}
shouldShowBackButton
/>
<TaxPicker
selectedTaxRate={selectedTaxRate}
policyID={policyID}
insets={insets}
onSubmit={onTaxRateChange}
onDismiss={dismiss}
/>
</>
)}
</ScreenWrapper>
</AccessOrNotFoundWrapper>
);
Expand Down

0 comments on commit 9862fdb

Please sign in to comment.