From 8f1f8c64f50242d7ca9e72e13ebd5a205947edb7 Mon Sep 17 00:00:00 2001 From: Carlos Alvarez Date: Thu, 12 Dec 2024 16:50:39 -0700 Subject: [PATCH] Merge pull request #54076 from Expensify/revert-paultsimura/fix/46897-distance-accountant (cherry picked from commit f48bc89d4c77d36b35fddb857d102b29b60123a1) (CP triggered by luacmartins) --- .../MoneyRequestConfirmationList.tsx | 53 ++---------------- .../MoneyRequestConfirmationListFooter.tsx | 2 - src/languages/en.ts | 3 - src/languages/es.ts | 3 - src/languages/params.ts | 5 +- .../CategorizeTrackedExpenseParams.ts | 6 -- .../parameters/ShareTrackedExpenseParams.ts | 6 -- src/libs/ModifiedExpenseMessage.ts | 22 -------- src/libs/ReportUtils.ts | 29 ++++------ src/libs/actions/IOU.ts | 56 +++---------------- .../step/IOURequestStepConfirmation.tsx | 13 ----- .../step/IOURequestStepParticipants.tsx | 17 ++---- 12 files changed, 32 insertions(+), 183 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index 8ec8626af35b..19af05a1581b 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -211,8 +211,9 @@ function MoneyRequestConfirmationList({ } const defaultRate = defaultMileageRate?.customUnitRateID ?? ''; - const lastSelectedRateID = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultRate; - IOU.setCustomUnitRateID(transactionID, lastSelectedRateID); + const lastSelectedRate = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultRate; + const rateID = lastSelectedRate; + IOU.setCustomUnitRateID(transactionID, rateID); }, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, transactionID, isDistanceRequest]); const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft}); @@ -277,18 +278,6 @@ function MoneyRequestConfirmationList({ const [didConfirm, setDidConfirm] = useState(isConfirmed); const [didConfirmSplit, setDidConfirmSplit] = useState(false); - // Clear the form error if it's set to one among the list passed as an argument - const clearFormErrors = useCallback( - (errors: string[]) => { - if (!errors.includes(formError)) { - return; - } - - setFormError(''); - }, - [formError, setFormError], - ); - const shouldDisplayFieldError: boolean = useMemo(() => { if (!isEditingSplitBill) { return false; @@ -330,33 +319,6 @@ function MoneyRequestConfirmationList({ }, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]); const routeError = Object.values(transaction?.errorFields?.route ?? {}).at(0); - - useEffect(() => { - // We want this effect to run only when the transaction is moving from Self DM to a workspace chat - if (!isDistanceRequest || !isMovingTransactionFromTrackExpense || !isPolicyExpenseChat) { - return; - } - - const errorKey = 'iou.error.invalidRate'; - const policyRates = DistanceRequestUtils.getMileageRates(policy); - - // If the selected rate belongs to the policy, clear the error - if (Object.keys(policyRates).includes(customUnitRateID)) { - clearFormErrors([errorKey]); - return; - } - - // If there is a distance rate in the policy that matches the rate and unit of the currently selected mileage rate, select it automatically - const matchingRate = Object.values(policyRates).find((policyRate) => policyRate.rate === mileageRate.rate && policyRate.unit === mileageRate.unit); - if (matchingRate?.customUnitRateID) { - IOU.setCustomUnitRateID(transactionID, matchingRate.customUnitRateID); - return; - } - - // If none of the above conditions are met, display the rate error - setFormError(errorKey); - }, [isDistanceRequest, isPolicyExpenseChat, transactionID, mileageRate, customUnitRateID, policy, isMovingTransactionFromTrackExpense, setFormError, clearFormErrors]); - const isFirstUpdatedDistanceAmount = useRef(false); useEffect(() => { @@ -507,8 +469,8 @@ function MoneyRequestConfirmationList({ return; } - clearFormErrors(['iou.error.invalidSplit', 'iou.error.invalidSplitParticipants', 'iou.error.invalidSplitYourself']); - }, [isFocused, transaction, isTypeSplit, transaction?.splitShares, currentUserPersonalDetails.accountID, iouAmount, iouCurrencyCode, setFormError, translate, clearFormErrors]); + setFormError(''); + }, [isFocused, transaction, isTypeSplit, transaction?.splitShares, currentUserPersonalDetails.accountID, iouAmount, iouCurrencyCode, setFormError, translate]); useEffect(() => { if (!isTypeSplit || !transaction?.splitShares) { @@ -675,9 +637,7 @@ function MoneyRequestConfirmationList({ }, [isTypeSplit, translate, payeePersonalDetails, getSplitSectionHeader, splitParticipants, selectedParticipants]); useEffect(() => { - if (!isDistanceRequest || (isMovingTransactionFromTrackExpense && !isPolicyExpenseChat)) { - // We don't want to recalculate the distance merchant when moving a transaction from Track Expense to a 1:1 chat, because the distance rate will be the same default P2P rate. - // When moving to a policy chat (e.g. sharing with an accountant), we should recalculate the distance merchant with the policy's rate. + if (!isDistanceRequest || isMovingTransactionFromTrackExpense) { return; } @@ -700,7 +660,6 @@ function MoneyRequestConfirmationList({ translate, toLocaleDigit, isDistanceRequest, - isPolicyExpenseChat, transaction, transactionID, action, diff --git a/src/components/MoneyRequestConfirmationListFooter.tsx b/src/components/MoneyRequestConfirmationListFooter.tsx index c391564a6d3d..340be8a6c3e1 100644 --- a/src/components/MoneyRequestConfirmationListFooter.tsx +++ b/src/components/MoneyRequestConfirmationListFooter.tsx @@ -259,7 +259,6 @@ function MoneyRequestConfirmationListFooter({ const taxRateTitle = TransactionUtils.getTaxName(policy, transaction); // Determine if the merchant error should be displayed const shouldDisplayMerchantError = isMerchantRequired && (shouldDisplayFieldError || formError === 'iou.error.invalidMerchant') && isMerchantEmpty; - const shouldDisplayDistanceRateError = formError === 'iou.error.invalidRate'; // The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate") const shouldShowReceiptEmptyState = iouType === CONST.IOU.TYPE.SUBMIT && PolicyUtils.isPaidGroupPolicy(policy); const { @@ -370,7 +369,6 @@ function MoneyRequestConfirmationListFooter({ style={[styles.moneyRequestMenuItem]} titleStyle={styles.flex1} onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE_RATE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))} - brickRoadIndicator={shouldDisplayDistanceRateError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} disabled={didConfirm} interactive={!!rate && !isReadOnly && isPolicyExpenseChat} /> diff --git a/src/languages/en.ts b/src/languages/en.ts index d565893f2fa0..b2bc2b845639 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -98,7 +98,6 @@ import type { MarkedReimbursedParams, MarkReimbursedFromIntegrationParams, MissingPropertyParams, - MovedFromSelfDMParams, NoLongerHaveAccessParams, NotAllowedExtensionParams, NotYouParams, @@ -980,7 +979,6 @@ const translations = { threadExpenseReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${formattedAmount} ${comment ? `for ${comment}` : 'expense'}`, threadTrackReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Tracking ${formattedAmount} ${comment ? `for ${comment}` : ''}`, threadPaySomeoneReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`, - movedFromSelfDM: ({workspaceName, reportName}: MovedFromSelfDMParams) => `moved expense from self DM to ${workspaceName ?? `chat with ${reportName}`}`, tagSelection: 'Select a tag to better organize your spend.', categorySelection: 'Select a category to better organize your spend.', error: { @@ -1010,7 +1008,6 @@ const translations = { splitExpenseMultipleParticipantsErrorMessage: 'An expense cannot be split between a workspace and other members. Please update your selection.', invalidMerchant: 'Please enter a correct merchant.', atLeastOneAttendee: 'At least one attendee must be selected', - invalidRate: 'Rate not valid for this workspace. Please select an available rate from the workspace.', }, waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} enables their wallet.`, enableWallet: 'Enable wallet', diff --git a/src/languages/es.ts b/src/languages/es.ts index 0b59f8a9044c..d2c1d57d3ec2 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -97,7 +97,6 @@ import type { MarkedReimbursedParams, MarkReimbursedFromIntegrationParams, MissingPropertyParams, - MovedFromSelfDMParams, NoLongerHaveAccessParams, NotAllowedExtensionParams, NotYouParams, @@ -978,7 +977,6 @@ const translations = { threadExpenseReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${comment ? `${formattedAmount} para ${comment}` : `Gasto de ${formattedAmount}`}`, threadTrackReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Seguimiento ${formattedAmount} ${comment ? `para ${comment}` : ''}`, threadPaySomeoneReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`, - movedFromSelfDM: ({workspaceName, reportName}: MovedFromSelfDMParams) => `movió el gasto desde su propio mensaje directo a ${workspaceName ?? `un chat con ${reportName}`}`, tagSelection: 'Selecciona una etiqueta para organizar mejor tus gastos.', categorySelection: 'Selecciona una categoría para organizar mejor tus gastos.', error: { @@ -1008,7 +1006,6 @@ const translations = { splitExpenseMultipleParticipantsErrorMessage: 'Solo puedes dividir un gasto entre un único espacio de trabajo o con miembros individuales. Por favor, actualiza tu selección.', invalidMerchant: 'Por favor, introduce un comerciante correcto.', atLeastOneAttendee: 'Debe seleccionarse al menos un asistente', - invalidRate: 'Tasa no válida para este espacio de trabajo. Por favor, selecciona una tasa disponible en el espacio de trabajo.', }, waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su billetera`, enableWallet: 'Habilitar billetera', diff --git a/src/languages/params.ts b/src/languages/params.ts index 9ac9cd585f4a..3088b99e753b 100644 --- a/src/languages/params.ts +++ b/src/languages/params.ts @@ -165,8 +165,6 @@ type ThreadRequestReportNameParams = {formattedAmount: string; comment: string}; type ThreadSentMoneyReportNameParams = {formattedAmount: string; comment: string}; -type MovedFromSelfDMParams = {workspaceName?: string; reportName?: string}; - type SizeExceededParams = {maxUploadSizeInMB: number}; type ResolutionConstraintsParams = {minHeightInPx: number; minWidthInPx: number; maxHeightInPx: number; maxWidthInPx: number}; @@ -669,7 +667,7 @@ export type { LoggedInAsParams, ManagerApprovedAmountParams, ManagerApprovedParams, - MovedFromSelfDMParams, + SignUpNewFaceCodeParams, NoLongerHaveAccessParams, NotAllowedExtensionParams, NotYouParams, @@ -703,7 +701,6 @@ export type { SetTheRequestParams, SettleExpensifyCardParams, SettledAfterAddedBankAccountParams, - SignUpNewFaceCodeParams, SizeExceededParams, SplitAmountParams, StepCounterParams, diff --git a/src/libs/API/parameters/CategorizeTrackedExpenseParams.ts b/src/libs/API/parameters/CategorizeTrackedExpenseParams.ts index 7b322189838a..78eb0adecc5e 100644 --- a/src/libs/API/parameters/CategorizeTrackedExpenseParams.ts +++ b/src/libs/API/parameters/CategorizeTrackedExpenseParams.ts @@ -20,12 +20,6 @@ type CategorizeTrackedExpenseParams = { taxCode: string; taxAmount: number; billable?: boolean; - waypoints?: string; - customUnitRateID?: string; - policyExpenseChatReportID?: string; - policyExpenseCreatedReportActionID?: string; - adminsChatReportID?: string; - adminsCreatedReportActionID?: string; }; export default CategorizeTrackedExpenseParams; diff --git a/src/libs/API/parameters/ShareTrackedExpenseParams.ts b/src/libs/API/parameters/ShareTrackedExpenseParams.ts index d44a7af5a444..cee4bc40d9ac 100644 --- a/src/libs/API/parameters/ShareTrackedExpenseParams.ts +++ b/src/libs/API/parameters/ShareTrackedExpenseParams.ts @@ -20,12 +20,6 @@ type ShareTrackedExpenseParams = { taxCode: string; taxAmount: number; billable?: boolean; - waypoints?: string; - customUnitRateID?: string; - policyExpenseChatReportID?: string; - policyExpenseCreatedReportActionID?: string; - adminsChatReportID?: string; - adminsCreatedReportActionID?: string; }; export default ShareTrackedExpenseParams; diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 24998db0e5cd..c3c12600f882 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -1,4 +1,3 @@ -import isEmpty from 'lodash/isEmpty'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; @@ -10,8 +9,6 @@ import * as Localize from './Localize'; import Log from './Log'; import * as PolicyUtils from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; -// eslint-disable-next-line import/no-cycle -import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getRootParentReport, isPolicyExpenseChat} from './ReportUtils'; import * as TransactionUtils from './TransactionUtils'; let allPolicyTags: OnyxCollection = {}; @@ -135,20 +132,6 @@ function getForDistanceRequest(newMerchant: string, oldMerchant: string, newAmou }); } -function getForExpenseMovedFromSelfDM(destinationReportID: string) { - const destinationReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${destinationReportID}`]; - const rootParentReport = getRootParentReport(destinationReport); - - // The "Move report" flow only supports moving expenses to a policy expense chat or a 1:1 DM. - const reportName = isPolicyExpenseChat(rootParentReport) ? getPolicyExpenseChatName(rootParentReport) : buildReportNameFromParticipantNames({report: rootParentReport}); - const policyName = getPolicyName(rootParentReport, true); - - return Localize.translateLocal('iou.movedFromSelfDM', { - reportName, - workspaceName: !isEmpty(policyName) ? policyName : undefined, - }); -} - /** * Get the report action message when expense has been modified. * @@ -159,14 +142,9 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) { return ''; } - const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction); const policyID = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1'; - if (reportActionOriginalMessage?.movedToReportID) { - return getForExpenseMovedFromSelfDM(reportActionOriginalMessage.movedToReportID); - } - const removalFragments: string[] = []; const setFragments: string[] = []; const changeFragments: string[] = []; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a30de7b97198..1a829f17e283 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -73,7 +73,6 @@ import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import Log from './Log'; import {isEmailPublicDomain} from './LoginUtils'; -// eslint-disable-next-line import/no-cycle import ModifiedExpenseMessage from './ModifiedExpenseMessage'; import linkingConfig from './Navigation/linkingConfig'; import Navigation from './Navigation/Navigation'; @@ -3916,21 +3915,6 @@ const reportNameCache = new Map): string => `${report?.reportID}-${report?.lastVisibleActionCreated}-${report?.reportName}`; -/** - * Get the title for a report using only participant names. This may be used for 1:1 DMs and other non-categorized chats. - */ -function buildReportNameFromParticipantNames({report, personalDetails}: {report: OnyxEntry; personalDetails?: Partial}) { - const participantsWithoutCurrentUser: number[] = []; - Object.keys(report?.participants ?? {}).forEach((accountID) => { - const accID = Number(accountID); - if (accID !== currentUserAccountID && participantsWithoutCurrentUser.length < 5) { - participantsWithoutCurrentUser.push(accID); - } - }); - const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1; - return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', '); -} - /** * Get the title for a report. */ @@ -4094,7 +4078,16 @@ function getReportName( } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetails}); + const participantsWithoutCurrentUser: number[] = []; + Object.keys(report?.participants ?? {}).forEach((accountID) => { + const accID = Number(accountID); + if (accID !== currentUserAccountID && participantsWithoutCurrentUser.length < 5) { + participantsWithoutCurrentUser.push(accID); + } + }); + const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1; + const participantNames = participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', '); + formattedName = participantNames; if (reportID) { reportNameCache.set(cacheKey, {lastVisibleActionCreated: report?.lastVisibleActionCreated ?? '', reportName: formattedName}); @@ -8530,7 +8523,6 @@ export { buildOptimisticWorkspaceChats, buildOptimisticCardAssignedReportAction, buildParticipantsFromAccountIDs, - buildReportNameFromParticipantNames, buildTransactionThread, canAccessReport, isReportNotFound, @@ -8618,7 +8610,6 @@ export { getPersonalDetailsForAccountID, getPolicyDescriptionText, getPolicyExpenseChat, - getPolicyExpenseChatName, getPolicyName, getPolicyType, getReimbursementDeQueuedActionMessage, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 6b45283421ea..8b33a5283b2a 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -8,7 +8,6 @@ import ReceiptGeneric from '@assets/images/receipt-generic.png'; import * as API from '@libs/API'; import type { ApproveMoneyRequestParams, - CategorizeTrackedExpenseParams as CategorizeTrackedExpenseApiParams, CompleteSplitBillParams, CreateDistanceRequestParams, CreateWorkspaceParams, @@ -22,7 +21,6 @@ import type { SendInvoiceParams, SendMoneyParams, SetNameValuePairParams, - ShareTrackedExpenseParams as ShareTrackedExpenseApiParams, SplitBillParams, StartSplitBillParams, SubmitReportParams, @@ -127,8 +125,6 @@ type CategorizeTrackedExpenseTransactionParams = { tag?: string; billable?: boolean; receipt?: Receipt; - waypoints?: string; - customUnitRateID?: string; }; type CategorizeTrackedExpensePolicyParams = { policyID: string; @@ -591,31 +587,7 @@ function setMoneyRequestReceipt(transactionID: string, source: string, filename: * Set custom unit rateID for the transaction draft */ function setCustomUnitRateID(transactionID: string, customUnitRateID: string) { - const isFakeP2PRate = customUnitRateID === CONST.CUSTOM_UNITS.FAKE_P2P_ID; - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, { - comment: { - customUnit: { - customUnitRateID, - ...(!isFakeP2PRate && {defaultP2PRate: null}), - }, - }, - }); -} - -/** - * Revert custom unit of the draft transaction to the original transaction's value - */ -function resetDraftTransactionsCustomUnit(transactionID: string) { - const originalTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; - if (!originalTransaction) { - return; - } - - Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, { - comment: { - customUnit: originalTransaction.comment?.customUnit ?? {}, - }, - }); + Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {comment: {customUnit: {customUnitRateID}}}); } /** Set the distance rate of a new transaction */ @@ -3614,8 +3586,8 @@ function categorizeTrackedExpense(trackedExpenseParams: CategorizeTrackedExpense optimisticData?.push(...moveTransactionOptimisticData); successData?.push(...moveTransactionSuccessData); failureData?.push(...moveTransactionFailureData); - - const parameters: CategorizeTrackedExpenseApiParams = { + const parameters = { + onyxData, ...reportInformation, ...policyParams, ...transactionParams, @@ -3658,8 +3630,6 @@ function shareTrackedExpense( taxAmount = 0, billable?: boolean, receipt?: Receipt, - waypoints?: string, - customUnitRateID?: string, createdWorkspaceParams?: CreateWorkspaceParams, ) { const {optimisticData, successData, failureData} = onyxData ?? {}; @@ -3683,7 +3653,7 @@ function shareTrackedExpense( successData?.push(...moveTransactionSuccessData); failureData?.push(...moveTransactionFailureData); - const parameters: ShareTrackedExpenseApiParams = { + const parameters = { policyID, transactionID, moneyRequestPreviewReportActionID, @@ -3703,8 +3673,6 @@ function shareTrackedExpense( taxAmount, billable, receipt, - waypoints, - customUnitRateID, policyExpenseChatReportID: createdWorkspaceParams?.expenseChatReportID, policyExpenseCreatedReportActionID: createdWorkspaceParams?.expenseCreatedReportActionID, adminsChatReportID: createdWorkspaceParams?.adminsChatReportID, @@ -3942,7 +3910,6 @@ function trackExpense( // Pass an open receipt so the distance expense will show a map with the route optimistically const trackedReceipt = validWaypoints ? {source: ReceiptGeneric as ReceiptSource, state: CONST.IOU.RECEIPT_STATE.OPEN} : receipt; - const sanitizedWaypoints = validWaypoints ? JSON.stringify(sanitizeRecentWaypoints(validWaypoints)) : undefined; const { createdWorkspaceParams, @@ -3997,7 +3964,7 @@ function trackExpense( if (!linkedTrackedExpenseReportAction || !actionableWhisperReportActionID || !linkedTrackedExpenseReportID) { return; } - const transactionParams: CategorizeTrackedExpenseTransactionParams = { + const transactionParams = { transactionID: transaction?.transactionID ?? '-1', amount, currency, @@ -4010,14 +3977,12 @@ function trackExpense( tag, billable, receipt: trackedReceipt, - waypoints: sanitizedWaypoints, - customUnitRateID, }; - const policyParams: CategorizeTrackedExpensePolicyParams = { + const policyParams = { policyID: chatReport?.policyID ?? '-1', isDraftPolicy, }; - const reportInformation: CategorizeTrackedExpenseReportInformation = { + const reportInformation = { moneyRequestPreviewReportActionID: iouAction?.reportActionID ?? '-1', moneyRequestReportID: iouReport?.reportID ?? '-1', moneyRequestCreatedReportActionID: createdIOUReportActionID ?? '-1', @@ -4027,7 +3992,7 @@ function trackExpense( transactionThreadReportID: transactionThreadReportID ?? '-1', reportPreviewReportActionID: reportPreviewAction?.reportActionID ?? '-1', }; - const trackedExpenseParams: CategorizeTrackedExpenseParams = { + const trackedExpenseParams = { onyxData, reportInformation, transactionParams, @@ -4065,8 +4030,6 @@ function trackExpense( taxAmount, billable, trackedReceipt, - sanitizedWaypoints, - customUnitRateID, createdWorkspaceParams, ); break; @@ -4096,7 +4059,7 @@ function trackExpense( receiptGpsPoints: gpsPoints ? JSON.stringify(gpsPoints) : undefined, transactionThreadReportID: transactionThreadReportID ?? '-1', createdReportActionIDForThread: createdReportActionIDForThread ?? '-1', - waypoints: sanitizedWaypoints, + waypoints: validWaypoints ? JSON.stringify(sanitizeRecentWaypoints(validWaypoints)) : undefined, customUnitRateID, }; if (actionableWhisperReportActionIDParam) { @@ -8792,7 +8755,6 @@ export { replaceReceipt, requestMoney, resetSplitShares, - resetDraftTransactionsCustomUnit, savePreferredPaymentMethod, sendInvoice, sendMoneyElsewhere, diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index 39634eb061b9..989277bb5fc1 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -135,19 +135,6 @@ function IOURequestStepConfirmation({ useFetchRoute(transaction, transaction?.comment?.waypoints, action, IOUUtils.shouldUseTransactionDraft(action) ? CONST.TRANSACTION.STATE.DRAFT : CONST.TRANSACTION.STATE.CURRENT); - useEffect( - // This effect runs on the component unmount. It resets the custom unit rate ID of the transaction if it's moving from Track Expense. - // This is needed to revert the rate back to the original FAKE_P2P_RATE_ID when changing the destination workspace. - () => () => { - if (!isMovingTransactionFromTrackExpense) { - return; - } - - IOU.resetDraftTransactionsCustomUnit(transactionID); - }, - [isMovingTransactionFromTrackExpense, transactionID], - ); - useEffect(() => { const policyExpenseChat = participants?.find((participant) => participant.isPolicyExpenseChat); if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { diff --git a/src/pages/iou/request/step/IOURequestStepParticipants.tsx b/src/pages/iou/request/step/IOURequestStepParticipants.tsx index df0504a25c01..fb2484ea414f 100644 --- a/src/pages/iou/request/step/IOURequestStepParticipants.tsx +++ b/src/pages/iou/request/step/IOURequestStepParticipants.tsx @@ -44,7 +44,6 @@ function IOURequestStepParticipants({ const numberOfParticipants = useRef(participants?.length ?? 0); const iouRequestType = TransactionUtils.getRequestType(transaction); const isSplitRequest = iouType === CONST.IOU.TYPE.SPLIT; - const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action); const headerTitle = useMemo(() => { if (action === CONST.IOU.ACTION.CATEGORIZE) { return translate('iou.categorize'); @@ -76,27 +75,23 @@ function IOURequestStepParticipants({ // the image ceases to exist. The best way for the user to recover from this is to start over from the start of the expense process. // skip this in case user is moving the transaction as the receipt path will be valid in that case useEffect(() => { - if (isMovingTransactionFromTrackExpense) { + if (IOUUtils.isMovingTransactionFromTrackExpense(action)) { return; } IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename ?? '', receiptPath ?? '', () => {}, iouRequestType, iouType, transactionID, reportID, receiptType ?? ''); - }, [receiptType, receiptPath, receiptFilename, iouRequestType, iouType, transactionID, reportID, isMovingTransactionFromTrackExpense]); + }, [receiptType, receiptPath, receiptFilename, iouRequestType, iouType, transactionID, reportID, action]); const addParticipant = useCallback( (val: Participant[]) => { HttpUtils.cancelPendingRequests(READ_COMMANDS.SEARCH_FOR_REPORTS); const firstParticipantReportID = val.at(0)?.reportID ?? ''; + const rateID = DistanceRequestUtils.getCustomUnitRateID(firstParticipantReportID); const isInvoice = iouType === CONST.IOU.TYPE.INVOICE && ReportUtils.isInvoiceRoomWithID(firstParticipantReportID); numberOfParticipants.current = val.length; - IOU.setMoneyRequestParticipants(transactionID, val); - if (!isMovingTransactionFromTrackExpense) { - // When moving the transaction, keep the original rate and let the user manually change it to the one they want from the workspace. - // Otherwise, select the default one automatically. - const rateID = DistanceRequestUtils.getCustomUnitRateID(firstParticipantReportID); - IOU.setCustomUnitRateID(transactionID, rateID); - } + IOU.setMoneyRequestParticipants(transactionID, val); + IOU.setCustomUnitRateID(transactionID, rateID); // When multiple participants are selected, the reportID is generated at the end of the confirmation step. // So we are resetting selectedReportID ref to the reportID coming from params. @@ -108,7 +103,7 @@ function IOURequestStepParticipants({ // When a participant is selected, the reportID needs to be saved because that's the reportID that will be used in the confirmation step. selectedReportID.current = firstParticipantReportID || reportID; }, - [iouType, reportID, transactionID, isMovingTransactionFromTrackExpense], + [iouType, reportID, transactionID], ); const goToNextStep = useCallback(() => {