-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32550 from teneeto/feat/31672/add-new-input-field…
…s-for-tax-tracking feat: add new input fields for tax tracking
- Loading branch information
Showing
26 changed files
with
1,044 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import lodashGet from 'lodash/get'; | ||
import React, {useMemo, useState} from 'react'; | ||
import _ from 'underscore'; | ||
import OptionsSelector from '@components/OptionsSelector'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
import * as TransactionUtils from '@libs/TransactionUtils'; | ||
import CONST from '@src/CONST'; | ||
import {defaultProps, propTypes} from './taxPickerPropTypes'; | ||
|
||
function TaxPicker({selectedTaxRate, policyTaxRates, 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 shouldShowTextInput = !isTaxRatesCountBelowThreshold; | ||
|
||
const selectedOptions = useMemo(() => { | ||
if (!selectedTaxRate) { | ||
return []; | ||
} | ||
|
||
return [ | ||
{ | ||
name: selectedTaxRate, | ||
enabled: true, | ||
accountID: null, | ||
}, | ||
]; | ||
}, [selectedTaxRate]); | ||
|
||
const sections = useMemo(() => { | ||
const {policyTaxRatesOptions} = OptionsListUtils.getFilteredOptions( | ||
{}, | ||
{}, | ||
[], | ||
searchValue, | ||
selectedOptions, | ||
[], | ||
false, | ||
false, | ||
false, | ||
{}, | ||
[], | ||
false, | ||
{}, | ||
[], | ||
false, | ||
false, | ||
true, | ||
policyTaxRates, | ||
); | ||
return policyTaxRatesOptions; | ||
}, [policyTaxRates, searchValue, selectedOptions]); | ||
|
||
const selectedOptionKey = lodashGet(_.filter(lodashGet(sections, '[0].data', []), (taxRate) => taxRate.searchText === selectedTaxRate)[0], 'keyForList'); | ||
|
||
return ( | ||
<OptionsSelector | ||
contentContainerStyles={[{paddingBottom: StyleUtils.getSafeAreaMargins(insets).marginBottom}]} | ||
optionHoveredStyle={styles.hoveredComponentBG} | ||
sectionHeaderStyle={styles.mt5} | ||
sections={sections} | ||
selectedOptions={selectedOptions} | ||
value={searchValue} | ||
// Focus the first option when searching | ||
focusedIndex={0} | ||
initiallyFocusedOptionKey={selectedOptionKey} | ||
textInputLabel={translate('common.search')} | ||
boldStyle | ||
highlightSelectedOptions | ||
isRowMultilineSupported | ||
shouldShowTextInput={shouldShowTextInput} | ||
onChangeText={setSearchValue} | ||
onSelectRow={onSubmit} | ||
/> | ||
); | ||
} | ||
|
||
TaxPicker.displayName = 'TaxPicker'; | ||
TaxPicker.propTypes = propTypes; | ||
TaxPicker.defaultProps = defaultProps; | ||
|
||
export default TaxPicker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import PropTypes from 'prop-types'; | ||
import taxPropTypes from '@components/taxPropTypes'; | ||
|
||
const propTypes = { | ||
/** The selected tax rate of an expense */ | ||
selectedTaxRate: PropTypes.string, | ||
|
||
/** Callback to fire when a tax is pressed */ | ||
onSubmit: PropTypes.func.isRequired, | ||
|
||
/* Onyx Props */ | ||
/** Collection of tax rates attached to a policy */ | ||
policyTaxRates: taxPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
selectedTaxRate: '', | ||
policyTaxRates: {}, | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
const taxPropTypes = PropTypes.shape({ | ||
/** Name of a tax */ | ||
name: PropTypes.string, | ||
|
||
/** The value of a tax */ | ||
value: PropTypes.string, | ||
|
||
/** Whether the tax is disabled */ | ||
isDisabled: PropTypes.bool, | ||
}); | ||
|
||
export default PropTypes.shape({ | ||
/** Name of the tax */ | ||
name: PropTypes.string, | ||
|
||
/** Default policy tax ID */ | ||
defaultExternalID: PropTypes.string, | ||
|
||
/** Default value of taxes */ | ||
defaultValue: PropTypes.string, | ||
|
||
/** Default foreign policy tax ID */ | ||
foreignTaxDefault: PropTypes.string, | ||
|
||
/** List of tax names and values */ | ||
taxes: PropTypes.objectOf(taxPropTypes), | ||
}); |
Oops, something went wrong.