Skip to content

Commit

Permalink
Merge pull request #43521 from dominictb/fix/42854-tax-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Jun 17, 2024
2 parents a67e55d + 7c9396e commit d7c2781
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/components/TaxPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo, useState} from 'react';
import React, {useCallback, useMemo, useState} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import type {EdgeInsets} from 'react-native-safe-area-context';
Expand Down Expand Up @@ -54,9 +54,11 @@ type TaxPickerProps = TaxPickerOnyxProps & {

/** The type of IOU */
iouType?: ValueOf<typeof CONST.IOU.TYPE>;

onDismiss: () => void;
};

function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit, action, splitDraftTransaction, iouType}: TaxPickerProps) {
function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit, action, splitDraftTransaction, iouType, onDismiss}: TaxPickerProps) {
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const [searchValue, setSearchValue] = useState('');
Expand Down Expand Up @@ -94,14 +96,25 @@ function TaxPicker({selectedTaxRate = '', policy, transaction, insets, onSubmit,

const selectedOptionKey = useMemo(() => sections?.[0]?.data?.find((taxRate) => taxRate.searchText === selectedTaxRate)?.keyForList, [sections, selectedTaxRate]);

const handleSelectRow = useCallback(
(newSelectedOption: OptionsListUtils.TaxRatesOption) => {
if (selectedOptionKey === newSelectedOption.keyForList) {
onDismiss();
return;
}
onSubmit(newSelectedOption);
},
[onSubmit, onDismiss, selectedOptionKey],
);

return (
<SelectionList
sections={sections}
headerMessage={headerMessage}
textInputValue={searchValue}
textInputLabel={shouldShowTextInput ? translate('common.search') : undefined}
onChangeText={setSearchValue}
onSelectRow={onSubmit}
onSelectRow={handleSelectRow}
ListItem={RadioListItem}
initiallyFocusedOptionKey={selectedOptionKey ?? undefined}
isRowMultilineSupported
Expand Down
5 changes: 1 addition & 4 deletions src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ function IOURequestStepTaxRatePage({

if (isEditing) {
const newTaxCode = taxes.code;
if (newTaxCode === TransactionUtils.getTaxCode(currentTransaction)) {
navigateBack();
return;
}
IOU.updateMoneyRequestTaxRate({
transactionID: currentTransaction?.transactionID ?? '-1',
optimisticReportActionID: report?.reportID ?? '-1',
Expand Down Expand Up @@ -127,6 +123,7 @@ function IOURequestStepTaxRatePage({
onSubmit={updateTaxRates}
action={action}
iouType={iouType}
onDismiss={navigateBack}
/>
</StepScreenWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function WorkspaceTaxesSettingsForeignCurrency({
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

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 @@ -60,6 +64,7 @@ function WorkspaceTaxesSettingsForeignCurrency({
policyID={policyID}
insets={insets}
onSubmit={submit}
onDismiss={dismiss}
/>
</View>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({
Navigation.goBack(ROUTES.WORKSPACE_TAXES_SETTINGS.getRoute(policyID));
};

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 @@ -60,6 +64,7 @@ function WorkspaceTaxesSettingsWorkspaceCurrency({
policyID={policyID}
insets={insets}
onSubmit={submit}
onDismiss={dismiss}
/>
</View>
</>
Expand Down

0 comments on commit d7c2781

Please sign in to comment.