Skip to content

Commit

Permalink
Merge pull request #53729 from Shahidullah-Muffakir/fix/53326
Browse files Browse the repository at this point in the history
Move Workspace creation in the onboardingFlow to OnboardingPurpose page and skip Workspace creation for OD signups
  • Loading branch information
carlosmiceli authored Dec 24, 2024
2 parents a088878 + a0afb37 commit 8b7096f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 | null | undefined>(onboardingCompanySize);
const [error, setError] = useState('');
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8b7096f

Please sign in to comment.