From efea383fcba7a46f09342313abed5258a05e02c9 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 1 Feb 2024 18:26:42 +0100 Subject: [PATCH 1/2] Refactor workspace switcher and PolicyMembersUtils --- .../subscribeToReportCommentPushNotifications.ts | 2 +- src/libs/PolicyMembersUtils.ts | 8 +++----- src/pages/WorkspaceSwitcherPage.js | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts index 6e1f6e833609..070f83e19e0f 100644 --- a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts +++ b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.ts @@ -59,7 +59,7 @@ export default function subscribeToReportCommentPushNotifications() { Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID}); if (!reportBelongsToWorkspace) { - Navigation.navigateWithSwitchPolicyID({policyID: undefined, route: ROUTES.HOME}); + Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME}); } Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(String(reportID))); } catch (error) { diff --git a/src/libs/PolicyMembersUtils.ts b/src/libs/PolicyMembersUtils.ts index 12138129e134..4376de150f17 100644 --- a/src/libs/PolicyMembersUtils.ts +++ b/src/libs/PolicyMembersUtils.ts @@ -3,6 +3,7 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PolicyMembers} from '@src/types/onyx'; import {getCurrentUserAccountID} from './actions/Report'; +import {getPolicyMembersByIdWithoutCurrentUser} from './PolicyUtils'; let policyMembers: OnyxCollection; Onyx.connect({ @@ -17,11 +18,8 @@ function getPolicyMemberAccountIDs(policyID?: string) { } const currentUserAccountID = getCurrentUserAccountID(); - return policyMembers - ? Object.keys(policyMembers[`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`] ?? {}) - .map((policyMemberAccountID) => Number(policyMemberAccountID)) - .filter((policyMemberAccountID) => policyMemberAccountID !== currentUserAccountID) - : []; + + return getPolicyMembersByIdWithoutCurrentUser(policyMembers, policyID, currentUserAccountID); } export default getPolicyMemberAccountIDs; diff --git a/src/pages/WorkspaceSwitcherPage.js b/src/pages/WorkspaceSwitcherPage.js index 6c63617200c8..73734b5a5256 100644 --- a/src/pages/WorkspaceSwitcherPage.js +++ b/src/pages/WorkspaceSwitcherPage.js @@ -192,7 +192,7 @@ function WorkspaceSwitcherPage({policies}) { Date: Thu, 1 Feb 2024 18:35:07 +0100 Subject: [PATCH 2/2] Refactor showReportActionNotification --- src/libs/actions/Report.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index b4a7a12ccfca..782cf2b174c2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1969,7 +1969,7 @@ function showReportActionNotification(reportID: string, reportAction: ReportActi const policyMembersAccountIDs = policyID ? getPolicyMemberAccountIDs(policyID) : []; const reportBelongsToWorkspace = policyID ? doesReportBelongToWorkspace(report, policyMembersAccountIDs, policyID) : false; if (!reportBelongsToWorkspace) { - Navigation.navigateWithSwitchPolicyID({policyID: undefined, route: ROUTES.HOME}); + Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME}); } Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID)); });