From 8b3bd1503a55b055bd680b22b658a95da8d1c66e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 1 Nov 2024 10:30:56 +0700 Subject: [PATCH 1/7] fix: Skip onboarding screen with company size if signupQualifier is VSB --- src/libs/actions/Welcome/OnboardingFlow.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index 9b7dfc894b6a..a6f9b45bb279 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -5,6 +5,8 @@ import linkingConfig from '@libs/Navigation/linkingConfig'; import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; +import * as Policy from '@userActions/Policy/Policy'; +import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -34,6 +36,17 @@ Onyx.connect({ }, }); +let onboardingPolicyID: string; +Onyx.connect({ + key: ONYXKEYS.ONBOARDING_POLICY_ID, + callback: (value) => { + if (value === undefined) { + return; + } + onboardingPolicyID = value; + }, +}); + /** * Start a new onboarding flow or continue from the last visited onboarding page. */ @@ -57,7 +70,13 @@ 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); + if (!onboardingPolicyID) { + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + } + return `/${ROUTES.ONBOARDING_ACCOUNTING.route}`; } const isIndividual = onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL; if (isIndividual) { From 616cef797a567bf6b4f75fffdb0bf9c6f1dc536d Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 1 Nov 2024 10:38:30 +0700 Subject: [PATCH 2/7] fix lint --- src/libs/actions/Welcome/OnboardingFlow.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index a6f9b45bb279..b0885e97de9c 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -6,7 +6,6 @@ import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedSt import {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; import * as Policy from '@userActions/Policy/Policy'; -import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -73,8 +72,8 @@ function getOnboardingInitialPath(): string { Onyx.set(ONYXKEYS.ONBOARDING_COMPANY_SIZE, CONST.ONBOARDING_COMPANY_SIZE.MICRO); if (!onboardingPolicyID) { const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); - Welcome.setOnboardingPolicyID(policyID); + Onyx.set(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, adminsChatReportID ?? null); + Onyx.set(ONYXKEYS.ONBOARDING_POLICY_ID, policyID ?? null); } return `/${ROUTES.ONBOARDING_ACCOUNTING.route}`; } From 50daec071c009da8e0ba371d9d2c2d4d873090ba Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 1 Nov 2024 15:43:42 +0700 Subject: [PATCH 3/7] move the logic create workspace to accounting page --- src/libs/actions/Welcome/OnboardingFlow.ts | 17 ----------------- .../BaseOnboardingAccounting.tsx | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index b0885e97de9c..5a1b4fc0474a 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -5,7 +5,6 @@ import linkingConfig from '@libs/Navigation/linkingConfig'; import getAdaptedStateFromPath from '@libs/Navigation/linkingConfig/getAdaptedStateFromPath'; import {navigationRef} from '@libs/Navigation/Navigation'; import type {RootStackParamList} from '@libs/Navigation/types'; -import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -35,17 +34,6 @@ Onyx.connect({ }, }); -let onboardingPolicyID: string; -Onyx.connect({ - key: ONYXKEYS.ONBOARDING_POLICY_ID, - callback: (value) => { - if (value === undefined) { - return; - } - onboardingPolicyID = value; - }, -}); - /** * Start a new onboarding flow or continue from the last visited onboarding page. */ @@ -70,11 +58,6 @@ function getOnboardingInitialPath(): string { if (isVsb) { Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM); Onyx.set(ONYXKEYS.ONBOARDING_COMPANY_SIZE, CONST.ONBOARDING_COMPANY_SIZE.MICRO); - if (!onboardingPolicyID) { - const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - Onyx.set(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, adminsChatReportID ?? null); - Onyx.set(ONYXKEYS.ONBOARDING_POLICY_ID, policyID ?? null); - } return `/${ROUTES.ONBOARDING_ACCOUNTING.route}`; } const isIndividual = onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL; diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index ef5a58caf4ea..a6af41d9ddd2 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,4 +1,4 @@ -import React, {useMemo, useState} from 'react'; +import React, {useEffect, useMemo, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; import FormHelpMessage from '@components/FormHelpMessage'; @@ -20,6 +20,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 +42,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 +52,17 @@ 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; + + 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) From f4de5a0aa09cfa0adaba562c57efcca6c38da1d6 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Fri, 1 Nov 2024 15:45:16 +0700 Subject: [PATCH 4/7] add comment --- src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index a6af41d9ddd2..63e4b435bcd3 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -54,6 +54,8 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding 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; From 206cd0f63b8358893d07c3dda9c142ea6879bb5b Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 7 Nov 2024 16:05:08 +0700 Subject: [PATCH 5/7] fix: dup create workspace --- .../OnboardingAccounting/BaseOnboardingAccounting.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 63e4b435bcd3..649f9cb74340 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,4 +1,5 @@ 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'; @@ -60,7 +61,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding if (!isVsb || !!onboardingPolicyID) { return; } - + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); @@ -162,10 +163,10 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding onboardingCompanySize, userReportedIntegration, ); - - Welcome.setOnboardingAdminsChatReportID(); - Welcome.setOnboardingPolicyID(); - + InteractionManager.runAfterInteractions(() => { + Welcome.setOnboardingAdminsChatReportID(); + Welcome.setOnboardingPolicyID(); + }); navigateAfterOnboarding(isSmallScreenWidth, shouldUseNarrowLayout, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, route.params?.backTo); }} pressOnEnter From 9a9600f7c5f054aea867c886f0ea2a212d935af2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 7 Nov 2024 16:12:53 +0700 Subject: [PATCH 6/7] fix lint --- src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 649f9cb74340..f9f456daf541 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -61,7 +61,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding if (!isVsb || !!onboardingPolicyID) { return; } - + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); From d979c4a39d0cf6934bda89b8e920d2e07b6a7d55 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 11 Nov 2024 09:36:36 +0700 Subject: [PATCH 7/7] add comment --- src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index f9f456daf541..6e3e4c62aeda 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -163,6 +163,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding onboardingCompanySize, userReportedIntegration, ); + // Avoid creating new WS because onboardingPolicyID is cleared before unmounting InteractionManager.runAfterInteractions(() => { Welcome.setOnboardingAdminsChatReportID(); Welcome.setOnboardingPolicyID();