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 9c1644720c51..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'; @@ -10263,6 +10263,7 @@ function prepareOnboardingOnyxData( userReportedIntegration?: OnboardingAccounting, wasInvited?: boolean, companySize?: OnboardingCompanySize, + selectedInterestedFeatures: string[] = [], ) { if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) { // eslint-disable-next-line no-param-reassign @@ -10350,6 +10351,12 @@ function prepareOnboardingOnyxData( let createWorkspaceTaskReportID; const tasksData = onboardingMessage.tasks .filter((task) => { + if (engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { + if (selectedInterestedFeatures?.length && TASK_TO_FEATURE[task.type] && !selectedInterestedFeatures.includes(TASK_TO_FEATURE[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 1f439259e34e..c7ea65503fd1 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4225,6 +4225,7 @@ function completeOnboarding({ companySize, userReportedIntegration, wasInvited, + selectedInterestedFeatures = [], }: { engagementChoice: OnboardingPurpose; onboardingMessage: OnboardingMessage; @@ -4236,6 +4237,7 @@ function completeOnboarding({ companySize?: OnboardingCompanySize; userReportedIntegration?: OnboardingAccounting; wasInvited?: boolean; + selectedInterestedFeatures?: string[]; }) { const onboardingData = prepareOnboardingOnyxData( introSelected, @@ -4246,6 +4248,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..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, @@ -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 43aac315620c..87054f120c4d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -377,6 +377,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', () => {