Skip to content

Commit 72f2971

Browse files
authored
Merge pull request Expensify#84029 from callstack-internal/extract-remove-onyx-connect-browsernotifications-chain
[No QA][Part 3f] Pass policyTags through BrowserNotifications modified-expense chain
2 parents 9b4d357 + b6446ae commit 72f2971

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

src/libs/Notification/LocalNotification/BrowserNotifications.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {Str} from 'expensify-common';
33
import type {ImageSourcePropType} from 'react-native';
44
import EXPENSIFY_ICON_URL from '@assets/images/expensify-logo-round-clearspace.png';
55
import * as AppUpdate from '@libs/actions/AppUpdate';
6-
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
6+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook
7+
import {translateLocal} from '@libs/Localize';
8+
import {getForReportActionTemp} from '@libs/ModifiedExpenseMessage';
79
import {getTextFromHtml} from '@libs/ReportActionsUtils';
810
import * as ReportUtils from '@libs/ReportUtils';
911
import playSound, {SOUNDS} from '@libs/Sound';
@@ -130,13 +132,26 @@ export default {
130132
push(title, body, icon, data, onClick);
131133
},
132134

133-
pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon = false, currentUserLogin}: LocalNotificationModifiedExpensePushParams) {
135+
pushModifiedExpenseNotification({
136+
report,
137+
reportAction,
138+
movedFromReport,
139+
movedToReport,
140+
onClick,
141+
usesIcon = false,
142+
policyTags,
143+
policy,
144+
currentUserLogin,
145+
}: LocalNotificationModifiedExpensePushParams) {
134146
const title = reportAction.person?.map((f) => f.text).join(', ') ?? '';
135-
const body = getForReportAction({
147+
const body = getForReportActionTemp({
148+
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook
149+
translate: translateLocal,
136150
reportAction,
137-
policyID: report.policyID,
151+
policy,
138152
movedFromReport,
139153
movedToReport,
154+
policyTags,
140155
currentUserLogin,
141156
});
142157
const icon = usesIcon ? EXPENSIFY_ICON_URL : '';

src/libs/Notification/LocalNotification/index.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1-
import type {Report, ReportAction} from '@src/types/onyx';
1+
import Onyx from 'react-native-onyx';
2+
import type {OnyxCollection} from 'react-native-onyx';
3+
import ONYXKEYS from '@src/ONYXKEYS';
4+
import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx';
25
import BrowserNotifications from './BrowserNotifications';
36
import type {LocalNotificationClickHandler, LocalNotificationModifiedExpenseParams, LocalNotificationModule} from './types';
47

8+
let allPolicies: OnyxCollection<Policy>;
9+
// This is a temporary subscription until the modified-expense notification chain is fully migrated
10+
// see https://github.com/Expensify/App/issues/66336
11+
Onyx.connectWithoutView({
12+
key: ONYXKEYS.COLLECTION.POLICY,
13+
waitForCollectionCallback: true,
14+
callback: (value) => {
15+
allPolicies = value;
16+
},
17+
});
18+
19+
let allPolicyTags: OnyxCollection<PolicyTagLists>;
20+
// This is a temporary subscription until the modified-expense notification chain is fully migrated
21+
// see https://github.com/Expensify/App/issues/66336
22+
Onyx.connectWithoutView({
23+
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
24+
waitForCollectionCallback: true,
25+
callback: (value) => {
26+
allPolicyTags = value;
27+
},
28+
});
29+
530
function showCommentNotification(report: Report, reportAction: ReportAction, onClick: LocalNotificationClickHandler, conciergeReportID: string | undefined) {
631
BrowserNotifications.pushReportCommentNotification(report, reportAction, onClick, conciergeReportID, true);
732
}
@@ -10,8 +35,11 @@ function showUpdateAvailableNotification() {
1035
BrowserNotifications.pushUpdateAvailableNotification();
1136
}
1237

13-
function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, currentUserLogin, onClick}: LocalNotificationModifiedExpenseParams) {
14-
BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true, currentUserLogin});
38+
function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, currentUserLogin}: LocalNotificationModifiedExpenseParams) {
39+
const policyID = report.policyID;
40+
const policyTags = policyID ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] : undefined;
41+
const policy = policyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] : undefined;
42+
BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true, policyTags, policy, currentUserLogin});
1543
}
1644

1745
function clearReportNotifications(reportID: string | undefined) {

src/libs/Notification/LocalNotification/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {OnyxEntry} from 'react-native-onyx';
22
import type ClearReportNotifications from '@libs/Notification/clearReportNotifications/types';
3-
import type {Report, ReportAction} from '@src/types/onyx';
3+
import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx';
44

55
type LocalNotificationClickHandler = () => void;
66

@@ -26,6 +26,8 @@ type LocalNotificationModifiedExpenseParams = {
2626

2727
type LocalNotificationModifiedExpensePushParams = LocalNotificationModifiedExpenseParams & {
2828
usesIcon?: boolean;
29+
policyTags: OnyxEntry<PolicyTagLists>;
30+
policy?: OnyxEntry<Policy>;
2931
};
3032

3133
export type {LocalNotificationModule, LocalNotificationClickHandler, LocalNotificationData, LocalNotificationModifiedExpenseParams, LocalNotificationModifiedExpensePushParams};

0 commit comments

Comments
 (0)