diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 6f4596b0e5973..4e373f614274b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -172,6 +172,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Attendee, Participant, Split} from '@src/types/onyx/IOU'; import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import type {QuickActionName} from '@src/types/onyx/QuickAction'; import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; @@ -1882,11 +1883,12 @@ function buildOnyxDataForTrackExpense( const successData: OnyxUpdate[] = []; const failureData: OnyxUpdate[] = []; - let newQuickAction: ValueOf = CONST.QUICK_ACTIONS.TRACK_MANUAL; + const isSelfDMReport = isSelfDM(chatReport); + let newQuickAction: QuickActionName = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; if (isScanRequest) { - newQuickAction = CONST.QUICK_ACTIONS.TRACK_SCAN; + newQuickAction = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_SCAN : CONST.QUICK_ACTIONS.REQUEST_SCAN; } else if (isDistanceRequest) { - newQuickAction = CONST.QUICK_ACTIONS.TRACK_DISTANCE; + newQuickAction = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_DISTANCE : CONST.QUICK_ACTIONS.REQUEST_DISTANCE; } const existingTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingTransactionThreadReportID}`] ?? null; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index b87ebf46f1f96..7f1ff92705ccf 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -174,7 +174,7 @@ describe('actions/IOU', () => { }; // Given a policyExpenseChat report - const expenseReport = { + const policyExpenseChat = { ...createRandomReport(1), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, }; @@ -290,7 +290,7 @@ describe('actions/IOU', () => { // When the user confirms the category for the tracked expense trackExpense({ - report: expenseReport, + report: policyExpenseChat, isDraftPolicy: false, action: CONST.IOU.ACTION.CATEGORIZE, participantParams: { @@ -337,6 +337,21 @@ describe('actions/IOU', () => { }, }); }); + + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + callback: (quickAction) => { + Onyx.disconnect(connection); + resolve(); + + // Then the quickAction.action should be set to REQUEST_DISTANCE + expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.REQUEST_DISTANCE); + // Then the quickAction.chatReportID should be set to the given policyExpenseChat reportID + expect(quickAction?.chatReportID).toBe(policyExpenseChat.reportID); + }, + }); + }); }); });