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

fix: user is navigated back to same iou #39723

12 changes: 6 additions & 6 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ const ROUTES = {
getUrlWithBackToParam(`${action}/${iouType}/amount/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAX_RATE: {
route: 'create/:iouType/taxRate/:transactionID/:reportID?',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo: string) =>
getUrlWithBackToParam(`create/${iouType}/taxRate/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/taxRate/:transactionID/:reportID?',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/taxRate/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAX_AMOUNT: {
route: 'create/:iouType/taxAmount/:transactionID/:reportID?',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo: string) =>
getUrlWithBackToParam(`create/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/taxAmount/:transactionID/:reportID?',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_CATEGORY: {
route: ':action/:iouType/category/:transactionID/:reportID/:reportActionID?',
Expand Down
16 changes: 14 additions & 2 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,13 @@ function MoneyRequestConfirmationList({
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams()),
ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(
CONST.IOU.ACTION.CREATE,
iouType,
transaction?.transactionID ?? '',
reportID,
Navigation.getActiveRouteWithoutParams(),
),
)
}
disabled={didConfirm}
Expand All @@ -846,7 +852,13 @@ function MoneyRequestConfirmationList({
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(iouType, transaction?.transactionID ?? '', reportID, Navigation.getActiveRouteWithoutParams()),
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(
CONST.IOU.ACTION.CREATE,
iouType,
transaction?.transactionID ?? '',
reportID,
Navigation.getActiveRouteWithoutParams(),
),
)
}
disabled={didConfirm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,11 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
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()))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.CREATE, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()),
)
}
disabled={didConfirm}
interactive={!isReadOnly}
/>
Expand All @@ -887,7 +891,11 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
description={translate('iou.taxAmount')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.CREATE, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()),
)
}
disabled={didConfirm}
interactive={!isReadOnly}
/>
Expand Down
12 changes: 10 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,11 @@ function MoneyRequestView({
interactive={canEdit}
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.TAX_RATE))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID),
)
}
/>
</OfflineWithFeedback>
)}
Expand All @@ -459,7 +463,11 @@ function MoneyRequestView({
interactive={canEdit}
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.TAX_AMOUNT))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID),
)
}
/>
</OfflineWithFeedback>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ type MoneyRequestNavigatorParamList = {
backTo: Routes;
};
[SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: {
action: ValueOf<typeof CONST.IOU.ACTION>;
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
reportID: string;
Expand All @@ -390,6 +391,7 @@ type MoneyRequestNavigatorParamList = {
backTo: Routes;
};
[SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: {
action: ValueOf<typeof CONST.IOU.ACTION>;
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
reportID: string;
Expand Down
74 changes: 1 addition & 73 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ import ScreenWrapper from '@components/ScreenWrapper';
import tagPropTypes from '@components/tagPropTypes';
import transactionPropTypes from '@components/transactionPropTypes';
import compose from '@libs/compose';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import EditRequestReceiptPage from './EditRequestReceiptPage';
import EditRequestTagPage from './EditRequestTagPage';
import EditRequestTaxAmountPage from './EditRequestTaxAmountPage';
import EditRequestTaxRatePage from './EditRequestTaxRatePage';
import reportActionPropTypes from './home/report/reportActionPropTypes';
import reportPropTypes from './reportPropTypes';
import {policyPropTypes} from './workspace/withPolicy';
Expand Down Expand Up @@ -72,17 +68,10 @@ const defaultProps = {
transaction: {},
};

const getTaxAmount = (transactionAmount, transactionTaxCode, taxRates) => {
const percentage = (transactionTaxCode && taxRates.taxes[transactionTaxCode] ? taxRates.taxes[transactionTaxCode].value : taxRates.defaultValue) || '';
return CurrencyUtils.convertToBackendAmount(Number.parseFloat(TransactionUtils.calculateTaxAmount(percentage, transactionAmount)));
};

function EditRequestPage({report, route, policy, policyCategories, policyTags, parentReportActions, transaction}) {
const parentReportActionID = lodashGet(report, 'parentReportActionID', '0');
const parentReportAction = lodashGet(parentReportActions, parentReportActionID, {});
const {taxAmount: transactionTaxAmount, taxCode: transactionTaxCode, currency: transactionCurrency, tag: transactionTag} = ReportUtils.getTransactionDetails(transaction);

const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency;
const {tag: transactionTag} = ReportUtils.getTransactionDetails(transaction);

const fieldToEdit = lodashGet(route, ['params', 'field'], '');
const tagListIndex = Number(lodashGet(route, ['params', 'tagIndex'], undefined));
Expand All @@ -91,23 +80,12 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
const policyTagListName = PolicyUtils.getTagListName(policyTags, tagListIndex);
const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]);

const taxRates = lodashGet(policy, 'taxRates', {});

const taxRateTitle =
taxRates &&
(transactionTaxCode === taxRates.defaultExternalID
? transaction && TransactionUtils.getDefaultTaxName(taxRates, transaction)
: transactionTaxCode && TransactionUtils.getTaxName(taxRates.taxes, transactionTaxCode));

// A flag for verifying that the current report is a sub-report of a workspace chat
const isPolicyExpenseChat = ReportUtils.isGroupPolicy(report);

// A flag for showing the tags page
const shouldShowTags = useMemo(() => isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)), [isPolicyExpenseChat, policyTagLists, transactionTag]);

// A flag for showing tax rate
const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy);

// Decides whether to allow or disallow editing a money request
useEffect(() => {
// Do not dismiss the modal, when a current user can edit this property of the money request.
Expand All @@ -121,35 +99,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
});
}, [parentReportAction, fieldToEdit]);

const updateTaxAmount = useCallback(
(transactionChanges) => {
const newTaxAmount = CurrencyUtils.convertToBackendAmount(Number.parseFloat(transactionChanges.amount));

if (newTaxAmount === TransactionUtils.getTaxAmount(transaction)) {
Navigation.dismissModal();
return;
}
IOU.updateMoneyRequestTaxAmount(transaction.transactionID, report.reportID, newTaxAmount, policy, policyTags, policyCategories);
Navigation.dismissModal(report.reportID);
},
[transaction, report, policy, policyTags, policyCategories],
);

const updateTaxRate = useCallback(
(transactionChanges) => {
const newTaxCode = transactionChanges.data.code;

if (newTaxCode === undefined || newTaxCode === TransactionUtils.getTaxCode(transaction)) {
Navigation.dismissModal();
return;
}

IOU.updateMoneyRequestTaxRate(transaction.transactionID, report.reportID, newTaxCode, policy, policyTags, policyCategories);
Navigation.dismissModal(report.reportID);
},
[transaction, report, policy, policyTags, policyCategories],
);

const saveTag = useCallback(
({tag: newTag}) => {
let updatedTag = newTag;
Expand Down Expand Up @@ -182,27 +131,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAX_AMOUNT && shouldShowTax) {
return (
<EditRequestTaxAmountPage
defaultAmount={transactionTaxAmount}
defaultTaxAmount={getTaxAmount(TransactionUtils.getAmount(transaction), transactionTaxCode, taxRates)}
defaultCurrency={defaultCurrency}
onSubmit={updateTaxAmount}
/>
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAX_RATE && shouldShowTax) {
return (
<EditRequestTaxRatePage
defaultTaxRate={taxRateTitle}
policyID={lodashGet(report, 'policyID', '')}
onSubmit={updateTaxRate}
/>
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT) {
return (
<EditRequestReceiptPage
Expand Down
66 changes: 0 additions & 66 deletions src/pages/EditRequestTaxAmountPage.tsx

This file was deleted.

44 changes: 0 additions & 44 deletions src/pages/EditRequestTaxRatePage.tsx

This file was deleted.

Loading
Loading