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
23 changes: 19 additions & 4 deletions src/libs/Notification/LocalNotification/BrowserNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 : '';
Expand Down
34 changes: 31 additions & 3 deletions src/libs/Notification/LocalNotification/index.ts
Original file line number Diff line number Diff line change
@@ -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<Policy>;
// 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<PolicyTagLists>;
// 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);
}
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/libs/Notification/LocalNotification/types.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -26,6 +26,8 @@ type LocalNotificationModifiedExpenseParams = {

type LocalNotificationModifiedExpensePushParams = LocalNotificationModifiedExpenseParams & {
usesIcon?: boolean;
policyTags: OnyxEntry<PolicyTagLists>;
policy?: OnyxEntry<Policy>;
};

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