Skip to content

Commit

Permalink
Merge pull request #36784 from teneeto/chore/36171/move-policy-tax-ra…
Browse files Browse the repository at this point in the history
…tes-to-policy-key

chore: move policy tax rates to policy key
  • Loading branch information
MonilBhavsar authored Feb 26, 2024
2 parents 3b7aebf + 697f7e1 commit 7120be2
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 170 deletions.
2 changes: 0 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ const ONYXKEYS = {
POLICY_CATEGORIES: 'policyCategories_',
POLICY_RECENTLY_USED_CATEGORIES: 'policyRecentlyUsedCategories_',
POLICY_TAGS: 'policyTags_',
POLICY_TAX_RATE: 'policyTaxRates_',
POLICY_RECENTLY_USED_TAGS: 'policyRecentlyUsedTags_',
POLICY_REPORT_FIELDS: 'policyReportFields_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
Expand Down Expand Up @@ -477,7 +476,6 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.SELECTED_TAB]: string;
[ONYXKEYS.COLLECTION.PRIVATE_NOTES_DRAFT]: string;
[ONYXKEYS.COLLECTION.NEXT_STEP]: OnyxTypes.ReportNextStep;
[ONYXKEYS.COLLECTION.POLICY_TAX_RATE]: string[];
};

type OnyxValuesMapping = {
Expand Down
20 changes: 9 additions & 11 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import {iouDefaultProps, iouPropTypes} from '@pages/iou/propTypes';
import {policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -41,7 +42,6 @@ import SettlementButton from './SettlementButton';
import ShowMoreButton from './ShowMoreButton';
import Switch from './Switch';
import tagPropTypes from './tagPropTypes';
import taxPropTypes from './taxPropTypes';
import Text from './Text';
import transactionPropTypes from './transactionPropTypes';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from './withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -167,8 +167,8 @@ const propTypes = {
policyTags: tagPropTypes,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
/** The policy of the report */
policy: policyPropTypes.policy,

/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
iou: iouPropTypes,
Expand Down Expand Up @@ -196,6 +196,7 @@ const defaultProps = {
receiptPath: '',
receiptFilename: '',
listStyles: [],
policy: {},
policyCategories: {},
policyTags: {},
transactionID: '',
Expand All @@ -206,7 +207,6 @@ const defaultProps = {
shouldShowSmartScanFields: true,
isPolicyExpenseChat: false,
iou: iouDefaultProps,
policyTaxRates: {},
};

function MoneyRequestConfirmationList(props) {
Expand All @@ -228,6 +228,7 @@ function MoneyRequestConfirmationList(props) {
const {unit, rate, currency} = props.mileageRate;
const distance = lodashGet(transaction, 'routes.route0.distance', 0);
const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const taxRates = lodashGet(props.policy, 'taxRates', {});

// A flag for showing the categories field
const shouldShowCategories = props.isPolicyExpenseChat && (props.iouCategory || OptionsListUtils.hasEnabledOptions(_.values(props.policyCategories)));
Expand Down Expand Up @@ -262,8 +263,8 @@ function MoneyRequestConfirmationList(props) {
);
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(props.transaction.taxAmount, props.iouCurrencyCode);

const defaultTaxKey = props.policyTaxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${props.policyTaxRates.taxes[defaultTaxKey].name} (${props.policyTaxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const taxRateTitle = (props.transaction.taxRate && props.transaction.taxRate.text) || defaultTaxName;

const isFocused = useIsFocused();
Expand Down Expand Up @@ -818,7 +819,7 @@ function MoneyRequestConfirmationList(props) {
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly}
title={taxRateTitle}
description={props.policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() =>
Expand All @@ -835,7 +836,7 @@ function MoneyRequestConfirmationList(props) {
<MenuItemWithTopDescription
shouldShowRightIcon={!props.isReadOnly}
title={formattedTaxAmount}
description={props.policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() =>
Expand Down Expand Up @@ -890,9 +891,6 @@ export default compose(
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
policyTaxRates: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,
},
iou: {
key: ONYXKEYS.IOU,
},
Expand Down
25 changes: 11 additions & 14 deletions src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as ReceiptUtils from '@libs/ReceiptUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import * as TransactionUtils from '@libs/TransactionUtils';
import {policyPropTypes} from '@pages/workspace/withPolicy';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -41,7 +42,6 @@ import ReceiptEmptyState from './ReceiptEmptyState';
import SettlementButton from './SettlementButton';
import Switch from './Switch';
import tagPropTypes from './tagPropTypes';
import taxPropTypes from './taxPropTypes';
import Text from './Text';
import transactionPropTypes from './transactionPropTypes';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from './withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -161,8 +161,8 @@ const propTypes = {
policyTags: tagPropTypes,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
/** The policy of the report */
policy: policyPropTypes.policy,

/** Transaction that represents the money request */
transaction: transactionPropTypes,
Expand All @@ -189,6 +189,7 @@ const defaultProps = {
receiptPath: '',
receiptFilename: '',
listStyles: [],
policy: {},
policyCategories: {},
policyTags: {},
transactionID: '',
Expand All @@ -197,7 +198,6 @@ const defaultProps = {
isDistanceRequest: false,
shouldShowSmartScanFields: true,
isPolicyExpenseChat: false,
policyTaxRates: {},
};

function MoneyTemporaryForRefactorRequestConfirmationList({
Expand Down Expand Up @@ -238,7 +238,6 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
session: {accountID},
shouldShowSmartScanFields,
transaction,
policyTaxRates,
}) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -252,6 +251,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
const {unit, rate, currency} = mileageRate;
const distance = lodashGet(transaction, 'routes.route0.distance', 0);
const shouldCalculateDistanceAmount = isDistanceRequest && iouAmount === 0;
const taxRates = lodashGet(policy, 'taxRates', {});

// A flag for showing the categories field
const shouldShowCategories = isPolicyExpenseChat && (iouCategory || OptionsListUtils.hasEnabledOptions(_.values(policyCategories)));
Expand Down Expand Up @@ -286,8 +286,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
);
const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transaction.taxAmount, iouCurrencyCode);

const defaultTaxKey = policyTaxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${policyTaxRates.taxes[defaultTaxKey].name} (${policyTaxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const defaultTaxKey = taxRates.defaultExternalID;
const defaultTaxName = (defaultTaxKey && `${taxRates.taxes[defaultTaxKey].name} (${taxRates.taxes[defaultTaxKey].value}) • ${translate('common.default')}`) || '';
const taxRateTitle = (transaction.taxRate && transaction.taxRate.text) || defaultTaxName;

const isFocused = useIsFocused();
Expand Down Expand Up @@ -787,10 +787,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
{
item: (
<MenuItemWithTopDescription
key={`${policyTaxRates.name}${taxRateTitle}`}
key={`${taxRates.name}${taxRateTitle}`}
shouldShowRightIcon={!isReadOnly}
title={taxRateTitle}
description={policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
Expand All @@ -804,10 +804,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
{
item: (
<MenuItemWithTopDescription
key={`${policyTaxRates.name}${formattedTaxAmount}`}
key={`${taxRates.name}${formattedTaxAmount}`}
shouldShowRightIcon={!isReadOnly}
title={formattedTaxAmount}
description={policyTaxRates.name}
description={taxRates.name}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
Expand Down Expand Up @@ -936,8 +936,5 @@ export default compose(
policy: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
},
policyTaxRates: {
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,
},
}),
)(MoneyTemporaryForRefactorRequestConfirmationList);
31 changes: 6 additions & 25 deletions src/components/TaxPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import {defaultProps, propTypes} from './taxPickerPropTypes';

function TaxPicker({selectedTaxRate, policyTaxRates, insets, onSubmit}) {
function TaxPicker({selectedTaxRate, taxRates, insets, onSubmit}) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const [searchValue, setSearchValue] = useState('');

const policyTaxRatesCount = TransactionUtils.getEnabledTaxRateCount(policyTaxRates.taxes);
const isTaxRatesCountBelowThreshold = policyTaxRatesCount < CONST.TAX_RATES_LIST_THRESHOLD;
const taxRatesCount = TransactionUtils.getEnabledTaxRateCount(taxRates.taxes);
const isTaxRatesCountBelowThreshold = taxRatesCount < CONST.TAX_RATES_LIST_THRESHOLD;

const shouldShowTextInput = !isTaxRatesCountBelowThreshold;

Expand All @@ -36,28 +36,9 @@ function TaxPicker({selectedTaxRate, policyTaxRates, insets, onSubmit}) {
}, [selectedTaxRate]);

const sections = useMemo(() => {
const {policyTaxRatesOptions} = OptionsListUtils.getFilteredOptions(
{},
{},
[],
searchValue,
selectedOptions,
[],
false,
false,
false,
{},
[],
false,
{},
[],
false,
false,
true,
policyTaxRates,
);
return policyTaxRatesOptions;
}, [policyTaxRates, searchValue, selectedOptions]);
const {taxRatesOptions} = OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], false, {}, [], false, false, true, taxRates);
return taxRatesOptions;
}, [taxRates, searchValue, selectedOptions]);

const selectedOptionKey = lodashGet(_.filter(lodashGet(sections, '[0].data', []), (taxRate) => taxRate.searchText === selectedTaxRate)[0], 'keyForList');

Expand Down
12 changes: 9 additions & 3 deletions src/components/TaxPicker/taxPickerPropTypes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import taxPropTypes from '@components/taxPropTypes';
import safeAreaInsetPropTypes from '@pages/safeAreaInsetPropTypes';

const propTypes = {
/** The selected tax rate of an expense */
Expand All @@ -8,14 +9,19 @@ const propTypes = {
/** Callback to fire when a tax is pressed */
onSubmit: PropTypes.func.isRequired,

/* Onyx Props */
/** Collection of tax rates attached to a policy */
policyTaxRates: taxPropTypes,
taxRates: taxPropTypes,

/**
* Safe area insets required for reflecting the portion of the view,
* that is not covered by navigation bars, tab bars, toolbars, and other ancestor views.
*/
insets: safeAreaInsetPropTypes.isRequired,
};

const defaultProps = {
selectedTaxRate: '',
policyTaxRates: {},
taxRates: {},
};

export {propTypes, defaultProps};
Loading

0 comments on commit 7120be2

Please sign in to comment.