From d85da2b23bda3fa44ee39ca1205ddf3d5a8f4e0b Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 29 Oct 2025 20:56:04 +0530 Subject: [PATCH 1/2] Refactored navigateToTrainingModal to pure function --- src/libs/actions/Report.ts | 17 ++++++----------- src/pages/ReportChangeWorkspacePage.tsx | 8 ++++++++ tests/actions/ReportTest.ts | 7 ++++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 7d9ee9807f84..a20bd7bec21b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -182,7 +182,6 @@ import ROUTES from '@src/ROUTES'; import INPUT_IDS from '@src/types/form/NewRoomForm'; import type { Account, - DismissedProductTraining, IntroSelected, InvitedEmailsToAccountIDs, NewGroupChatDraft, @@ -418,12 +417,6 @@ Onyx.connect({ callback: (value) => (allReportDraftComments = value), }); -let nvpDismissedProductTraining: OnyxEntry; -Onyx.connect({ - key: ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, - callback: (value) => (nvpDismissedProductTraining = value), -}); - const allPolicies: OnyxCollection = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -5673,8 +5666,8 @@ function updatePolicyIdForReportAndThreads( }); } -function navigateToTrainingModal(dismissedProductTrainingNVP: OnyxEntry, reportID: string) { - if (dismissedProductTrainingNVP?.[CONST.CHANGE_POLICY_TRAINING_MODAL]) { +function navigateToTrainingModal(isChangePolicyTrainingModalDismissed: boolean, reportID: string) { + if (isChangePolicyTrainingModalDismissed) { return; } @@ -5965,6 +5958,7 @@ function changeReportPolicy( accountID: number, email: string, hasViolationsParam: boolean, + isChangePolicyTrainingModalDismissed: boolean, isASAPSubmitBetaEnabled: boolean, reportNextStep?: ReportNextStep, isReportLastVisibleArchived = false, @@ -5994,7 +5988,7 @@ function changeReportPolicy( // If the dismissedProductTraining.changeReportModal is not set, // navigate to CHANGE_POLICY_EDUCATIONAL and a backTo param for the report page. - navigateToTrainingModal(nvpDismissedProductTraining, report.reportID); + navigateToTrainingModal(isChangePolicyTrainingModalDismissed, report.reportID); } /** @@ -6006,6 +6000,7 @@ function changeReportPolicyAndInviteSubmitter( accountID: number, email: string, hasViolationsParam: boolean, + isChangePolicyTrainingModalDismissed: boolean, isASAPSubmitBetaEnabled: boolean, employeeList: PolicyEmployeeList | undefined, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], @@ -6069,7 +6064,7 @@ function changeReportPolicyAndInviteSubmitter( // If the dismissedProductTraining.changeReportModal is not set, // navigate to CHANGE_POLICY_EDUCATIONAL and a backTo param for the report page. - navigateToTrainingModal(nvpDismissedProductTraining, report.reportID); + navigateToTrainingModal(isChangePolicyTrainingModalDismissed, report.reportID); } /** diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 533ae3725484..96651f7d0130 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -1,4 +1,5 @@ import React, {useCallback} from 'react'; +import type {OnyxEntry} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import {useSession} from '@components/OnyxListItemProvider'; @@ -31,12 +32,15 @@ import { import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; +import type {DismissedProductTraining} from '@src/types/onyx'; import NotFoundPage from './ErrorPage/NotFoundPage'; import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound'; import withReportOrNotFound from './home/report/withReportOrNotFound'; type ReportChangeWorkspacePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps; +const changePolicyTrainingModalDismissedSelector = (nvpDismissedProductTraining: OnyxEntry): boolean => !!nvpDismissedProductTraining?.[CONST.CHANGE_POLICY_TRAINING_MODAL]; + function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePageProps) { const reportID = report?.reportID; const {isOffline} = useNetwork(); @@ -46,6 +50,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro const [policies, fetchStatus] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {canBeMissing: false}); const [reportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`, {canBeMissing: true}); + const [isChangePolicyTrainingModalDismissed = false] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true, selector: changePolicyTrainingModalDismissedSelector}); const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: false}); const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true}); const isReportLastVisibleArchived = useReportIsArchived(report?.parentReportID); @@ -83,6 +88,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '', hasViolations, + isChangePolicyTrainingModalDismissed, isASAPSubmitBetaEnabled, employeeList, formatPhoneNumber, @@ -95,6 +101,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '', hasViolations, + isChangePolicyTrainingModalDismissed, isASAPSubmitBetaEnabled, reportNextStep, isReportLastVisibleArchived, @@ -113,6 +120,7 @@ function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePagePro hasViolations, isASAPSubmitBetaEnabled, reportNextStep, + isChangePolicyTrainingModalDismissed, ], ); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index e103613e14f8..02c067f20d9a 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -2069,7 +2069,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); // When moving to another workspace - Report.changeReportPolicy(expenseReport, newPolicy, 1, '', true, false); + Report.changeReportPolicy(expenseReport, newPolicy, 1, '', true, false, false); await waitForBatchedUpdates(); // Then the expense report should not be archived anymore @@ -2112,7 +2112,7 @@ describe('actions/Report', () => { await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${newPolicy.id}`, newPolicy); // When moving to another workspace - Report.changeReportPolicy(expenseReport, newPolicy, 1, '', false, false); + Report.changeReportPolicy(expenseReport, newPolicy, 1, '', false, false, false); await waitForBatchedUpdates(); // Then the expense report chatReportID and parentReportID should be updated to the new expense chat reportID @@ -2159,6 +2159,7 @@ describe('actions/Report', () => { '', true, false, + false, { [adminEmail]: {role: CONST.POLICY.ROLE.ADMIN}, }, @@ -2238,7 +2239,7 @@ describe('actions/Report', () => { await waitForBatchedUpdates(); // Call changeReportPolicyAndInviteSubmitter - Report.changeReportPolicyAndInviteSubmitter(expenseReport, newPolicy, 1, '', true, false, employeeList, TestHelper.formatPhoneNumber, false); + Report.changeReportPolicyAndInviteSubmitter(expenseReport, newPolicy, 1, '', true, false, false, employeeList, TestHelper.formatPhoneNumber, false); await waitForBatchedUpdates(); // Simulate network failure From f265d3a9bf4cdb50a7607102197169776cc3001e Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 29 Oct 2025 21:11:58 +0530 Subject: [PATCH 2/2] Fixed prettier --- src/pages/ReportChangeWorkspacePage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportChangeWorkspacePage.tsx b/src/pages/ReportChangeWorkspacePage.tsx index 96651f7d0130..f7e5cb58f842 100644 --- a/src/pages/ReportChangeWorkspacePage.tsx +++ b/src/pages/ReportChangeWorkspacePage.tsx @@ -39,7 +39,8 @@ import withReportOrNotFound from './home/report/withReportOrNotFound'; type ReportChangeWorkspacePageProps = WithReportOrNotFoundProps & PlatformStackScreenProps; -const changePolicyTrainingModalDismissedSelector = (nvpDismissedProductTraining: OnyxEntry): boolean => !!nvpDismissedProductTraining?.[CONST.CHANGE_POLICY_TRAINING_MODAL]; +const changePolicyTrainingModalDismissedSelector = (nvpDismissedProductTraining: OnyxEntry): boolean => + !!nvpDismissedProductTraining?.[CONST.CHANGE_POLICY_TRAINING_MODAL]; function ReportChangeWorkspacePage({report, route}: ReportChangeWorkspacePageProps) { const reportID = report?.reportID;