From 0f0c7a0fe80d8633b5510744be7e48559bd5bed8 Mon Sep 17 00:00:00 2001 From: shahid Date: Sat, 7 Dec 2024 12:52:00 +0530 Subject: [PATCH 1/8] Skip workspace creation for OD signups and move logic back to OnboardingPurpose page --- .../BaseOnboardingAccounting.tsx | 22 +------------------ .../BaseOnboardingEmployees.tsx | 7 ------ .../BaseOnboardingPurpose.tsx | 13 +++++++++++ 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index c616479eea2d..0ef0e3118500 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useMemo, useState} from 'react'; +import React, {useMemo, useState} from 'react'; import {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; @@ -20,16 +20,13 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import navigateAfterOnboarding from '@libs/navigateAfterOnboarding'; import Navigation from '@libs/Navigation/Navigation'; -import * as PolicyUtils from '@libs/PolicyUtils'; 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'; import type {OnboardingAccounting} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {} from '@src/types/onyx/Bank'; -import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type {BaseOnboardingAccountingProps} from './types'; type OnboardingListItem = ListItem & { @@ -45,10 +42,8 @@ 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 [allPolicies, allPoliciesResult] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); const {canUseDefaultRooms} = usePermissions(); @@ -56,21 +51,6 @@ 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(() => { - const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy); - if (!isVsb || filteredPolicies.length > 0 || isLoadingOnyxValue(allPoliciesResult)) { - return; - } - - const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); - Welcome.setOnboardingPolicyID(policyID); - }, [isVsb, allPolicies, allPoliciesResult]); - const accountingOptions: OnboardingListItem[] = useMemo(() => { const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME) .map((connectionName): OnboardingListItem | undefined => { diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index fee409c6480d..183144aba586 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -12,7 +12,6 @@ import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; -import * as Policy from '@userActions/Policy/Policy'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import type {OnboardingCompanySize} from '@src/CONST'; @@ -63,12 +62,6 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE } Welcome.setOnboardingCompanySize(selectedCompanySize); - if (!onboardingPolicyID) { - const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); - Welcome.setOnboardingPolicyID(policyID); - } - Navigation.navigate(ROUTES.ONBOARDING_ACCOUNTING.getRoute(route.params?.backTo)); }} pressOnEnter diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 74d2facf55dc..28d30ff2c751 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -19,7 +19,10 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import Navigation from '@libs/Navigation/Navigation'; import OnboardingRefManager from '@libs/OnboardingRefManager'; import type {TOnboardingRef} from '@libs/OnboardingRefManager'; +import * as PolicyUtils from '@libs/PolicyUtils'; import variables from '@styles/variables'; +import * as Policy from '@userActions/Policy/Policy'; +import {generatePolicyID} from '@userActions/Policy/Policy'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -58,6 +61,11 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro const theme = useTheme(); const [onboardingErrorMessage, onboardingErrorMessageResult] = useOnyx(ONYXKEYS.ONBOARDING_ERROR_MESSAGE); + const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy); + const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING); + const hasSignupQualifier = !!(onboardingValues && 'signupQualifier' in onboardingValues); const maxHeight = shouldEnableMaxHeight ? windowHeight : undefined; const paddingHorizontal = onboardingIsMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5; @@ -83,6 +91,11 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro Welcome.setOnboardingErrorMessage(''); if (choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { + if (!onboardingPolicyID && !hasSignupQualifier && filteredPolicies.length === 0) { + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', generatePolicyID(), choice); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + } Navigation.navigate(ROUTES.ONBOARDING_EMPLOYEES.getRoute(route.params?.backTo)); return; } From cf61eba73ff4dda7a06a33ef31d2d40e2f957625 Mon Sep 17 00:00:00 2001 From: shahid Date: Sat, 7 Dec 2024 22:19:43 +0530 Subject: [PATCH 2/8] fix eslint error --- src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 183144aba586..472d26b345d9 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -27,7 +27,6 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE const {translate} = useLocalize(); const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); - const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const {onboardingIsMediumOrLargerScreenWidth} = useResponsiveLayout(); const [selectedCompanySize, setSelectedCompanySize] = useState(onboardingCompanySize); const [error, setError] = useState(''); From cf21dc82b7b2a2e8a1a58ed3625905fe0eb89e42 Mon Sep 17 00:00:00 2001 From: shahid Date: Wed, 18 Dec 2024 16:45:04 +0530 Subject: [PATCH 3/8] Remove hasSignupQualifier check, rely on onboardingPolicyID for workspace creation --- src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 003a94ce8b0e..0f7c435289c6 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -67,9 +67,6 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy); - const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING); - const hasSignupQualifier = !!(onboardingValues && 'signupQualifier' in onboardingValues); - const maxHeight = shouldEnableMaxHeight ? windowHeight : undefined; const paddingHorizontal = onboardingIsMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5; @@ -93,7 +90,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro Welcome.setOnboardingPurposeSelected(choice); Welcome.setOnboardingErrorMessage(''); if (choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { - if (!onboardingPolicyID && !hasSignupQualifier && filteredPolicies.length === 0) { + if (!onboardingPolicyID && filteredPolicies.length === 0) { const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', generatePolicyID(), choice); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); From 5170a994e0d2299cb843577d231f122f01cb979b Mon Sep 17 00:00:00 2001 From: shahid Date: Wed, 18 Dec 2024 16:51:35 +0530 Subject: [PATCH 4/8] fix eslint issue --- src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 0f7c435289c6..2a81f67472cd 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -21,9 +21,9 @@ import OnboardingRefManager from '@libs/OnboardingRefManager'; import type {TOnboardingRef} from '@libs/OnboardingRefManager'; import * as PolicyUtils from '@libs/PolicyUtils'; import variables from '@styles/variables'; -import * as Session from '@userActions/Session'; import * as Policy from '@userActions/Policy/Policy'; import {generatePolicyID} from '@userActions/Policy/Policy'; +import * as Session from '@userActions/Session'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; From 96a81cb65fcf83820e8422eca3d3371c2d46e6e6 Mon Sep 17 00:00:00 2001 From: shahid Date: Fri, 20 Dec 2024 05:33:34 +0530 Subject: [PATCH 5/8] Set onboarding policy and admin chat ID for OD signups --- .../BaseOnboardingAccounting.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 81445b4e8d94..b9fbdab06508 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 {InteractionManager} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import Button from '@components/Button'; @@ -20,6 +20,7 @@ import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import navigateAfterOnboarding from '@libs/navigateAfterOnboarding'; import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; import variables from '@styles/variables'; import * as Report from '@userActions/Report'; import * as Welcome from '@userActions/Welcome'; @@ -46,9 +47,20 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const onboardingPolicyForOD = Object.values(allPolicies ?? {}).find(PolicyUtils.isPaidGroupPolicy); const {canUseDefaultRooms} = usePermissions(); const {activeWorkspaceID} = useActiveWorkspace(); + // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signups + useEffect(() => { + if (!onboardingPolicyForOD || onboardingPolicyID) { + return; + } + Welcome.setOnboardingAdminsChatReportID(onboardingPolicyForOD.chatReportIDAdmins?.toString()); + Welcome.setOnboardingPolicyID(onboardingPolicyForOD.id); + }, [onboardingPolicyForOD, onboardingPolicyID]); + const [userReportedIntegration, setUserReportedIntegration] = useState(undefined); const [error, setError] = useState(''); const accountingOptions: OnboardingListItem[] = useMemo(() => { From c21ef33df07050035640bd89b262b4893b5c3be4 Mon Sep 17 00:00:00 2001 From: shahid Date: Fri, 20 Dec 2024 05:45:31 +0530 Subject: [PATCH 6/8] fix eslint --- src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index b9fbdab06508..0c800de1b0c4 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -52,6 +52,9 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding const {canUseDefaultRooms} = usePermissions(); const {activeWorkspaceID} = useActiveWorkspace(); + const [userReportedIntegration, setUserReportedIntegration] = useState(undefined); + const [error, setError] = useState(''); + // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signups useEffect(() => { if (!onboardingPolicyForOD || onboardingPolicyID) { @@ -60,9 +63,6 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding Welcome.setOnboardingAdminsChatReportID(onboardingPolicyForOD.chatReportIDAdmins?.toString()); Welcome.setOnboardingPolicyID(onboardingPolicyForOD.id); }, [onboardingPolicyForOD, onboardingPolicyID]); - - const [userReportedIntegration, setUserReportedIntegration] = useState(undefined); - const [error, setError] = useState(''); const accountingOptions: OnboardingListItem[] = useMemo(() => { const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME) .map((connectionName): OnboardingListItem | undefined => { From eaadcd68f4fa6e642e0042c837c3bbff4e1d5411 Mon Sep 17 00:00:00 2001 From: shahid Date: Tue, 24 Dec 2024 05:12:40 +0530 Subject: [PATCH 7/8] create workspace in onboarding flow if not created by backend --- .../BaseOnboardingAccounting.tsx | 29 +++++++++++++++---- .../BaseOnboardingEmployees.tsx | 13 +++++++++ .../BaseOnboardingPurpose.tsx | 12 +------- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 0c800de1b0c4..b136c75b5116 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -22,12 +22,14 @@ import navigateAfterOnboarding from '@libs/navigateAfterOnboarding'; import Navigation from '@libs/Navigation/Navigation'; import * as PolicyUtils from '@libs/PolicyUtils'; 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'; import type {OnboardingAccounting} from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {} from '@src/types/onyx/Bank'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import type {BaseOnboardingAccountingProps} from './types'; type OnboardingListItem = ListItem & { @@ -43,26 +45,41 @@ 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 [allPolicies, allPoliciesResult] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); - const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const onboardingPolicyForOD = Object.values(allPolicies ?? {}).find(PolicyUtils.isPaidGroupPolicy); const {canUseDefaultRooms} = usePermissions(); const {activeWorkspaceID} = useActiveWorkspace(); 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 + const paidGroupPolicy = Object.values(allPolicies ?? {}).find(PolicyUtils.isPaidGroupPolicy); + useEffect(() => { + if (!isVsb || paidGroupPolicy || isLoadingOnyxValue(allPoliciesResult)) { + return; + } + + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + }, [isVsb, allPolicies, allPoliciesResult]); // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signups useEffect(() => { - if (!onboardingPolicyForOD || onboardingPolicyID) { + if (!paidGroupPolicy || onboardingPolicyID) { return; } - Welcome.setOnboardingAdminsChatReportID(onboardingPolicyForOD.chatReportIDAdmins?.toString()); - Welcome.setOnboardingPolicyID(onboardingPolicyForOD.id); - }, [onboardingPolicyForOD, onboardingPolicyID]); + Welcome.setOnboardingAdminsChatReportID(paidGroupPolicy.chatReportIDAdmins?.toString()); + Welcome.setOnboardingPolicyID(paidGroupPolicy.id); + }, [paidGroupPolicy, onboardingPolicyID]); + const accountingOptions: OnboardingListItem[] = useMemo(() => { const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME) .map((connectionName): OnboardingListItem | undefined => { diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 85995cf7a81b..dd8b9745ed7d 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -12,6 +12,8 @@ import useLocalize from '@hooks/useLocalize'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; +import * as Policy from '@userActions/Policy/Policy'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; import type {OnboardingCompanySize} from '@src/CONST'; @@ -27,6 +29,11 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE const {translate} = useLocalize(); const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); + const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + + const paidGroupPolicy = Object.values(allPolicies ?? {}).find(PolicyUtils.isPaidGroupPolicy); + const {onboardingIsMediumOrLargerScreenWidth} = useResponsiveLayout(); const [selectedCompanySize, setSelectedCompanySize] = useState(onboardingCompanySize); const [error, setError] = useState(''); @@ -61,6 +68,12 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE } Welcome.setOnboardingCompanySize(selectedCompanySize); + if (!onboardingPolicyID && !paidGroupPolicy) { + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + } + Navigation.navigate(ROUTES.ONBOARDING_ACCOUNTING.getRoute(route.params?.backTo)); }} pressOnEnter diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 2a81f67472cd..b4e9e54dfd87 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -19,10 +19,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions'; import Navigation from '@libs/Navigation/Navigation'; import OnboardingRefManager from '@libs/OnboardingRefManager'; import type {TOnboardingRef} from '@libs/OnboardingRefManager'; -import * as PolicyUtils from '@libs/PolicyUtils'; import variables from '@styles/variables'; -import * as Policy from '@userActions/Policy/Policy'; -import {generatePolicyID} from '@userActions/Policy/Policy'; import * as Session from '@userActions/Session'; import * as Welcome from '@userActions/Welcome'; import CONST from '@src/CONST'; @@ -64,9 +61,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro const theme = useTheme(); const [onboardingErrorMessage, onboardingErrorMessageResult] = useOnyx(ONYXKEYS.ONBOARDING_ERROR_MESSAGE); - const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); - const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy); + const maxHeight = shouldEnableMaxHeight ? windowHeight : undefined; const paddingHorizontal = onboardingIsMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5; @@ -90,11 +85,6 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro Welcome.setOnboardingPurposeSelected(choice); Welcome.setOnboardingErrorMessage(''); if (choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) { - if (!onboardingPolicyID && filteredPolicies.length === 0) { - const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', generatePolicyID(), choice); - Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); - Welcome.setOnboardingPolicyID(policyID); - } Navigation.navigate(ROUTES.ONBOARDING_EMPLOYEES.getRoute(route.params?.backTo)); return; } From a0afb376a1428de3f1a32068e597dc52ed56c539 Mon Sep 17 00:00:00 2001 From: shahid Date: Tue, 24 Dec 2024 05:26:38 +0530 Subject: [PATCH 8/8] fix eslint --- src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index b136c75b5116..61fb6050460e 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -62,6 +62,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding // So we need to create the new workspace in the accounting step const paidGroupPolicy = Object.values(allPolicies ?? {}).find(PolicyUtils.isPaidGroupPolicy); useEffect(() => { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing if (!isVsb || paidGroupPolicy || isLoadingOnyxValue(allPoliciesResult)) { return; } @@ -69,7 +70,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); - }, [isVsb, allPolicies, allPoliciesResult]); + }, [isVsb, paidGroupPolicy, allPolicies, allPoliciesResult]); // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signups useEffect(() => {