diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index da9cf10cfde7..1245ee92fca2 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -2359,6 +2359,7 @@ function createTransactionThreadReport(params: CreateTransactionThreadReportPara isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, + hasReportActions: false, }); return optimisticTransactionThread; } @@ -2700,6 +2701,7 @@ function createChildReport( isNewThread: true, betas, isSelfTourViewed, + hasReportActions: false, currentUserAccountID, }); } else { @@ -3616,6 +3618,20 @@ function updateRoomVisibility(reportID: string, previousValue: RoomVisibility | API.write(WRITE_COMMANDS.UPDATE_ROOM_VISIBILITY, parameters, {optimisticData, failureData}); } +type ToggleSubscribeToChildReportParams = { + childReportID: string | undefined; + currentUserAccountID: number; + parentReportAction: ReportAction; + parentReport: OnyxEntry; + introSelected: OnyxEntry; + isSelfTourViewed: boolean | undefined; + hasCompletedGuidedSetupFlow: boolean | undefined; + betas: OnyxEntry; + prevNotificationPreference: NotificationPreference | undefined; + personalDetails: OnyxEntry; + hasReportActions: boolean; +}; + /** * This will subscribe to an existing thread, or create a new one and then subscribe to it if necessary * @@ -3624,20 +3640,21 @@ function updateRoomVisibility(reportID: string, previousValue: RoomVisibility | * @param parentReport The parent report * @param prevNotificationPreference The previous notification preference for the child report */ -function toggleSubscribeToChildReport( - childReportID: string | undefined, - currentUserAccountID: number, - parentReportAction: ReportAction, - parentReport: OnyxEntry, - introSelected: OnyxEntry, - isSelfTourViewed: boolean | undefined, - hasCompletedGuidedSetupFlow: boolean | undefined, - betas: OnyxEntry, - prevNotificationPreference: NotificationPreference | undefined, - personalDetails: OnyxEntry, -) { +function toggleSubscribeToChildReport({ + childReportID, + currentUserAccountID, + parentReportAction, + parentReport, + introSelected, + isSelfTourViewed, + hasCompletedGuidedSetupFlow, + betas, + prevNotificationPreference, + personalDetails, + hasReportActions, +}: ToggleSubscribeToChildReportParams) { if (childReportID) { - openReport({reportID: childReportID, introSelected, betas, isSelfTourViewed, hasCompletedGuidedSetupFlow, currentUserAccountID}); + openReport({reportID: childReportID, introSelected, betas, isSelfTourViewed, hasCompletedGuidedSetupFlow, hasReportActions, currentUserAccountID}); const parentReportActionID = parentReportAction.reportActionID; if (!prevNotificationPreference || isHiddenForCurrentUser(prevNotificationPreference)) { updateNotificationPreference( @@ -3684,6 +3701,7 @@ function toggleSubscribeToChildReport( isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, + hasReportActions: false, currentUserAccountID, }); const notificationPreference = isHiddenForCurrentUser(prevNotificationPreference) ? CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS : CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; diff --git a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx index 9180c2924279..2942d4d1a187 100644 --- a/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx +++ b/src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx @@ -764,40 +764,45 @@ const ContextMenuActions: ContextMenuAction[] = [ (shouldDisplayThreadReplies || (!isDeletedAction && !isArchivedRoom)) ); }, - onPress: (closePopover, {reportAction, currentUserAccountID, originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, personalDetails}) => { + onPress: ( + closePopover, + {reportAction, currentUserAccountID, originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, personalDetails, childReportActions}, + ) => { const childReportNotificationPreference = getChildReportNotificationPreferenceReportUtils(reportAction); if (closePopover) { hideContextMenu(false, () => { ReportActionComposeFocusManager.focus(); - toggleSubscribeToChildReport( - reportAction?.childReportID, + toggleSubscribeToChildReport({ + childReportID: reportAction?.childReportID, currentUserAccountID, - reportAction, - originalReport, + parentReportAction: reportAction, + parentReport: originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, - childReportNotificationPreference, + prevNotificationPreference: childReportNotificationPreference, personalDetails, - ); + hasReportActions: !!childReportActions, + }); }); return; } ReportActionComposeFocusManager.focus(); - toggleSubscribeToChildReport( - reportAction?.childReportID, + toggleSubscribeToChildReport({ + childReportID: reportAction?.childReportID, currentUserAccountID, - reportAction, - originalReport, + parentReportAction: reportAction, + parentReport: originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, - childReportNotificationPreference, + prevNotificationPreference: childReportNotificationPreference, personalDetails, - ); + hasReportActions: !!childReportActions, + }); }, getDescription: () => {}, sentryLabel: CONST.SENTRY_LABEL.CONTEXT_MENU.JOIN_THREAD, @@ -825,40 +830,45 @@ const ContextMenuActions: ContextMenuAction[] = [ (shouldDisplayThreadReplies || (!isDeletedAction && !isArchivedRoom)) ); }, - onPress: (closePopover, {reportAction, currentUserAccountID, originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, personalDetails}) => { + onPress: ( + closePopover, + {reportAction, currentUserAccountID, originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, personalDetails, childReportActions}, + ) => { const childReportNotificationPreference = getChildReportNotificationPreferenceReportUtils(reportAction); if (closePopover) { hideContextMenu(false, () => { ReportActionComposeFocusManager.focus(); - toggleSubscribeToChildReport( - reportAction?.childReportID, + toggleSubscribeToChildReport({ + childReportID: reportAction?.childReportID, currentUserAccountID, - reportAction, - originalReport, + parentReportAction: reportAction, + parentReport: originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, - childReportNotificationPreference, + prevNotificationPreference: childReportNotificationPreference, personalDetails, - ); + hasReportActions: !!childReportActions, + }); }); return; } ReportActionComposeFocusManager.focus(); - toggleSubscribeToChildReport( - reportAction?.childReportID, + toggleSubscribeToChildReport({ + childReportID: reportAction?.childReportID, currentUserAccountID, - reportAction, - originalReport, + parentReportAction: reportAction, + parentReport: originalReport, introSelected, isSelfTourViewed, hasCompletedGuidedSetupFlow, betas, - childReportNotificationPreference, + prevNotificationPreference: childReportNotificationPreference, personalDetails, - ); + hasReportActions: !!childReportActions, + }); }, getDescription: () => {}, sentryLabel: CONST.SENTRY_LABEL.CONTEXT_MENU.LEAVE_THREAD, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 83cae41bd658..81d79627be6a 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -6085,18 +6085,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - CHILD_REPORT_ID, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - false, - undefined, - undefined, - 'hidden', - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: false, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: 'hidden', + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6114,7 +6115,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport(undefined, TEST_USER_ACCOUNT_ID, PARENT_REPORT_ACTION, PARENT_REPORT, INTRO_SELECTED, false, undefined, undefined, undefined, undefined); + Report.toggleSubscribeToChildReport({ + childReportID: undefined, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: false, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: undefined, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6132,7 +6145,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport(CHILD_REPORT_ID, TEST_USER_ACCOUNT_ID, PARENT_REPORT_ACTION, PARENT_REPORT, undefined, true, undefined, undefined, 'hidden', undefined); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: undefined, + isSelfTourViewed: true, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: 'hidden', + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6150,18 +6175,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - CHILD_REPORT_ID, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - true, - undefined, - undefined, - CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: true, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6179,7 +6205,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport(undefined, TEST_USER_ACCOUNT_ID, PARENT_REPORT_ACTION, PARENT_REPORT, INTRO_SELECTED, true, undefined, undefined, undefined, undefined); + Report.toggleSubscribeToChildReport({ + childReportID: undefined, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: true, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: undefined, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6197,7 +6235,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport(undefined, TEST_USER_ACCOUNT_ID, PARENT_REPORT_ACTION, PARENT_REPORT, INTRO_SELECTED, false, undefined, undefined, undefined, undefined); + Report.toggleSubscribeToChildReport({ + childReportID: undefined, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: false, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: undefined, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6215,18 +6265,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - CHILD_REPORT_ID, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - true, - undefined, - undefined, - 'hidden', - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: true, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: 'hidden', + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6244,18 +6295,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - CHILD_REPORT_ID, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - false, - undefined, - undefined, - undefined, - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: false, + hasCompletedGuidedSetupFlow: undefined, + betas: undefined, + prevNotificationPreference: undefined, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6274,18 +6326,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - CHILD_REPORT_ID, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - undefined, - undefined, - testBetas, - 'hidden', - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: CHILD_REPORT_ID, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: undefined, + hasCompletedGuidedSetupFlow: undefined, + betas: testBetas, + prevNotificationPreference: 'hidden', + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); @@ -6304,18 +6357,19 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); expect(() => { - Report.toggleSubscribeToChildReport( - undefined, - TEST_USER_ACCOUNT_ID, - PARENT_REPORT_ACTION, - PARENT_REPORT, - INTRO_SELECTED, - undefined, - undefined, - testBetas, - undefined, - undefined, - ); + Report.toggleSubscribeToChildReport({ + childReportID: undefined, + currentUserAccountID: TEST_USER_ACCOUNT_ID, + parentReportAction: PARENT_REPORT_ACTION, + parentReport: PARENT_REPORT, + introSelected: INTRO_SELECTED, + isSelfTourViewed: undefined, + hasCompletedGuidedSetupFlow: undefined, + betas: testBetas, + prevNotificationPreference: undefined, + personalDetails: undefined, + hasReportActions: false, + }); }).not.toThrow(); }); });