Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 2 deletions src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const defaultListOptions = {
userToInvite: null,
currentUserOption: null,
categoryOptions: [],
tagOptions: [],
taxRatesOptions: [],
headerMessage: '',
};

Expand Down
2 changes: 0 additions & 2 deletions src/components/Search/SearchFiltersParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const defaultListOptions = {
currentUserOption: null,
headerMessage: '',
categoryOptions: [],
tagOptions: [],
taxRatesOptions: [],
};

function getSelectedOptionData(option: Option): OptionData {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function SearchRouter({onRouterClose}: SearchRouterProps) {
const {options, areOptionsInitialized} = useOptionsList();
const searchOptions = useMemo(() => {
if (!areOptionsInitialized) {
return {recentReports: [], personalDetails: [], userToInvite: null, currentUserOption: null, categoryOptions: [], tagOptions: [], taxRatesOptions: []};
return {recentReports: [], personalDetails: [], userToInvite: null, currentUserOption: null, categoryOptions: []};
}
return OptionsListUtils.getSearchOptions(options, '', betas ?? []);
}, [areOptionsInitialized, betas, options]);
Expand Down
32 changes: 20 additions & 12 deletions src/components/TaxPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import * as IOUUtils from '@libs/IOUUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as TaxOptionsListUtils from '@libs/TaxOptionsListUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import type {IOUAction} from '@src/CONST';
Expand All @@ -20,11 +20,9 @@ type TaxPickerProps = {
selectedTaxRate?: string;

/** ID of the policy */
// eslint-disable-next-line react/no-unused-prop-types
policyID?: string;

/** ID of the transaction */
// eslint-disable-next-line react/no-unused-prop-types
transactionID?: string;

/**
Expand All @@ -34,10 +32,9 @@ type TaxPickerProps = {
insets?: EdgeInsets;

/** Callback to fire when a tax is pressed */
onSubmit: (tax: OptionsListUtils.TaxRatesOption) => void;
onSubmit: (tax: TaxOptionsListUtils.TaxRatesOption) => void;

/** The action to take */
// eslint-disable-next-line react/no-unused-prop-types
action?: IOUAction;

/** The type of IOU */
Expand All @@ -50,12 +47,17 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, insets, onSub
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const [searchValue, setSearchValue] = useState('');
const policy = PolicyUtils.getPolicy(policyID);
const [draftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}` as `${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`);
const [defaultTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);

const transaction = IOUUtils.shouldUseTransactionDraft(action) ? draftTransaction : defaultTransaction;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
const [transaction] = useOnyx(
(() => {
if (IOUUtils.shouldUseTransactionDraft(action)) {
return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}` as `${typeof ONYXKEYS.COLLECTION.TRANSACTION}${string}`;
}
return `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`;
})(),
);

const isEditing = action === CONST.IOU.ACTION.EDIT;
const isEditingSplitBill = isEditing && iouType === CONST.IOU.TYPE.SPLIT;
Expand All @@ -67,7 +69,7 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, insets, onSub

const shouldShowTextInput = !isTaxRatesCountBelowThreshold;

const selectedOptions = useMemo(() => {
const selectedOptions = useMemo<TaxOptionsListUtils.Tax[]>(() => {
if (!selectedTaxRate) {
return [];
}
Expand All @@ -82,7 +84,13 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, insets, onSub
}, [selectedTaxRate]);

const sections = useMemo(
() => OptionsListUtils.getTaxRatesSection(policy, selectedOptions as OptionsListUtils.Tax[], searchValue, currentTransaction),
() =>
TaxOptionsListUtils.getTaxRatesSection({
policy,
searchValue,
selectedOptions,
transaction: currentTransaction,
}),
[searchValue, selectedOptions, policy, currentTransaction],
);

Expand All @@ -91,7 +99,7 @@ function TaxPicker({selectedTaxRate = '', policyID, transactionID, insets, onSub
const selectedOptionKey = useMemo(() => sections?.at(0)?.data?.find((taxRate) => taxRate.searchText === selectedTaxRate)?.keyForList, [sections, selectedTaxRate]);

const handleSelectRow = useCallback(
(newSelectedOption: OptionsListUtils.TaxRatesOption) => {
(newSelectedOption: TaxOptionsListUtils.TaxRatesOption) => {
if (selectedOptionKey === newSelectedOption.keyForList) {
onDismiss();
return;
Expand Down
Loading