Skip to content

Commit

Permalink
Merge pull request #29681 from rezkiy37/feature/29593-optimistic-mone…
Browse files Browse the repository at this point in the history
…y-requests-hidden

Make optimistic requests/IOUs/expense reports “hidden”
  • Loading branch information
puneetlath authored Nov 7, 2023
2 parents 5654bfc + f06d7b2 commit 9b53463
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,16 @@ function getReport(reportID) {
return lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}) || {};
}

/**
* Get the notification preference given a report
*
* @param {Object} report
* @returns {String}
*/
function getReportNotificationPreference(report) {
return lodashGet(report, 'notificationPreference', '');
}

/**
* Returns whether or not the author of the action is this user
*
Expand Down Expand Up @@ -2420,7 +2430,7 @@ function buildOptimisticIOUReport(payeeAccountID, payerAccountID, total, chatRep

// We don't translate reportName because the server response is always in English
reportName: `${payerEmail} owes ${formattedTotal}`,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReportID: chatReportID,
};
}
Expand Down Expand Up @@ -2459,7 +2469,7 @@ function buildOptimisticExpenseReport(chatReportID, policyID, payeeAccountID, to
state: CONST.REPORT.STATE.SUBMITTED,
stateNum: CONST.REPORT.STATE_NUM.PROCESSING,
total: storedTotal,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
parentReportID: chatReportID,
};
}
Expand Down Expand Up @@ -3156,7 +3166,7 @@ function buildTransactionThread(reportAction, moneyRequestReportID) {
'',
undefined,
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
reportAction.reportActionID,
moneyRequestReportID,
);
Expand Down Expand Up @@ -4217,6 +4227,7 @@ export {
getDisplayNamesStringFromTooltips,
getReportName,
getReport,
getReportNotificationPreference,
getReportIDFromLink,
getRouteFromLink,
getDeletedParentActionMessageForChatReport,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ function addActions(reportID, text = '', file) {
lastReadTime: currentTime,
};

if (ReportUtils.getReportNotificationPreference(ReportUtils.getReport(reportID)) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS;
}

// Optimistically add the new actions to the store before waiting to save them to the server
const optimisticReportActions = {};
if (text) {
Expand Down
17 changes: 17 additions & 0 deletions tests/actions/IOUTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ describe('actions/IOU', () => {
const iouReport = iouReports[0];
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]);
expect(chatReport.iouReportID).toBe(iouReport.reportID);
Expand Down Expand Up @@ -243,6 +245,8 @@ describe('actions/IOU', () => {
const iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU);
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.iouReportID).toBe(iouReportID);
expect(chatReport.hasOutstandingIOU).toBe(true);
Expand Down Expand Up @@ -572,6 +576,8 @@ describe('actions/IOU', () => {
const iouReport = iouReports[0];
iouReportID = iouReport.reportID;

expect(iouReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

// They should be linked together
expect(chatReport.participantAccountIDs).toEqual([CARLOS_ACCOUNT_ID]);
expect(chatReport.iouReportID).toBe(iouReport.reportID);
Expand Down Expand Up @@ -982,6 +988,7 @@ describe('actions/IOU', () => {
expect(carlosChatReport.hasOutstandingIOU).toBe(true);
expect(carlosChatReport.iouReportID).toBe(carlosIOUReport.reportID);
expect(carlosIOUReport.chatReportID).toBe(carlosChatReport.reportID);
expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

expect(julesChatReport.hasOutstandingIOU).toBe(true);
expect(julesChatReport.iouReportID).toBe(julesIOUReport.reportID);
Expand All @@ -990,6 +997,7 @@ describe('actions/IOU', () => {
expect(vitChatReport.hasOutstandingIOU).toBe(true);
expect(vitChatReport.iouReportID).toBe(vitIOUReport.reportID);
expect(vitIOUReport.chatReportID).toBe(vitChatReport.reportID);
expect(carlosIOUReport.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

resolve();
},
Expand Down Expand Up @@ -2171,6 +2179,8 @@ describe('actions/IOU', () => {
// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down Expand Up @@ -2248,6 +2258,9 @@ describe('actions/IOU', () => {

// Given a transaction thread
thread = ReportUtils.buildTransactionThread(createIOUAction);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

const userLogins = PersonalDetailsUtils.getLoginsByAccountIDs(thread.participantAccountIDs);
jest.advanceTimersByTime(10);
Report.openReport(thread.reportID, userLogins, thread, createIOUAction.reportActionID);
Expand Down Expand Up @@ -2332,6 +2345,8 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down Expand Up @@ -2545,6 +2560,8 @@ describe('actions/IOU', () => {
jest.advanceTimersByTime(10);
thread = ReportUtils.buildTransactionThread(createIOUAction, IOU_REPORT_ID);

expect(thread.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN);

Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`,
callback: (val) => (reportActions = val),
Expand Down

0 comments on commit 9b53463

Please sign in to comment.