diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index 8f704da582c5..61fb6050460e 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -60,16 +60,26 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding // 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(() => { - const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy); - if (!isVsb || filteredPolicies.length > 0 || isLoadingOnyxValue(allPoliciesResult)) { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + 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]); + }, [isVsb, paidGroupPolicy, allPolicies, allPoliciesResult]); + + // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signups + useEffect(() => { + if (!paidGroupPolicy || onboardingPolicyID) { + return; + } + Welcome.setOnboardingAdminsChatReportID(paidGroupPolicy.chatReportIDAdmins?.toString()); + Welcome.setOnboardingPolicyID(paidGroupPolicy.id); + }, [paidGroupPolicy, onboardingPolicyID]); const accountingOptions: OnboardingListItem[] = useMemo(() => { const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME) diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 91919a64d0bb..dd8b9745ed7d 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -12,6 +12,7 @@ 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'; @@ -29,6 +30,10 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE 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(''); @@ -63,7 +68,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE } Welcome.setOnboardingCompanySize(selectedCompanySize); - if (!onboardingPolicyID) { + if (!onboardingPolicyID && !paidGroupPolicy) { const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID);