diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index 7939c2825148..47292f118391 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -8,7 +8,6 @@ import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleCon import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type { - IntroSelected, PersonalDetails, PersonalDetailsList, Policy, @@ -28,7 +27,6 @@ import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNum import {translateLocal} from './Localize'; // eslint-disable-next-line import/no-cycle import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage'; -import isTrackOnboardingChoice from './OnboardingUtils'; import Parser from './Parser'; import {getDisplayNameOrDefault} from './PersonalDetailsUtils'; import {getCleanedTagName, isPolicyAdmin, isPolicyFieldListEmpty} from './PolicyUtils'; @@ -185,6 +183,7 @@ type ComputeReportName = { // TODO: Make this required when https://github.com/Expensify/App/issues/66411 is done conciergeReportID?: string; reportAttributes?: ReportAttributesDerivedValue['reports']; + isTrackIntentUser: boolean | undefined; }; let allPersonalDetails: OnyxEntry; @@ -197,15 +196,6 @@ Onyx.connect({ }, }); -let introSelected: OnyxEntry; -// eslint-disable-next-line rulesdir/no-onyx-connect -- NextStepUtils is a pure utility called from action files that cannot use hooks -Onyx.connect({ - key: ONYXKEYS.NVP_INTRO_SELECTED, - callback: (value) => { - introSelected = value; - }, -}); - function generateArchivedReportName(reportName: string): string { return `${reportName} (${translateLocal('common.archived')}) `; } @@ -436,6 +426,7 @@ function computeReportNameBasedOnReportAction( parentReport: Report | undefined, personalDetailsList: OnyxEntry, reportAttributes: ReportAttributesDerivedValue['reports'] | undefined, + isTrackIntentUser: boolean | undefined, ): string | undefined { if (!parentReportAction) { return undefined; @@ -451,7 +442,7 @@ function computeReportNameBasedOnReportAction( } if ( shouldShowMarkAsDone({ - isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice), + isTrackIntentUser, policy: reportPolicy, report: parentReport, }) @@ -933,6 +924,7 @@ function computeReportName({ allPolicyTags, conciergeReportID, reportAttributes, + isTrackIntentUser, }: ComputeReportName): string { if (!report?.reportID) { return ''; @@ -951,6 +943,7 @@ function computeReportName({ parentReport, personalDetailsList, reportAttributes, + isTrackIntentUser, ); if (parentReportActionBasedName) { @@ -976,6 +969,7 @@ function computeReportName({ currentUserLogin, conciergeReportID, reportAttributes, + isTrackIntentUser, }); return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, isOriginalReportDeleted(parentReportAction, originalReport), translateLocal); } diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index afb7937405c8..e773e03514e7 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -1,5 +1,6 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {getIsOffline} from '@libs/NetworkState'; +import isTrackOnboardingChoice from '@libs/OnboardingUtils'; import {getLinkedTransactionID} from '@libs/ReportActionsUtils'; import {computeReportName} from '@libs/ReportNameUtils'; import {generateIsEmptyReport, generateReportAttributes, hasVisibleReportFieldViolations, isArchivedReport, isPolicyAdmin, isPolicyExpenseChat, isValidReport} from '@libs/ReportUtils'; @@ -90,11 +91,25 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.COLLECTION.POLICY_TAGS, ONYXKEYS.CONCIERGE_REPORT_ID, + ONYXKEYS.NVP_INTRO_SELECTED, ONYXKEYS.COLLECTION.REPORT_METADATA, ONYXKEYS.NETWORK, ], compute: ( - [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, session, policies, policyTags, conciergeReportID], + [ + reports, + preferredLocale, + transactionViolations, + reportActions, + reportNameValuePairs, + transactions, + personalDetails, + session, + policies, + policyTags, + conciergeReportID, + introSelected, + ], {currentValue, sourceValues}, ) => { // Read the in-memory offline state directly (NETWORK is a dependency so recompute still fires when it changes). @@ -118,7 +133,8 @@ export default createOnyxDerivedValueConfig({ let needsFullRecompute = (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues) && preferredLocale !== currentValue?.locale) || displayNamesChanged || - hasKeyTriggeredCompute(ONYXKEYS.CONCIERGE_REPORT_ID, sourceValues); + hasKeyTriggeredCompute(ONYXKEYS.CONCIERGE_REPORT_ID, sourceValues) || + hasKeyTriggeredCompute(ONYXKEYS.NVP_INTRO_SELECTED, sourceValues); // if policies are loaded first time, we need to recompute all report attributes to get correct action badge in LHN, such as Approve because it depends on policy's type (see canApproveIOU function) const policyChangedReportKeys: string[] = []; @@ -356,6 +372,7 @@ export default createOnyxDerivedValueConfig({ allPolicyTags: policyTags, conciergeReportID: conciergeReportID ?? undefined, reportAttributes: currentValue?.reports, + isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice), }) : '', isEmpty: generateIsEmptyReport(report, isReportArchived), diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index 63311c1e21b8..06caed82cb3d 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -124,9 +124,12 @@ describe('OnyxDerived', () => { const transaction = createRandomTransaction(1); // When the report attributes are recomputed with both report and transaction updates - reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {}); + reportAttributes.compute( + [reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], + {}, + ); const reportAttributesComputedValue = reportAttributes.compute( - [reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], + [reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], { sourceValues: { [ONYXKEYS.COLLECTION.REPORT]: { diff --git a/tests/unit/ReportNameUtilsTest.ts b/tests/unit/ReportNameUtilsTest.ts index 1bce09b884e3..57400ee0f766 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -46,6 +46,7 @@ describe('ReportNameUtils', () => { reportActions, currentUserAccountID: currentUserID, currentUserLogin, + isTrackIntentUser: false, }); const participantsPersonalDetails: PersonalDetailsList = [ { @@ -556,6 +557,7 @@ describe('ReportNameUtils', () => { currentUserAccountID, currentUserLogin: '', allPolicyTags: policyTagsCollection, + isTrackIntentUser: false, }); expect(name).toContain('Cost Center'); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index cbf3abdfb507..412412b4b744 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -307,6 +307,7 @@ const computeReportName = ( currentUserAccountID: currentUserID, currentUserLogin: currentUserEmail, conciergeReportID, + isTrackIntentUser: false, }); const participantsPersonalDetails: PersonalDetailsList = { '1': {