From 1430ce538e03e39035268d52065468524400bbc1 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 27 Aug 2025 14:55:30 +0700 Subject: [PATCH 1/2] fix: connect your corporate card task is shown even the user disabled this feature --- src/libs/ReportUtils.ts | 14 ++++++++++++++ src/libs/actions/Report.ts | 3 +++ .../BaseOnboardingInterestedFeatures.tsx | 1 + tests/unit/ReportUtilsTest.ts | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 1ae31f9dd17c..ba05a3d3016a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -10268,7 +10268,15 @@ function prepareOnboardingOnyxData( userReportedIntegration?: OnboardingAccounting, wasInvited?: boolean, companySize?: OnboardingCompanySize, + selectedInterestedFeatures: string[] = [], ) { + const taskToFeature: Record = { + [CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES]: 'categories', + [CONST.ONBOARDING_TASK_TYPE.ADD_ACCOUNTING_INTEGRATION]: 'accounting', + [CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD]: 'company-cards', + [CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS]: 'tags', + }; + if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) { // eslint-disable-next-line no-param-reassign onboardingMessage = getOnboardingMessages().onboardingMessages[CONST.ONBOARDING_CHOICES.PERSONAL_SPEND]; @@ -10355,6 +10363,12 @@ function prepareOnboardingOnyxData( let createWorkspaceTaskReportID; const tasksData = onboardingMessage.tasks .filter((task) => { + if (engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { + if (selectedInterestedFeatures?.length && taskToFeature[task.type] && !selectedInterestedFeatures.includes(taskToFeature[task.type])) { + return false; + } + } + if (([CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES, CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS] as string[]).includes(task.type) && userReportedIntegration) { return false; } diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 83558bfafab2..8948bf8a3825 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4180,6 +4180,7 @@ function completeOnboarding({ companySize, userReportedIntegration, wasInvited, + selectedInterestedFeatures = [], }: { engagementChoice: OnboardingPurpose; onboardingMessage: OnboardingMessage; @@ -4191,6 +4192,7 @@ function completeOnboarding({ companySize?: OnboardingCompanySize; userReportedIntegration?: OnboardingAccounting; wasInvited?: boolean; + selectedInterestedFeatures?: string[]; }) { const onboardingData = prepareOnboardingOnyxData( introSelected, @@ -4201,6 +4203,7 @@ function completeOnboarding({ userReportedIntegration, wasInvited, companySize, + selectedInterestedFeatures, ); if (!onboardingData) { return; diff --git a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx index d8d32cd075c1..9881b79928cf 100644 --- a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx +++ b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx @@ -209,6 +209,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin userReportedIntegration: newUserReportedIntegration, firstName: currentUserPersonalDetails?.firstName, lastName: currentUserPersonalDetails?.lastName, + selectedInterestedFeatures: featuresMap.filter((feature) => feature.enabled).map((feature) => feature.id), }); if (shouldOnboardingRedirectToOldDot(onboardingCompanySize, newUserReportedIntegration)) { diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index bb385dbb1c53..5a40fcc4d8ec 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -376,6 +376,25 @@ describe('ReportUtils', () => { }), ); }); + + it('should not create tasks if the task feature is not in the selected interested features', () => { + const result = prepareOnboardingOnyxData( + undefined, + CONST.ONBOARDING_CHOICES.MANAGE_TEAM, + { + message: 'This is a test', + tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false, mediaAttributes: {}}], + }, + '1', + undefined, + undefined, + undefined, + undefined, + ['categories', 'accounting', 'tags'], + ); + + expect(result?.guidedSetupData.filter((data) => data.type === 'task')).toHaveLength(0); + }); }); describe('getIconsForParticipants', () => { From 970396381fbeabac0d727688b13bfd7d7b6fef81 Mon Sep 17 00:00:00 2001 From: mkzie2 Date: Wed, 3 Sep 2025 11:14:18 +0700 Subject: [PATCH 2/2] move taskTofeature to CONST --- src/CONST/index.ts | 22 ++++++++++++++++++- src/libs/ReportUtils.ts | 11 ++-------- .../BaseOnboardingInterestedFeatures.tsx | 22 +++++++++---------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 8b1046994725..2d0c2696d2a7 100755 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -7166,6 +7166,26 @@ const CONTINUATION_DETECTION_SEARCH_FILTER_KEYS = [ CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTER, ] as SearchFilterKey[]; +const FEATURE_IDS = { + CATEGORIES: 'categories', + ACCOUNTING: 'accounting', + COMPANY_CARDS: 'company-cards', + TAGS: 'tags', + WORKFLOWS: 'workflows', + INVOICES: 'invoices', + RULES: 'rules', + PER_DIEM: 'per-diem', + DISTANCE_RATES: 'distance-rates', + EXPENSIFY_CARD: 'expensify-card', +}; + +const TASK_TO_FEATURE: Record = { + [CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES]: FEATURE_IDS.CATEGORIES, + [CONST.ONBOARDING_TASK_TYPE.ADD_ACCOUNTING_INTEGRATION]: FEATURE_IDS.ACCOUNTING, + [CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD]: FEATURE_IDS.COMPANY_CARDS, + [CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS]: FEATURE_IDS.TAGS, +}; + type Country = keyof typeof CONST.ALL_COUNTRIES; type IOUType = ValueOf; @@ -7179,6 +7199,6 @@ type CancellationType = ValueOf; export type {Country, IOUAction, IOUType, IOURequestType, SubscriptionType, FeedbackSurveyOptionID, CancellationType, OnboardingInvite, OnboardingAccounting, IOUActionParams}; -export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS}; +export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS, TASK_TO_FEATURE, FEATURE_IDS}; export default CONST; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 941b09b5d3be..3d1255818bb2 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -20,7 +20,7 @@ import type {LocaleContextProps} from '@components/LocaleContextProvider'; import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput'; import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; import type {IOUAction, IOUType, OnboardingAccounting} from '@src/CONST'; -import CONST from '@src/CONST'; +import CONST, {TASK_TO_FEATURE} from '@src/CONST'; import type {ParentNavigationSummaryParams} from '@src/languages/params'; import type {TranslationPaths} from '@src/languages/types'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -10265,13 +10265,6 @@ function prepareOnboardingOnyxData( companySize?: OnboardingCompanySize, selectedInterestedFeatures: string[] = [], ) { - const taskToFeature: Record = { - [CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES]: 'categories', - [CONST.ONBOARDING_TASK_TYPE.ADD_ACCOUNTING_INTEGRATION]: 'accounting', - [CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD]: 'company-cards', - [CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS]: 'tags', - }; - if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) { // eslint-disable-next-line no-param-reassign onboardingMessage = getOnboardingMessages().onboardingMessages[CONST.ONBOARDING_CHOICES.PERSONAL_SPEND]; @@ -10359,7 +10352,7 @@ function prepareOnboardingOnyxData( const tasksData = onboardingMessage.tasks .filter((task) => { if (engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { - if (selectedInterestedFeatures?.length && taskToFeature[task.type] && !selectedInterestedFeatures.includes(taskToFeature[task.type])) { + if (selectedInterestedFeatures?.length && TASK_TO_FEATURE[task.type] && !selectedInterestedFeatures.includes(TASK_TO_FEATURE[task.type])) { return false; } } diff --git a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx index 9881b79928cf..8de0a6715f9a 100644 --- a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx +++ b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx @@ -33,7 +33,7 @@ import {shouldOnboardingRedirectToOldDot} from '@libs/OnboardingUtils'; import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; import {closeReactNativeApp} from '@userActions/HybridApp'; import CONFIG from '@src/CONFIG'; -import CONST from '@src/CONST'; +import CONST, {FEATURE_IDS} from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import ONYXKEYS from '@src/ONYXKEYS'; import type {BaseOnboardingInterestedFeaturesProps, Feature, SectionObject} from './types'; @@ -67,66 +67,66 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin const features: Feature[] = useMemo(() => { return [ { - id: 'categories', + id: FEATURE_IDS.CATEGORIES, title: translate('workspace.moreFeatures.categories.title'), icon: Illustrations.FolderOpen, enabledByDefault: true, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES, }, { - id: 'accounting', + id: FEATURE_IDS.ACCOUNTING, title: translate('workspace.moreFeatures.connections.title'), icon: Illustrations.Accounting, enabledByDefault: !!userReportedIntegration, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS, }, { - id: 'company-cards', + id: FEATURE_IDS.COMPANY_CARDS, title: translate('workspace.moreFeatures.companyCards.title'), icon: Illustrations.CompanyCard, enabledByDefault: true, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_COMPANY_CARDS, }, { - id: 'workflows', + id: FEATURE_IDS.WORKFLOWS, title: translate('workspace.moreFeatures.workflows.title'), icon: Illustrations.Workflows, enabledByDefault: true, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS, }, { - id: 'invoices', + id: FEATURE_IDS.INVOICES, title: translate('workspace.moreFeatures.invoices.title'), icon: Illustrations.InvoiceBlue, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_INVOICING, }, { - id: 'rules', + id: FEATURE_IDS.RULES, title: translate('workspace.moreFeatures.rules.title'), icon: Illustrations.Rules, apiEndpoint: WRITE_COMMANDS.SET_POLICY_RULES_ENABLED, requiresUpdate: true, }, { - id: 'distance-rates', + id: FEATURE_IDS.DISTANCE_RATES, title: translate('workspace.moreFeatures.distanceRates.title'), icon: Illustrations.Car, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES, }, { - id: 'expensify-card', + id: FEATURE_IDS.EXPENSIFY_CARD, title: translate('workspace.moreFeatures.expensifyCard.title'), icon: Illustrations.HandCard, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS, }, { - id: 'tags', + id: FEATURE_IDS.TAGS, title: translate('workspace.moreFeatures.tags.title'), icon: Illustrations.Tag, apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_TAGS, }, { - id: 'per-diem', + id: FEATURE_IDS.PER_DIEM, title: translate('workspace.moreFeatures.perDiem.title'), icon: Illustrations.PerDiem, apiEndpoint: WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM,