Skip to content
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
18 changes: 16 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,21 @@ function getForReportAction({
movedFromReport,
movedToReport,
policyForMovingExpensesID,
currentUserLogin: currentUserLoginParam,
}: {
reportAction: OnyxEntry<ReportAction>;
policyID: string | undefined;
movedFromReport?: OnyxEntry<Report>;
movedToReport?: OnyxEntry<Report>;
policyForMovingExpensesID?: string;
currentUserLogin?: string;
}): string {
// Temporary fallback to storedCurrentUserLogin since currentUserLogin can be empty string.
// Remove once all callers pass currentUserLogin explicitly and the migration to getForReportActionTemp is complete.
let currentUserLogin = currentUserLoginParam;
if (!currentUserLogin) {
currentUserLogin = storedCurrentUserLogin;
}
if (!isModifiedExpenseAction(reportAction)) {
return '';
}
Expand Down Expand Up @@ -371,7 +379,7 @@ function getForReportAction({
} else if (reportActionOriginalMessage?.source === CONST.CATEGORY_SOURCE.MCC) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(policyID);
const isAdmin = isPolicyAdmin(policy, storedCurrentUserLogin);
const isAdmin = isPolicyAdmin(policy, currentUserLogin);

// For admins, create a hyperlink to the workspace rules page
if (isAdmin && policy?.id) {
Expand Down Expand Up @@ -557,7 +565,7 @@ function getForReportActionTemp({
movedFromReport,
movedToReport,
policyTags,
currentUserLogin,
currentUserLogin: currentUserLoginParam,
}: {
translate: LocalizedTranslate;
reportAction: OnyxEntry<ReportAction>;
Expand All @@ -567,6 +575,12 @@ function getForReportActionTemp({
policyTags: OnyxEntry<PolicyTagLists>;
currentUserLogin: string;
}): string {
// Temporary fallback to storedCurrentUserLogin since currentUserLogin can be empty string.
// Remove once all callers pass currentUserLogin explicitly and the migration to getForReportActionTemp is complete.
let currentUserLogin = currentUserLoginParam;
if (!currentUserLogin) {
currentUserLogin = storedCurrentUserLogin;
}
if (!isModifiedExpenseAction(reportAction)) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ export default {
push(title, body, icon, data, onClick);
},

pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon = false}: LocalNotificationModifiedExpensePushParams) {
pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon = false, currentUserLogin}: LocalNotificationModifiedExpensePushParams) {
const title = reportAction.person?.map((f) => f.text).join(', ') ?? '';
const body = getForReportAction({
reportAction,
policyID: report.policyID,
movedFromReport,
movedToReport,
currentUserLogin,
});
const icon = usesIcon ? EXPENSIFY_ICON_URL : '';
const data = {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Notification/LocalNotification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function showUpdateAvailableNotification() {
BrowserNotifications.pushUpdateAvailableNotification();
}

function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick}: LocalNotificationModifiedExpenseParams) {
BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true});
function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, currentUserLogin, onClick}: LocalNotificationModifiedExpenseParams) {
BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true, currentUserLogin});
}

function clearReportNotifications(reportID: string | undefined) {
Expand Down
1 change: 1 addition & 0 deletions src/libs/Notification/LocalNotification/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type LocalNotificationModifiedExpenseParams = {
onClick: LocalNotificationClickHandler;
movedFromReport?: OnyxEntry<Report>;
movedToReport?: OnyxEntry<Report>;
currentUserLogin: string;
};

type LocalNotificationModifiedExpensePushParams = LocalNotificationModifiedExpenseParams & {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
/** @deprecated This value is deprecated and will be removed soon after migration. Use the email from useCurrentUserPersonalDetails hook instead. */
let deprecatedCurrentUserLogin: string | undefined;

Onyx.connect({

Check warning on line 317 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -328,7 +328,7 @@
},
});

Onyx.connect({

Check warning on line 331 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => (conciergeReportIDOnyxConnect = value),
});
Expand All @@ -336,7 +336,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 339 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -348,7 +348,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 351 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -357,7 +357,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 360 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -372,7 +372,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 375 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -383,7 +383,7 @@
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({

Check warning on line 386 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (val) => (deprecatedIntroSelected = val),
});
Expand Down Expand Up @@ -3614,7 +3614,7 @@
return true;
}

function showReportActionNotification(reportID: string, reportAction: ReportAction, currentUserAccountID: number) {
function showReportActionNotification(reportID: string, reportAction: ReportAction, currentUserAccountID: number, currentUserLogin: string) {
if (!shouldShowReportActionNotification(reportID, currentUserAccountID, reportAction)) {
return;
}
Expand All @@ -3633,7 +3633,7 @@
if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) {
const movedFromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(reportAction, CONST.REPORT.MOVE_TYPE.FROM)}`];
const movedToReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(reportAction, CONST.REPORT.MOVE_TYPE.TO)}`];
LocalNotification.showModifiedExpenseNotification({report, reportAction, onClick, movedFromReport, movedToReport});
LocalNotification.showModifiedExpenseNotification({report, reportAction, onClick, movedFromReport, movedToReport, currentUserLogin});
} else {
LocalNotification.showCommentNotification(report, reportAction, onClick);
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

let currentUserAccountID = -1;
let currentEmail = '';
Onyx.connect({

Check warning on line 68 in src/libs/actions/User.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
Expand All @@ -74,7 +74,7 @@
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 77 in src/libs/actions/User.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -696,7 +696,8 @@

for (const action of reportActions) {
if (action) {
showReportActionNotification(reportID, action, currentUserAccountIDParam);
// They aren't connected to a UI anywhere, it's OK to use currentEmail
showReportActionNotification(reportID, action, currentUserAccountIDParam, currentEmail);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ describe('actions/Report', () => {

it('should show a notification for report action updates with shouldNotify', () => {
const TEST_USER_ACCOUNT_ID = 1;
const TEST_USER_LOGIN = 'test@user.com';
const REPORT_ID = '1';
const REPORT_ACTION = {
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
Expand Down Expand Up @@ -763,7 +764,7 @@ describe('actions/Report', () => {
})
.then(() => {
// Ensure we show a notification for this new report action
expect(Report.showReportActionNotification).toBeCalledWith(REPORT_ID, REPORT_ACTION, TEST_USER_ACCOUNT_ID);
expect(Report.showReportActionNotification).toBeCalledWith(REPORT_ID, REPORT_ACTION, TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN);
});
});

Expand Down
Loading