diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 9c420e3ea97d..5d4f164bcfac 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -58,6 +58,7 @@ import {rand64} from '@libs/NumberUtils'; import {getManagerMcTestParticipant, getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils'; import {getCustomUnitID} from '@libs/PerDiemRequestUtils'; import Performance from '@libs/Performance'; +import Permissions from '@libs/Permissions'; import {getAccountIDsByLogins} from '@libs/PersonalDetailsUtils'; import {addSMSDomainIfPhoneNumber} from '@libs/PhoneNumber'; import { @@ -787,6 +788,12 @@ Onyx.connect({ callback: (value) => (personalDetailsList = value), }); +let betas: OnyxEntry; +Onyx.connect({ + key: ONYXKEYS.BETAS, + callback: (value) => (betas = value), +}); + /** * @private * After finishing the action in RHP from the Inbox tab, besides dismissing the modal, we should open the report. @@ -5155,7 +5162,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) { Navigation.removeScreenByKey(trackReport.key); } - if (activeReportID) { + if (activeReportID && (!isMoneyRequestReport || !Permissions.canUseTableReportView(betas))) { notifyNewAction(activeReportID, payeeAccountID); } } @@ -7033,7 +7040,10 @@ function createDistanceRequest(distanceRequestInformation: CreateDistanceRequest InteractionManager.runAfterInteractions(() => removeDraftTransaction(CONST.IOU.OPTIMISTIC_TRANSACTION_ID)); const activeReportID = isMoneyRequestReport && report?.reportID ? report.reportID : parameters.chatReportID; dismissModalAndOpenReportInInboxTab(activeReportID); - notifyNewAction(activeReportID, userAccountID); + + if (!isMoneyRequestReport || !Permissions.canUseTableReportView(betas)) { + notifyNewAction(activeReportID, userAccountID); + } } type UpdateMoneyRequestAmountAndCurrencyParams = { diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 55adfdf78c49..e88a46597d39 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -9,6 +9,7 @@ import { cancelPayment, canIOUBePaid, canUnapproveIOU, + createDistanceRequest, deleteMoneyRequest, initMoneyRequest, payMoneyRequest, @@ -141,6 +142,11 @@ describe('actions/IOU', () => { mockFetch = fetch as MockFetch; return Onyx.clear().then(waitForBatchedUpdates); }); + + afterEach(() => { + jest.clearAllMocks(); + }); + describe('trackExpense', () => { it('category a distance expense of selfDM report', async () => { /* @@ -1527,6 +1533,122 @@ describe('actions/IOU', () => { .then(mockFetch?.succeed) ); }); + it('does not trigger notifyNewAction when doing the money request in a money request report and has a canUseTableReportView permission', async () => { + await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.TABLE_REPORT_VIEW]); + requestMoney({ + report: {reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, + participantParams: { + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(0); + }); + + it('trigger notifyNewAction when doing the money request in a chat report', async () => { + await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.TABLE_REPORT_VIEW]); + requestMoney({ + report: {reportID: '123'}, + participantParams: { + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(1); + }); + + it('trigger notifyNewAction when doing the money request without canUseTableReportView permission', () => { + requestMoney({ + report: {reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, + participantParams: { + payeeEmail: RORY_EMAIL, + payeeAccountID: RORY_ACCOUNT_ID, + participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, + }, + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(1); + }); + }); + + describe('createDistanceRequest', () => { + it('does not trigger notifyNewAction when doing the money request in a money request report and has a canUseTableReportView permission', async () => { + await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.TABLE_REPORT_VIEW]); + createDistanceRequest({ + report: {reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, + participants: [], + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + validWaypoints: {}, + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(0); + }); + + it('trigger notifyNewAction when doing the money request in a chat report', async () => { + await Onyx.merge(ONYXKEYS.BETAS, [CONST.BETAS.TABLE_REPORT_VIEW]); + createDistanceRequest({ + report: {reportID: '123'}, + participants: [], + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + validWaypoints: {}, + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(1); + }); + + it('trigger notifyNewAction when doing the money request without canUseTableReportView permission', () => { + createDistanceRequest({ + report: {reportID: '123', type: CONST.REPORT.TYPE.EXPENSE}, + participants: [], + transactionParams: { + amount: 1, + attendees: [], + currency: CONST.CURRENCY.USD, + created: '', + merchant: '', + comment: '', + validWaypoints: {}, + }, + }); + expect(notifyNewAction).toHaveBeenCalledTimes(1); + }); }); describe('split expense', () => {