Skip to content

Don't scroll to bottom when create money request in expense report with table reprot view permission #61461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -787,6 +788,12 @@ Onyx.connect({
callback: (value) => (personalDetailsList = value),
});

let betas: OnyxEntry<OnyxTypes.Beta[]>;
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.
Expand Down Expand Up @@ -5155,7 +5162,7 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation) {
Navigation.removeScreenByKey(trackReport.key);
}

if (activeReportID) {
if (activeReportID && (!isMoneyRequestReport || !Permissions.canUseTableReportView(betas))) {
notifyNewAction(activeReportID, payeeAccountID);
}
}
Expand Down Expand Up @@ -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 = {
Expand Down
122 changes: 122 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
cancelPayment,
canIOUBePaid,
canUnapproveIOU,
createDistanceRequest,
deleteMoneyRequest,
initMoneyRequest,
payMoneyRequest,
Expand Down Expand Up @@ -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 () => {
/*
Expand Down Expand Up @@ -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', () => {
Expand Down