From 6e0815a576b0cb80e6d5ec994a1901ae4533bb3b Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 15:52:19 +0100 Subject: [PATCH 01/11] add tax amount and rate screen action types --- src/libs/Navigation/types.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index fefad04b9faf..2e50f62f8969 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -382,6 +382,7 @@ type MoneyRequestNavigatorParamList = { backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_TAX_AMOUNT]: { + action: ValueOf; iouType: ValueOf; transactionID: string; reportID: string; @@ -395,6 +396,7 @@ type MoneyRequestNavigatorParamList = { backTo: Routes; }; [SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: { + action: ValueOf; iouType: ValueOf; transactionID: string; reportID: string; From 2e545efa1fc001944bbe6da2278740177b5b0028 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 15:52:49 +0100 Subject: [PATCH 02/11] update tax amount and rate routes --- src/ROUTES.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 7efc1f676f26..77db7b31445b 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -324,14 +324,14 @@ const ROUTES = { getUrlWithBackToParam(`${action}/${iouType}/amount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_TAX_RATE: { - route: 'create/:iouType/taxRate/:transactionID/:reportID?', - getRoute: (iouType: ValueOf, transactionID: string, reportID: string, backTo: string) => - getUrlWithBackToParam(`create/${iouType}/taxRate/${transactionID}/${reportID}`, backTo), + route: ':action/:iouType/taxRate/:transactionID/:reportID?', + getRoute: (action: ValueOf, iouType: ValueOf, 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, transactionID: string, reportID: string, backTo: string) => - getUrlWithBackToParam(`create/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo), + route: ':action/:iouType/taxAmount/:transactionID/:reportID?', + getRoute: (action: ValueOf, iouType: ValueOf, transactionID: string, reportID: string, backTo = '') => + getUrlWithBackToParam(`${action}/${iouType}/taxAmount/${transactionID}/${reportID}`, backTo), }, MONEY_REQUEST_STEP_CATEGORY: { route: ':action/:iouType/category/:transactionID/:reportID/:reportActionID?', From 54a1c784095f680783efe686f180f64e09a28e6a Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 15:53:47 +0100 Subject: [PATCH 03/11] use new tax amount and rate routes in confirmation list --- src/components/MoneyRequestConfirmationList.tsx | 16 ++++++++++++++-- ...emporaryForRefactorRequestConfirmationList.js | 12 ++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index e1e39279336f..d39e40179a9f 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -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} @@ -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} diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js index 8c236d020645..02da47d62e62 100755 --- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js +++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js @@ -860,7 +860,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} /> @@ -877,7 +881,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} /> From 6d26a825f7127553c2b185e354607dbb49e72057 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 15:54:13 +0100 Subject: [PATCH 04/11] use new tax amount and rate routes in money request view --- src/components/ReportActionItem/MoneyRequestView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 9f4e4dd84914..e2fb34009f0a 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -446,7 +446,7 @@ 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))} /> )} @@ -459,7 +459,7 @@ 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))} /> )} From cd812e8d506ffaeb527daa0766eca2f8f17d3e2b Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 15:55:17 +0100 Subject: [PATCH 05/11] tax amount page should request and edit tax amount --- .../step/IOURequestStepTaxAmountPage.tsx | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx index bf4a169058be..019f3f1d8b65 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx @@ -6,6 +6,7 @@ import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types'; import useLocalize from '@hooks/useLocalize'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import type {CurrentMoney} from '@pages/iou/steps/MoneyRequestAmountForm'; import MoneyRequestAmountForm from '@pages/iou/steps/MoneyRequestAmountForm'; @@ -14,7 +15,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Policy, Transaction} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagList, Transaction} from '@src/types/onyx'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; @@ -22,6 +23,10 @@ import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepTaxAmountPageOnyxProps = { policy: OnyxEntry; + policyCategories: OnyxEntry; + + /** Collection of tag list on a policy */ + policyTags: OnyxEntry; }; type IOURequestStepTaxAmountPageProps = IOURequestStepTaxAmountPageOnyxProps & @@ -39,20 +44,24 @@ function getTaxAmount(transaction: OnyxEntry, defaultTaxValue: stri function IOURequestStepTaxAmountPage({ route: { - params: {iouType, reportID, transactionID, backTo}, + params: {action, iouType, reportID, transactionID, backTo}, }, transaction, report, policy, + policyTags, + policyCategories, }: IOURequestStepTaxAmountPageProps) { const {translate} = useLocalize(); const textInput = useRef(); - const isEditing = Navigation.getActiveRoute().includes('taxAmount'); + const isEditing = action === CONST.IOU.ACTION.EDIT; const focusTimeoutRef = useRef(); const isSaveButtonPressed = useRef(false); const originalCurrency = useRef(); + + const transactionDetails = ReportUtils.getTransactionDetails(transaction); const taxRates = policy?.taxRates; useEffect(() => { @@ -99,6 +108,17 @@ function IOURequestStepTaxAmountPage({ const updateTaxAmount = (currentAmount: CurrentMoney) => { isSaveButtonPressed.current = true; const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount.amount)); + + if (isEditing) { + if (amountInSmallestCurrencyUnits === TransactionUtils.getTaxAmount(transaction, false)) { + navigateBack(); + return; + } + IOU.updateMoneyRequestTaxAmount(transactionID, report?.reportID ?? '', amountInSmallestCurrencyUnits, policy, policyTags, policyCategories); + navigateBack(); + return; + } + IOU.setMoneyRequestTaxAmount(transactionID, amountInSmallestCurrencyUnits, true); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing @@ -129,13 +149,13 @@ function IOURequestStepTaxAmountPage({ headerTitle={translate('iou.taxAmount')} onBackButtonPress={navigateBack} testID={IOURequestStepTaxAmountPage.displayName} - shouldShowWrapper={Boolean(backTo)} + shouldShowWrapper={Boolean(backTo || isEditing)} includeSafeAreaPaddingBottom > (textInput.current = e)} onCurrencyButtonPress={navigateToCurrencySelectionPage} @@ -151,6 +171,12 @@ const IOURequestStepTaxAmountPageWithOnyx = withOnyx `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, + policyCategories: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + }, + policyTags: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, + }, })(IOURequestStepTaxAmountPage); // eslint-disable-next-line rulesdir/no-negated-variables From a9c9dd90e5e89425c2cb72a5b9b43993453a2595 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 17:25:58 +0100 Subject: [PATCH 06/11] update tax amount page --- .../request/step/IOURequestStepTaxAmountPage.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx index 019f3f1d8b65..bac99deb0a4b 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx @@ -15,7 +15,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Policy, PolicyCategories, PolicyTagList, Transaction} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagList, TaxRate, TaxRates, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; @@ -34,12 +34,17 @@ type IOURequestStepTaxAmountPageProps = IOURequestStepTaxAmountPageOnyxProps & transaction: OnyxEntry; }; -function getTaxAmount(transaction: OnyxEntry, defaultTaxValue: string | undefined): number | undefined { +function getTaxAmount(transaction: OnyxEntry, taxRates: TaxRatesWithDefault | undefined, isEditing: boolean): number | undefined { if (!transaction?.amount) { return; } - const percentage = (transaction?.taxRate ? transaction?.taxRate?.data?.value : defaultTaxValue) ?? ''; - return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(percentage, transaction?.amount)); + const transactionTaxAmount = TransactionUtils.getAmount(transaction); + const transactionTaxCode = transaction?.taxCode ?? ''; + const defaultTaxValue = taxRates?.defaultValue; + const editingTaxPercentage = (transactionTaxCode ? taxRates?.taxes[transactionTaxCode].value : taxRates?.defaultValue) || ''; + const moneyRequestTaxPercentage = (transaction?.taxRate ? transaction?.taxRate?.data?.value : defaultTaxValue) ?? ''; + const percentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage; + return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(percentage, transactionTaxAmount)); } function IOURequestStepTaxAmountPage({ @@ -156,7 +161,7 @@ function IOURequestStepTaxAmountPage({ isEditing={Boolean(backTo || isEditing)} currency={transaction?.currency} amount={transactionDetails?.taxAmount} - taxAmount={getTaxAmount(transaction, taxRates?.defaultValue)} + taxAmount={getTaxAmount(transaction, taxRates, Boolean(backTo || isEditing))} ref={(e) => (textInput.current = e)} onCurrencyButtonPress={navigateToCurrencySelectionPage} onSubmitButtonPress={updateTaxAmount} From 9778fe94f52c1bd88dc0b1d675255ee440458c35 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 17:26:20 +0100 Subject: [PATCH 07/11] update tax rate page --- .../step/IOURequestStepTaxRatePage.tsx | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx index 7ab9ab1d0961..afe1e8263605 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx @@ -6,11 +6,13 @@ import useLocalize from '@hooks/useLocalize'; import * as CurrencyUtils from '@libs/CurrencyUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; +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 type SCREENS from '@src/SCREENS'; -import type {Policy, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagList, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; @@ -18,6 +20,10 @@ import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepTaxRatePageOnyxProps = { policy: OnyxEntry; + policyCategories: OnyxEntry; + + /** Collection of tag list on a policy */ + policyTags: OnyxEntry; }; type IOURequestStepTaxRatePageProps = IOURequestStepTaxRatePageOnyxProps & @@ -34,23 +40,39 @@ function getTaxAmount(taxRates: TaxRatesWithDefault, selectedTaxRate: string, am function IOURequestStepTaxRatePage({ route: { - params: {backTo}, + params: {action, backTo}, }, policy, transaction, report, + policyCategories, + policyTags, }: IOURequestStepTaxRatePageProps) { const {translate} = useLocalize(); + const isEditing = action === CONST.IOU.ACTION.EDIT; + const taxRates = policy?.taxRates; + const defaultExternalID = taxRates?.defaultExternalID; + const transactionDetails = ReportUtils.getTransactionDetails(transaction); + const transactionTaxCode = transactionDetails?.taxCode; + const navigateBack = () => { Navigation.goBack(backTo); }; - const taxRates = policy?.taxRates; - const defaultTaxKey = taxRates?.defaultExternalID; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const selectedTaxRate = transaction?.taxRate?.keyForList || defaultTaxKey; + const selectedTaxRate = transactionTaxCode === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : transaction?.taxRate?.keyForList; const updateTaxRates = (taxes: OptionsListUtils.TaxRatesOption) => { + if (isEditing) { + const newTaxCode = taxes.data.code; + if (newTaxCode === undefined || newTaxCode === TransactionUtils.getTaxCode(transaction)) { + navigateBack(); + return; + } + IOU.updateMoneyRequestTaxRate(transaction?.transactionID ?? '', report?.reportID ?? '', newTaxCode, policy, policyTags, policyCategories); + navigateBack(); + return; + } if (!transaction || !taxes.text || !taxRates) { Navigation.goBack(backTo); return; @@ -89,6 +111,12 @@ const IOURequestStepTaxRatePageWithOnyx = withOnyx `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, + policyCategories: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + }, + policyTags: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, + }, })(IOURequestStepTaxRatePage); // eslint-disable-next-line rulesdir/no-negated-variables From ccbe3f71c5df2d9973c2d3dd66c3e0ef1f9badaa Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 17:59:45 +0100 Subject: [PATCH 08/11] fix taxPicker default selected --- .../iou/request/step/IOURequestStepTaxRatePage.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx index afe1e8263605..7dc63215bf4f 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx @@ -60,11 +60,17 @@ function IOURequestStepTaxRatePage({ Navigation.goBack(backTo); }; // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const selectedTaxRate = transactionTaxCode === defaultExternalID ? taxRates && TransactionUtils.getDefaultTaxName(taxRates) : transaction?.taxRate?.keyForList; + const moneyRequestSelectedTaxRate = transaction?.taxRate?.keyForList || (taxRates && TransactionUtils.getDefaultTaxName(taxRates)); + const editingSelectedTaxRate = + taxRates && + (transactionTaxCode === defaultExternalID + ? transaction && TransactionUtils.getDefaultTaxName(taxRates, transaction) + : transactionTaxCode && TransactionUtils.getTaxName(taxRates.taxes, transactionTaxCode)); const updateTaxRates = (taxes: OptionsListUtils.TaxRatesOption) => { if (isEditing) { const newTaxCode = taxes.data.code; + console.log('tax rate ', newTaxCode); if (newTaxCode === undefined || newTaxCode === TransactionUtils.getTaxCode(transaction)) { navigateBack(); return; @@ -97,7 +103,7 @@ function IOURequestStepTaxRatePage({ testID={IOURequestStepTaxRatePage.displayName} > From 59ebbc8956cb78a22d7b745b9791ee46c7bf2965 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 18:08:23 +0100 Subject: [PATCH 09/11] fix lint --- src/components/ReportActionItem/MoneyRequestView.tsx | 12 ++++++++++-- .../iou/request/step/IOURequestStepTaxAmountPage.tsx | 4 ++-- .../iou/request/step/IOURequestStepTaxRatePage.tsx | 1 - 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index e2fb34009f0a..dd34d0ca2540 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -446,7 +446,11 @@ function MoneyRequestView({ interactive={canEdit} shouldShowRightIcon={canEdit} titleStyle={styles.flex1} - onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST,transaction?.transactionID ?? '', report.reportID))} + onPress={() => + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_TAX_RATE.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID), + ) + } /> )} @@ -459,7 +463,11 @@ function MoneyRequestView({ interactive={canEdit} shouldShowRightIcon={canEdit} titleStyle={styles.flex1} - onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST,transaction?.transactionID ?? '', report.reportID))} + onPress={() => + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_TAX_AMOUNT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID), + ) + } /> )} diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx index bac99deb0a4b..3546fe477478 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx @@ -15,7 +15,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {Policy, PolicyCategories, PolicyTagList, TaxRate, TaxRates, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; +import type {Policy, PolicyCategories, PolicyTagList, TaxRatesWithDefault, Transaction} from '@src/types/onyx'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; @@ -41,7 +41,7 @@ function getTaxAmount(transaction: OnyxEntry, taxRates: TaxRatesWit const transactionTaxAmount = TransactionUtils.getAmount(transaction); const transactionTaxCode = transaction?.taxCode ?? ''; const defaultTaxValue = taxRates?.defaultValue; - const editingTaxPercentage = (transactionTaxCode ? taxRates?.taxes[transactionTaxCode].value : taxRates?.defaultValue) || ''; + const editingTaxPercentage = (transactionTaxCode ? taxRates?.taxes[transactionTaxCode].value : taxRates?.defaultValue) ?? ''; const moneyRequestTaxPercentage = (transaction?.taxRate ? transaction?.taxRate?.data?.value : defaultTaxValue) ?? ''; const percentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage; return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(percentage, transactionTaxAmount)); diff --git a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx index 7dc63215bf4f..da3a244a2db2 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx @@ -70,7 +70,6 @@ function IOURequestStepTaxRatePage({ const updateTaxRates = (taxes: OptionsListUtils.TaxRatesOption) => { if (isEditing) { const newTaxCode = taxes.data.code; - console.log('tax rate ', newTaxCode); if (newTaxCode === undefined || newTaxCode === TransactionUtils.getTaxCode(transaction)) { navigateBack(); return; From deb1ac7bb6f71b7874f01bf35d4c2dbd993b15ab Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Fri, 5 Apr 2024 18:17:49 +0100 Subject: [PATCH 10/11] remove edit request tax amount and rate pages --- src/pages/EditRequestPage.js | 74 +------------------------- src/pages/EditRequestTaxAmountPage.tsx | 66 ----------------------- src/pages/EditRequestTaxRatePage.tsx | 44 --------------- 3 files changed, 1 insertion(+), 183 deletions(-) delete mode 100644 src/pages/EditRequestTaxAmountPage.tsx delete mode 100644 src/pages/EditRequestTaxRatePage.tsx diff --git a/src/pages/EditRequestPage.js b/src/pages/EditRequestPage.js index ec49e32a5f0f..d3941dca044e 100644 --- a/src/pages/EditRequestPage.js +++ b/src/pages/EditRequestPage.js @@ -8,12 +8,10 @@ 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'; @@ -21,8 +19,6 @@ 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'; @@ -72,17 +68,10 @@ const defaultProps = { transaction: {}, }; -const getTaxAmount = (transactionAmount, transactionTaxCode, taxRates) => { - const percentage = (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)); @@ -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. @@ -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; @@ -182,27 +131,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p ); } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAX_AMOUNT && shouldShowTax) { - return ( - - ); - } - - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.TAX_RATE && shouldShowTax) { - return ( - - ); - } - if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT) { return ( void; -}; - -function EditRequestTaxAmountPage({defaultAmount, defaultTaxAmount, defaultCurrency, onSubmit}: EditRequestTaxAmountPageProps) { - const {translate} = useLocalize(); - const textInput = useRef(); - - const focusTimeoutRef = useRef(null); - - useFocusEffect( - useCallback(() => { - focusTimeoutRef.current = setTimeout(() => textInput.current?.focus(), CONST.ANIMATED_TRANSITION); - return () => { - if (!focusTimeoutRef.current) { - return; - } - clearTimeout(focusTimeoutRef.current); - }; - }, []), - ); - - return ( - - - (textInput.current = e)} - isCurrencyPressable={false} - onSubmitButtonPress={onSubmit} - isEditing - /> - - ); -} - -EditRequestTaxAmountPage.displayName = 'EditRequestTaxAmountPage'; - -export default EditRequestTaxAmountPage; diff --git a/src/pages/EditRequestTaxRatePage.tsx b/src/pages/EditRequestTaxRatePage.tsx deleted file mode 100644 index 099851e92209..000000000000 --- a/src/pages/EditRequestTaxRatePage.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react'; -import HeaderWithBackButton from '@components/HeaderWithBackButton'; -import ScreenWrapper from '@components/ScreenWrapper'; -import TaxPicker from '@components/TaxPicker'; -import useLocalize from '@hooks/useLocalize'; - -type EditRequestTaxRatePageProps = { - /** Transaction default tax Rate value */ - defaultTaxRate: string; - - /** The policyID we are getting categories for */ - policyID: string; - - /** Callback to fire when the Save button is pressed */ - onSubmit: () => void; -}; - -function EditRequestTaxRatePage({defaultTaxRate, policyID, onSubmit}: EditRequestTaxRatePageProps) { - const {translate} = useLocalize(); - - return ( - - {({insets}) => ( - <> - - - - )} - - ); -} - -EditRequestTaxRatePage.displayName = 'EditRequestTaxRatePage'; - -export default EditRequestTaxRatePage; From 829a8c4586ad1d7b5717a9c3f5d7acf9b9263476 Mon Sep 17 00:00:00 2001 From: Etotaziba Olei Date: Tue, 9 Apr 2024 08:03:48 +0100 Subject: [PATCH 11/11] fix comment reviews --- src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx index 3546fe477478..a88de35a5025 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx @@ -41,10 +41,10 @@ function getTaxAmount(transaction: OnyxEntry, taxRates: TaxRatesWit const transactionTaxAmount = TransactionUtils.getAmount(transaction); const transactionTaxCode = transaction?.taxCode ?? ''; const defaultTaxValue = taxRates?.defaultValue; - const editingTaxPercentage = (transactionTaxCode ? taxRates?.taxes[transactionTaxCode].value : taxRates?.defaultValue) ?? ''; + const editingTaxPercentage = (transactionTaxCode ? taxRates?.taxes[transactionTaxCode]?.value : taxRates?.defaultValue) ?? ''; const moneyRequestTaxPercentage = (transaction?.taxRate ? transaction?.taxRate?.data?.value : defaultTaxValue) ?? ''; - const percentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage; - return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(percentage, transactionTaxAmount)); + const taxPercentage = isEditing ? editingTaxPercentage : moneyRequestTaxPercentage; + return CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, transactionTaxAmount)); } function IOURequestStepTaxAmountPage({