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

chore: move policy tax rates to policy key #36784

Merged
merged 50 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ecda0af
add taxRates propTypes to policy key
teneeto Feb 19, 2024
b5e8ed9
use policy propTypes temp_confirmation list
teneeto Feb 19, 2024
9c57826
use policy propTypes on money request confirmation list
teneeto Feb 19, 2024
b74b585
use taxRates from policy key
teneeto Feb 19, 2024
bf33e31
remove policyTaxRates props and ONYX key
teneeto Feb 19, 2024
3ca147b
use taxRates from policy key
teneeto Feb 19, 2024
8e10b1f
remove policyTaxRates props and ONYX key
teneeto Feb 19, 2024
77347eb
get taxRates with lodashGet
teneeto Feb 19, 2024
081ca79
remove unused import
teneeto Feb 19, 2024
3c26cf6
use taxRates from policy key for IOURequestStepAmount
teneeto Feb 19, 2024
1e88b6f
remove policyTaxRates props and ONYX key for IOURequestStepAmount
teneeto Feb 19, 2024
079bac4
add taxRates propTypes to policy for IOURequestStepAmount
teneeto Feb 19, 2024
2a248c3
get policy from ONYX for IOURequestStepAmount
teneeto Feb 19, 2024
614502a
remove policyTaxRates props and ONYX key for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
108fd3e
add taxRates propTypes to policy for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
697bc85
add comments for taxRates field on policy proptypes
teneeto Feb 19, 2024
b051dc4
add comments for taxRates field on policy proptypes for IOURequestSte…
teneeto Feb 19, 2024
80ce551
use taxRates from policy key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
f4deedf
remove policyTaxRates props and ONYX key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
52e15ef
add taxRates propTypes to policy for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
401cdec
update policy onyx request key for IOURequestStepTaxRatePage
teneeto Feb 19, 2024
c8434b2
update policy onyx request key for IOURequestStepTaxAmountPage
teneeto Feb 19, 2024
59f6200
remove tax rates types and keys
teneeto Feb 21, 2024
a90b409
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 21, 2024
5b30df8
update tax Picker Prop Types
teneeto Feb 22, 2024
7c38ea8
use taxRates from policy
teneeto Feb 22, 2024
c93638a
add missing import
teneeto Feb 22, 2024
158afd9
update getFiltered options for taxRates
teneeto Feb 22, 2024
11157b7
change all policyTaxRates variables to taxRates
teneeto Feb 22, 2024
8e38637
pass taxRates as props
teneeto Feb 22, 2024
591179d
update taxPicker propTypes
teneeto Feb 22, 2024
a76c179
update taxPicker props
teneeto Feb 22, 2024
d730c2d
update more policyTaxRates to taxRates only
teneeto Feb 22, 2024
8e2eefd
add taxRates types to Policy
teneeto Feb 22, 2024
ff40828
remove policy taxRates types
teneeto Feb 22, 2024
6248765
update Policy TaxRate types
teneeto Feb 22, 2024
aaa5d57
export policy tax rates types from onyx types
teneeto Feb 22, 2024
f81d547
update OptionsListUtils TaxRate Types
teneeto Feb 22, 2024
e0dab41
update Tax Rates types
teneeto Feb 22, 2024
d3842c9
fix prettier
teneeto Feb 22, 2024
fa62bd0
update OptionListUtilsTest var names
teneeto Feb 22, 2024
6a8239a
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 22, 2024
7823561
add policy defaults
teneeto Feb 23, 2024
7332ede
add policy defaults
teneeto Feb 23, 2024
d6f8cb7
add comments to ONYX Props
teneeto Feb 23, 2024
ebd910a
add comments to ONYX Props
teneeto Feb 23, 2024
71be744
update comments
teneeto Feb 23, 2024
71fd0cd
update comments
teneeto Feb 23, 2024
1283b12
update comments
teneeto Feb 23, 2024
697f7e1
Merge branch 'main' of github.com:teneeto/Expensify into chore/36171/…
teneeto Feb 26, 2024
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: 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: {},
teneeto marked this conversation as resolved.
Show resolved Hide resolved
};

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
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: {},
teneeto marked this conversation as resolved.
Show resolved Hide resolved
};

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')}`) || '';
Comment on lines +289 to +290
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we ignore here the foreignTaxDefault value?

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB, this was better readable 😄

{},
{},
[],
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,
teneeto marked this conversation as resolved.
Show resolved Hide resolved
};

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

export {propTypes, defaultProps};
Loading
Loading