diff --git a/src/libs/Notification/LocalNotification/BrowserNotifications.ts b/src/libs/Notification/LocalNotification/BrowserNotifications.ts index 0f3a312714d7f..9dbd6982ea9eb 100644 --- a/src/libs/Notification/LocalNotification/BrowserNotifications.ts +++ b/src/libs/Notification/LocalNotification/BrowserNotifications.ts @@ -3,7 +3,9 @@ import {Str} from 'expensify-common'; import type {ImageSourcePropType} from 'react-native'; import EXPENSIFY_ICON_URL from '@assets/images/expensify-logo-round-clearspace.png'; import * as AppUpdate from '@libs/actions/AppUpdate'; -import {getForReportAction} from '@libs/ModifiedExpenseMessage'; +// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook +import {translateLocal} from '@libs/Localize'; +import {getForReportActionTemp} from '@libs/ModifiedExpenseMessage'; import {getTextFromHtml} from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import playSound, {SOUNDS} from '@libs/Sound'; @@ -130,13 +132,26 @@ export default { push(title, body, icon, data, onClick); }, - pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon = false, currentUserLogin}: LocalNotificationModifiedExpensePushParams) { + pushModifiedExpenseNotification({ + report, + reportAction, + movedFromReport, + movedToReport, + onClick, + usesIcon = false, + policyTags, + policy, + currentUserLogin, + }: LocalNotificationModifiedExpensePushParams) { const title = reportAction.person?.map((f) => f.text).join(', ') ?? ''; - const body = getForReportAction({ + const body = getForReportActionTemp({ + // eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook + translate: translateLocal, reportAction, - policyID: report.policyID, + policy, movedFromReport, movedToReport, + policyTags, currentUserLogin, }); const icon = usesIcon ? EXPENSIFY_ICON_URL : ''; diff --git a/src/libs/Notification/LocalNotification/index.ts b/src/libs/Notification/LocalNotification/index.ts index 42446710b4887..fcf855898381c 100644 --- a/src/libs/Notification/LocalNotification/index.ts +++ b/src/libs/Notification/LocalNotification/index.ts @@ -1,7 +1,32 @@ -import type {Report, ReportAction} from '@src/types/onyx'; +import Onyx from 'react-native-onyx'; +import type {OnyxCollection} from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; import BrowserNotifications from './BrowserNotifications'; import type {LocalNotificationClickHandler, LocalNotificationModifiedExpenseParams, LocalNotificationModule} from './types'; +let allPolicies: OnyxCollection; +// This is a temporary subscription until the modified-expense notification chain is fully migrated +// see https://github.com/Expensify/App/issues/66336 +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.POLICY, + waitForCollectionCallback: true, + callback: (value) => { + allPolicies = value; + }, +}); + +let allPolicyTags: OnyxCollection; +// This is a temporary subscription until the modified-expense notification chain is fully migrated +// see https://github.com/Expensify/App/issues/66336 +Onyx.connectWithoutView({ + key: ONYXKEYS.COLLECTION.POLICY_TAGS, + waitForCollectionCallback: true, + callback: (value) => { + allPolicyTags = value; + }, +}); + function showCommentNotification(report: Report, reportAction: ReportAction, onClick: LocalNotificationClickHandler, conciergeReportID: string | undefined) { BrowserNotifications.pushReportCommentNotification(report, reportAction, onClick, conciergeReportID, true); } @@ -10,8 +35,11 @@ function showUpdateAvailableNotification() { BrowserNotifications.pushUpdateAvailableNotification(); } -function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, currentUserLogin, onClick}: LocalNotificationModifiedExpenseParams) { - BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true, currentUserLogin}); +function showModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, currentUserLogin}: LocalNotificationModifiedExpenseParams) { + const policyID = report.policyID; + const policyTags = policyID ? allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] : undefined; + const policy = policyID ? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] : undefined; + BrowserNotifications.pushModifiedExpenseNotification({report, reportAction, movedFromReport, movedToReport, onClick, usesIcon: true, policyTags, policy, currentUserLogin}); } function clearReportNotifications(reportID: string | undefined) { diff --git a/src/libs/Notification/LocalNotification/types.ts b/src/libs/Notification/LocalNotification/types.ts index 00d39120f2102..cb0b6805ebde8 100644 --- a/src/libs/Notification/LocalNotification/types.ts +++ b/src/libs/Notification/LocalNotification/types.ts @@ -1,6 +1,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import type ClearReportNotifications from '@libs/Notification/clearReportNotifications/types'; -import type {Report, ReportAction} from '@src/types/onyx'; +import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; type LocalNotificationClickHandler = () => void; @@ -26,6 +26,8 @@ type LocalNotificationModifiedExpenseParams = { type LocalNotificationModifiedExpensePushParams = LocalNotificationModifiedExpenseParams & { usesIcon?: boolean; + policyTags: OnyxEntry; + policy?: OnyxEntry; }; export type {LocalNotificationModule, LocalNotificationClickHandler, LocalNotificationData, LocalNotificationModifiedExpenseParams, LocalNotificationModifiedExpensePushParams};