From f16b3c566acb4f683ded9a20077e109a51f63559 Mon Sep 17 00:00:00 2001 From: Puneet Lath Date: Mon, 27 May 2024 17:17:37 -0400 Subject: [PATCH] Merge pull request #42670 from Expensify/revert-40240-monil-splitBillTaxUpdate Revert "Handle tax for split requests" (cherry picked from commit 0b293ea2e505ffc69f558cd74ad0d955c5859957) --- .../MoneyRequestConfirmationList.tsx | 63 +++++++++---------- src/libs/API/parameters/SplitBillParams.ts | 2 - src/libs/actions/IOU.ts | 29 ++------- .../iou/request/step/IOURequestStepAmount.tsx | 35 +++++++---- .../step/IOURequestStepConfirmation.tsx | 10 +-- .../step/IOURequestStepParticipants.tsx | 4 +- .../step/IOURequestStepTaxAmountPage.tsx | 28 ++------- .../step/IOURequestStepTaxRatePage.tsx | 42 +++---------- src/types/onyx/IOU.ts | 2 - 9 files changed, 72 insertions(+), 143 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 65a83090a059..bb7e3ac4f78e 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -178,15 +178,11 @@ type MoneyRequestConfirmationListProps = MoneyRequestConfirmationListOnyxProps & type MoneyRequestConfirmationListItem = Participant | ReportUtils.OptionData; -/** - * Calculate and set tax amount in transaction draft - */ -const setTaxAmountInDraft = (transaction: OnyxEntry, policy: OnyxEntry) => { +const getTaxAmount = (transaction: OnyxEntry, policy: OnyxEntry) => { const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction) ?? ''; + const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, transaction?.taxCode ?? defaultTaxCode) ?? ''; - const taxAmount = TransactionUtils.calculateTaxAmount(taxPercentage, transaction?.amount ?? 0); - const taxAmountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(taxAmount.toString())); - IOU.setMoneyRequestTaxAmount(transaction?.transactionID ?? '', taxAmountInSmallestCurrencyUnits, true); + return TransactionUtils.calculateTaxAmount(taxPercentage, transaction?.amount ?? 0); }; function MoneyRequestConfirmationList({ @@ -248,6 +244,16 @@ function MoneyRequestConfirmationList({ const transactionID = transaction?.transactionID ?? ''; const customUnitRateID = TransactionUtils.getRateID(transaction) ?? ''; + useEffect(() => { + if (customUnitRateID || !canUseP2PDistanceRequests) { + return; + } + if (!customUnitRateID) { + const rateID = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultMileageRate?.customUnitRateID ?? ''; + IOU.setCustomUnitRateID(transactionID, rateID); + } + }, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, canUseP2PDistanceRequests, transactionID]); + const policyCurrency = policy?.outputCurrency ?? PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD; const mileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction) @@ -308,9 +314,9 @@ function MoneyRequestConfirmationList({ ); const formattedTaxAmount = CurrencyUtils.convertToDisplayString(transaction?.taxAmount, iouCurrencyCode); const taxRateTitle = TransactionUtils.getTaxName(policy, transaction); - const prevTaxAmount = usePrevious(transaction?.taxAmount); - const prevAmount = usePrevious(transaction?.amount); - const prevCurrency = usePrevious(transaction?.currency); + + const previousTransactionAmount = usePrevious(transaction?.amount); + const previousTransactionCurrency = usePrevious(transaction?.currency); const isFocused = useIsFocused(); const [formError, debouncedFormError, setFormError] = useDebouncedState(''); @@ -339,31 +345,6 @@ function MoneyRequestConfirmationList({ const isCategoryRequired = !!policy?.requiresCategory; - useEffect(() => { - if (!shouldShowTax) { - return; - } - setTaxAmountInDraft(transaction, policy); - // eslint-disable-next-line react-hooks/exhaustive-deps -- we want to call this function when component is mounted - }, []); - - useEffect(() => { - if (!shouldShowTax || prevTaxAmount !== transaction?.taxAmount || (prevAmount === transaction?.amount && prevCurrency === transaction?.currency)) { - return; - } - setTaxAmountInDraft(transaction, policy); - }, [policy, shouldShowTax, prevTaxAmount, prevAmount, prevCurrency, transaction]); - - useEffect(() => { - if (customUnitRateID || !canUseP2PDistanceRequests) { - return; - } - if (!customUnitRateID) { - const rateID = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultMileageRate?.customUnitRateID ?? ''; - IOU.setCustomUnitRateID(transactionID, rateID); - } - }, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, canUseP2PDistanceRequests, transactionID]); - useEffect(() => { if (shouldDisplayFieldError && hasSmartScanFailed) { setFormError('iou.receiptScanningFailed'); @@ -388,6 +369,18 @@ function MoneyRequestConfirmationList({ IOU.setMoneyRequestAmount(transactionID, amount, currency ?? ''); }, [shouldCalculateDistanceAmount, distance, rate, unit, transactionID, currency]); + // Calculate and set tax amount in transaction draft + useEffect(() => { + const taxAmount = getTaxAmount(transaction, policy).toString(); + const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(taxAmount)); + + if (transaction?.taxAmount && previousTransactionAmount === transaction?.amount && previousTransactionCurrency === transaction?.currency) { + return IOU.setMoneyRequestTaxAmount(transactionID, transaction?.taxAmount ?? 0, true); + } + + IOU.setMoneyRequestTaxAmount(transactionID, amountInSmallestCurrencyUnits, true); + }, [policy, transaction, transactionID, previousTransactionAmount, previousTransactionCurrency]); + // If completing a split expense fails, set didConfirm to false to allow the user to edit the fields again if (isEditingSplitBill && didConfirm) { setDidConfirm(false); diff --git a/src/libs/API/parameters/SplitBillParams.ts b/src/libs/API/parameters/SplitBillParams.ts index 76252abe3292..dd5a88141222 100644 --- a/src/libs/API/parameters/SplitBillParams.ts +++ b/src/libs/API/parameters/SplitBillParams.ts @@ -15,8 +15,6 @@ type SplitBillParams = { policyID: string | undefined; chatType: string | undefined; splitPayerAccountIDs: number[]; - taxCode: string; - taxAmount: number; }; export default SplitBillParams; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 1eb00b99c5c4..0bc72a387227 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -3726,8 +3726,6 @@ function createSplitsAndOnyxData( existingSplitChatReportID = '', billable = false, iouRequestType: IOURequestType = CONST.IOU.REQUEST_TYPE.MANUAL, - taxCode = '', - taxAmount = 0, ): SplitsAndOnyxData { const currentUserEmailForIOUSplit = PhoneNumber.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = participants.map((participant) => Number(participant.accountID)); @@ -3749,8 +3747,8 @@ function createSplitsAndOnyxData( undefined, category, tag, - taxCode, - taxAmount, + undefined, + undefined, billable, ); @@ -3905,16 +3903,14 @@ function createSplitsAndOnyxData( // Loop through participants creating individual chats, iouReports and reportActionIDs as needed const currentUserAmount = splitShares?.[currentUserAccountID]?.amount ?? IOUUtils.calculateAmount(participants.length, amount, currency, true); - const currentUserTaxAmount = IOUUtils.calculateAmount(participants.length, taxAmount, currency, true); - const splits: Split[] = [{email: currentUserEmailForIOUSplit, accountID: currentUserAccountID, amount: currentUserAmount, taxAmount: currentUserTaxAmount}]; + const splits: Split[] = [{email: currentUserEmailForIOUSplit, accountID: currentUserAccountID, amount: currentUserAmount}]; const hasMultipleParticipants = participants.length > 1; participants.forEach((participant) => { // In a case when a participant is a workspace, even when a current user is not an owner of the workspace const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(participant); const splitAmount = splitShares?.[participant.accountID ?? -1]?.amount ?? IOUUtils.calculateAmount(participants.length, amount, currency, false); - const splitTaxAmount = IOUUtils.calculateAmount(participants.length, taxAmount, currency, false); // To exclude someone from a split, the amount can be 0. The scenario for this is when creating a split from a group chat, we have remove the option to deselect users to exclude them. // We can input '0' next to someone we want to exclude. @@ -3984,8 +3980,8 @@ function createSplitsAndOnyxData( undefined, category, tag, - taxCode, - ReportUtils.isExpenseReport(oneOnOneIOUReport) ? -splitTaxAmount : splitTaxAmount, + undefined, + undefined, billable, ); @@ -4077,7 +4073,6 @@ function createSplitsAndOnyxData( reportPreviewReportActionID: oneOnOneReportPreviewAction.reportActionID, transactionThreadReportID: optimisticTransactionThread.reportID, createdReportActionIDForThread: optimisticCreatedActionForTransactionThread.reportActionID, - taxAmount: splitTaxAmount, }; splits.push(individualSplit); @@ -4131,8 +4126,6 @@ type SplitBillActionsParams = { existingSplitChatReportID?: string; splitShares?: SplitShares; splitPayerAccountIDs?: number[]; - taxCode?: string; - taxAmount?: number; }; /** @@ -4155,8 +4148,6 @@ function splitBill({ existingSplitChatReportID = '', splitShares = {}, splitPayerAccountIDs = [], - taxCode = '', - taxAmount = 0, }: SplitBillActionsParams) { const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); const {splitData, splits, onyxData} = createSplitsAndOnyxData( @@ -4174,8 +4165,6 @@ function splitBill({ existingSplitChatReportID, billable, iouRequestType, - taxCode, - taxAmount, ); const parameters: SplitBillParams = { @@ -4195,8 +4184,6 @@ function splitBill({ policyID: splitData.policyID, chatType: splitData.chatType, splitPayerAccountIDs, - taxCode, - taxAmount, }; API.write(WRITE_COMMANDS.SPLIT_BILL, parameters, onyxData); @@ -4223,8 +4210,6 @@ function splitBillAndOpenReport({ iouRequestType = CONST.IOU.REQUEST_TYPE.MANUAL, splitShares = {}, splitPayerAccountIDs = [], - taxCode = '', - taxAmount = 0, }: SplitBillActionsParams) { const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created); const {splitData, splits, onyxData} = createSplitsAndOnyxData( @@ -4242,8 +4227,6 @@ function splitBillAndOpenReport({ '', billable, iouRequestType, - taxCode, - taxAmount, ); const parameters: SplitBillParams = { @@ -4263,8 +4246,6 @@ function splitBillAndOpenReport({ policyID: splitData.policyID, chatType: splitData.chatType, splitPayerAccountIDs, - taxCode, - taxAmount, }; API.write(WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT, parameters, onyxData); diff --git a/src/pages/iou/request/step/IOURequestStepAmount.tsx b/src/pages/iou/request/step/IOURequestStepAmount.tsx index 4ae2784f61b1..18dc951f949b 100644 --- a/src/pages/iou/request/step/IOURequestStepAmount.tsx +++ b/src/pages/iou/request/step/IOURequestStepAmount.tsx @@ -39,6 +39,9 @@ type IOURequestStepAmountOnyxProps = { /** Whether the confirmation step should be skipped */ skipConfirmation: OnyxEntry; + /** The draft transaction object being modified in Onyx */ + draftTransaction: OnyxEntry; + /** Personal details of all users */ personalDetails: OnyxEntry; @@ -64,6 +67,7 @@ function IOURequestStepAmount({ currentUserPersonalDetails, splitDraftTransaction, skipConfirmation, + draftTransaction, }: IOURequestStepAmountProps) { const {translate} = useLocalize(); const textInput = useRef(null); @@ -74,9 +78,8 @@ function IOURequestStepAmount({ const isEditing = action === CONST.IOU.ACTION.EDIT; const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const isEditingSplitBill = isEditing && isSplitBill; - const currentTransaction = isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction; - const {amount: transactionAmount} = ReportUtils.getTransactionDetails(currentTransaction) ?? {amount: 0}; - const {currency: originalCurrency} = ReportUtils.getTransactionDetails(currentTransaction) ?? {currency: CONST.CURRENCY.USD}; + const {amount: transactionAmount} = ReportUtils.getTransactionDetails(isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction) ?? {amount: 0}; + const {currency: originalCurrency} = ReportUtils.getTransactionDetails(isEditing ? draftTransaction : transaction) ?? {currency: CONST.CURRENCY.USD}; const currency = CurrencyUtils.isValidCurrencyCode(selectedCurrency) ? selectedCurrency : originalCurrency; // For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace request, as @@ -266,25 +269,25 @@ function IOURequestStepAmount({ } // If the value hasn't changed, don't request to save changes on the server and just close the modal - const transactionCurrency = TransactionUtils.getCurrency(currentTransaction); - if (newAmount === TransactionUtils.getAmount(currentTransaction) && currency === transactionCurrency) { + const transactionCurrency = TransactionUtils.getCurrency(transaction); + if (newAmount === TransactionUtils.getAmount(transaction) && currency === transactionCurrency) { Navigation.dismissModal(); return; } - // If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. - const transactionTaxCode = ReportUtils.getTransactionDetails(currentTransaction)?.taxCode; - const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, currentTransaction, currency) ?? ''; - const taxCode = (currency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; - const taxPercentage = TransactionUtils.getTaxValue(policy, currentTransaction, taxCode) ?? ''; - const taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, newAmount)); - if (isSplitBill) { - IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency, taxCode, taxAmount}); + IOU.setDraftSplitTransaction(transactionID, {amount: newAmount, currency}); Navigation.goBack(backTo); return; } + // If currency has changed, then we get the default tax rate based on currency, otherwise we use the current tax rate selected in transaction, if we have it. + const transactionTaxCode = transaction?.taxCode ?? ''; + const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction, currency) ?? ''; + const taxCode = (currency !== transactionCurrency ? defaultTaxCode : transactionTaxCode) ?? defaultTaxCode; + const taxPercentage = TransactionUtils.getTaxValue(policy, transaction, taxCode) ?? ''; + const taxAmount = CurrencyUtils.convertToBackendAmount(TransactionUtils.calculateTaxAmount(taxPercentage, newAmount)); + IOU.updateMoneyRequestAmountAndCurrency({transactionID, transactionThreadReportID: reportID, currency, amount: newAmount, taxAmount, policy, taxCode}); Navigation.dismissModal(); }; @@ -323,6 +326,12 @@ const IOURequestStepAmountWithOnyx = withOnyx { + const transactionID = route.params.transactionID ?? 0; + return `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`; + }, + }, skipConfirmation: { key: ({route}) => { const transactionID = route.params.transactionID ?? 0; diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index d0cdf956e07d..458df99a5f6c 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -325,9 +325,7 @@ function IOURequestStepConfirmation({ const participantsWithAmount = Object.keys(transaction.splitShares ?? {}) .filter((accountID: string): boolean => (transaction?.splitShares?.[Number(accountID)]?.amount ?? 0) > 0) .map((accountID) => Number(accountID)); - splitParticipants = selectedParticipants.filter((participant) => - participantsWithAmount.includes(participant.isPolicyExpenseChat ? participant?.ownerAccountID ?? -1 : participant.accountID ?? -1), - ); + splitParticipants = selectedParticipants.filter((participant) => participantsWithAmount.includes(participant.accountID ?? -1)); } const trimmedComment = (transaction?.comment.comment ?? '').trim(); @@ -377,8 +375,6 @@ function IOURequestStepConfirmation({ iouRequestType: transaction.iouRequestType, splitShares: transaction.splitShares, splitPayerAccountIDs: transaction.splitPayerAccountIDs ?? [], - taxCode: transactionTaxCode, - taxAmount: transactionTaxAmount, }); } return; @@ -402,8 +398,6 @@ function IOURequestStepConfirmation({ iouRequestType: transaction.iouRequestType, splitShares: transaction.splitShares, splitPayerAccountIDs: transaction.splitPayerAccountIDs, - taxCode: transactionTaxCode, - taxAmount: transactionTaxAmount, }); } return; @@ -499,8 +493,6 @@ function IOURequestStepConfirmation({ policy, policyTags, policyCategories, - transactionTaxAmount, - transactionTaxCode, ], ); diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index 89c6a4043b28..e0be24db5c85 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -41,9 +41,7 @@ function IOURequestStepParticipants({ const participants = transaction?.participants; const {translate} = useLocalize(); const styles = useThemeStyles(); - - // We need to set selectedReportID if user has navigated back from confirmation page and navigates to confirmation page with already selected participant - const selectedReportID = useRef(participants?.length === 1 ? participants[0]?.reportID ?? reportID : reportID); + const selectedReportID = useRef(reportID); const numberOfParticipants = useRef(participants?.length ?? 0); const iouRequestType = TransactionUtils.getRequestType(transaction); const isSplitRequest = iouType === CONST.IOU.TYPE.SPLIT; diff --git a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx index fd589b6361f0..27c2808669df 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxAmountPage.tsx @@ -16,7 +16,6 @@ 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 {isEmptyObject} from '@src/types/utils/EmptyObject'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; @@ -28,9 +27,6 @@ type IOURequestStepTaxAmountPageOnyxProps = { /** Collection of tag list on a policy */ policyTags: OnyxEntry; - - /** The draft transaction that holds data to be persisted on the current transaction */ - splitDraftTransaction: OnyxEntry; }; type IOURequestStepTaxAmountPageProps = IOURequestStepTaxAmountPageOnyxProps & @@ -62,16 +58,14 @@ function IOURequestStepTaxAmountPage({ policy, policyTags, policyCategories, - splitDraftTransaction, }: IOURequestStepTaxAmountPageProps) { const {translate} = useLocalize(); const textInput = useRef(); const isEditing = action === CONST.IOU.ACTION.EDIT; - const isEditingSplitBill = isEditing && iouType === CONST.IOU.TYPE.SPLIT; const focusTimeoutRef = useRef(); - const transactionDetails = ReportUtils.getTransactionDetails(isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction); + const transactionDetails = ReportUtils.getTransactionDetails(transaction); const currency = CurrencyUtils.isValidCurrencyCode(selectedCurrency) ? selectedCurrency : transactionDetails?.currency; useFocusEffect( @@ -108,25 +102,19 @@ function IOURequestStepTaxAmountPage({ }; const updateTaxAmount = (currentAmount: CurrentMoney) => { - const taxAmountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount.amount)); - - if (isEditingSplitBill) { - IOU.setDraftSplitTransaction(transactionID, {taxAmount: taxAmountInSmallestCurrencyUnits}); - navigateBack(); - return; - } + const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(Number.parseFloat(currentAmount.amount)); if (isEditing) { - if (taxAmountInSmallestCurrencyUnits === TransactionUtils.getTaxAmount(transaction, false)) { + if (amountInSmallestCurrencyUnits === TransactionUtils.getTaxAmount(transaction, false)) { navigateBack(); return; } - IOU.updateMoneyRequestTaxAmount(transactionID, report?.reportID ?? '', taxAmountInSmallestCurrencyUnits, policy, policyTags, policyCategories); + IOU.updateMoneyRequestTaxAmount(transactionID, report?.reportID ?? '', amountInSmallestCurrencyUnits, policy, policyTags, policyCategories); navigateBack(); return; } - IOU.setMoneyRequestTaxAmount(transactionID, taxAmountInSmallestCurrencyUnits, true); + IOU.setMoneyRequestTaxAmount(transactionID, amountInSmallestCurrencyUnits, true); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing IOU.setMoneyRequestCurrency(transactionID, currency || CONST.CURRENCY.USD); @@ -176,12 +164,6 @@ function IOURequestStepTaxAmountPage({ IOURequestStepTaxAmountPage.displayName = 'IOURequestStepTaxAmountPage'; const IOURequestStepTaxAmountPageWithOnyx = withOnyx({ - splitDraftTransaction: { - key: ({route}) => { - const transactionID = route?.params.transactionID ?? 0; - return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; - }, - }, policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, diff --git a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx index d048cae15089..9376aa65e4e6 100644 --- a/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx +++ b/src/pages/iou/request/step/IOURequestStepTaxRatePage.tsx @@ -12,11 +12,10 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type {Policy, PolicyCategories, PolicyTagList, Transaction} from '@src/types/onyx'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; import StepScreenWrapper from './StepScreenWrapper'; import withFullTransactionOrNotFound from './withFullTransactionOrNotFound'; -import withWritableReportOrNotFound from './withWritableReportOrNotFound'; import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound'; +import withWritableReportOrNotFound from './withWritableReportOrNotFound'; type IOURequestStepTaxRatePageOnyxProps = { policy: OnyxEntry; @@ -24,9 +23,6 @@ type IOURequestStepTaxRatePageOnyxProps = { /** Collection of tag list on a policy */ policyTags: OnyxEntry; - - /** The draft transaction that holds data to be persisted on the current transaction */ - splitDraftTransaction: OnyxEntry; }; type IOURequestStepTaxRatePageProps = IOURequestStepTaxRatePageOnyxProps & @@ -44,53 +40,41 @@ function getTaxAmount(policy: OnyxEntry, transaction: OnyxEntry { Navigation.goBack(backTo); }; - const taxRateTitle = TransactionUtils.getTaxName(policy, currentTransaction); + const taxRateTitle = TransactionUtils.getTaxName(policy, transaction); const updateTaxRates = (taxes: TaxRatesOption) => { - if (!currentTransaction || !taxes.code || !taxRates) { + if (!transaction || !taxes.code || !taxRates) { Navigation.goBack(); return; } - const taxAmount = getTaxAmount(policy, currentTransaction, taxes.code, TransactionUtils.getAmount(currentTransaction, false, true)); - - if (isEditingSplitBill) { - IOU.setDraftSplitTransaction(currentTransaction.transactionID, { - taxAmount: CurrencyUtils.convertToBackendAmount(taxAmount ?? 0), - taxCode: taxes.code, - }); - navigateBack(); - return; - } + const taxAmount = getTaxAmount(policy, transaction, taxes?.code, TransactionUtils.getAmount(transaction, false, true)); if (isEditing) { const newTaxCode = taxes.code; - if (newTaxCode === TransactionUtils.getTaxCode(currentTransaction)) { + if (newTaxCode === TransactionUtils.getTaxCode(transaction)) { navigateBack(); return; } IOU.updateMoneyRequestTaxRate({ - transactionID: currentTransaction?.transactionID ?? '', + transactionID: transaction?.transactionID ?? '', optimisticReportActionID: report?.reportID ?? '', taxCode: newTaxCode, taxAmount: CurrencyUtils.convertToBackendAmount(taxAmount ?? 0), @@ -107,8 +91,8 @@ function IOURequestStepTaxRatePage({ return; } const amountInSmallestCurrencyUnits = CurrencyUtils.convertToBackendAmount(taxAmount); - IOU.setMoneyRequestTaxRate(currentTransaction?.transactionID, taxes?.code ?? ''); - IOU.setMoneyRequestTaxAmount(currentTransaction.transactionID, amountInSmallestCurrencyUnits, true); + IOU.setMoneyRequestTaxRate(transaction?.transactionID, taxes?.code ?? ''); + IOU.setMoneyRequestTaxAmount(transaction.transactionID, amountInSmallestCurrencyUnits, true); navigateBack(); }; @@ -123,7 +107,7 @@ function IOURequestStepTaxRatePage({ @@ -134,12 +118,6 @@ function IOURequestStepTaxRatePage({ IOURequestStepTaxRatePage.displayName = 'IOURequestStepTaxRatePage'; const IOURequestStepTaxRatePageWithOnyx = withOnyx({ - splitDraftTransaction: { - key: ({route}) => { - const transactionID = route.params.transactionID ?? 0; - return `${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`; - }, - }, policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, diff --git a/src/types/onyx/IOU.ts b/src/types/onyx/IOU.ts index 68e8836e149c..8b0ca935f4b3 100644 --- a/src/types/onyx/IOU.ts +++ b/src/types/onyx/IOU.ts @@ -25,7 +25,6 @@ type Participant = { isSelfDM?: boolean; isSender?: boolean; iouType?: string; - ownerAccountID?: number; }; type Split = { @@ -42,7 +41,6 @@ type Split = { reportPreviewReportActionID?: string; transactionThreadReportID?: string; createdReportActionIDForThread?: string; - taxAmount?: number; }; type IOU = {