diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index 9b7dfc894b6a..5a1b4fc0474a 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -57,7 +57,8 @@ function getOnboardingInitialPath(): string { if (isVsb) { Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - return `/${ROUTES.ONBOARDING_EMPLOYEES.route}`; + Onyx.set(ONYXKEYS.ONBOARDING_COMPANY_SIZE, CONST.ONBOARDING_COMPANY_SIZE.MICRO); + return `/${ROUTES.ONBOARDING_ACCOUNTING.route}`; } const isIndividual = onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL; if (isIndividual) { diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index ef5a58caf4ea..6e3e4c62aeda 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,4 +1,5 @@ -import React, {useMemo, useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; +import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -20,6 +21,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import navigateAfterOnboarding from '@libs/navigateAfterOnboarding'; import Navigation from '@libs/Navigation/Navigation'; import variables from '@styles/variables'; +import * as Policy from '@userActions/Policy/Policy'; import * as Report from '@userActions/Report'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; @@ -41,6 +43,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding // We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout(); + const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING); const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); @@ -50,6 +53,19 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding const [userReportedIntegration, setUserReportedIntegration] = useState(undefined); const [error, setError] = useState(''); + const isVsb = onboardingValues && 'signupQualifier' in onboardingValues && onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB; + + // If the signupQualifier is VSB, the company size step is skip. + // So we need to create the new workspace in the accounting step + useEffect(() => { + if (!isVsb || !!onboardingPolicyID) { + return; + } + + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + }, [isVsb, onboardingPolicyID]); const accountingOptions: OnboardingListItem[] = useMemo(() => { const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME) @@ -147,10 +163,11 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding onboardingCompanySize, userReportedIntegration, ); - - Welcome.setOnboardingAdminsChatReportID(); - Welcome.setOnboardingPolicyID(); - + // Avoid creating new WS because onboardingPolicyID is cleared before unmounting + InteractionManager.runAfterInteractions(() => { + Welcome.setOnboardingAdminsChatReportID(); + Welcome.setOnboardingPolicyID(); + }); navigateAfterOnboarding(isSmallScreenWidth, shouldUseNarrowLayout, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, route.params?.backTo); }} pressOnEnter