Skip to content

Commit

Permalink
Merge pull request Expensify#53093 from FitseTLT/fix-onboarding-polic…
Browse files Browse the repository at this point in the history
…y-creation-bug

[CP Staging] Fix - `A Follow up on` [CRITICAL] Multiple workspaces get created when someone either refreshes the page, or drops off and returns later.
  • Loading branch information
mountiny authored Nov 28, 2024
2 parents 43640b1 + 8fd2c45 commit 3b832f8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 Policy from '@userActions/Policy/Policy';
import * as Report from '@userActions/Report';
Expand All @@ -46,7 +47,8 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
const [onboardingPolicyID, onboardingPolicyIDResult] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID);
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();
Expand All @@ -59,14 +61,15 @@ 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
useEffect(() => {
if (!isVsb || !!onboardingPolicyID || isLoadingOnyxValue(onboardingPolicyIDResult)) {
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, onboardingPolicyID, onboardingPolicyIDResult]);
}, [isVsb, allPolicies, allPoliciesResult]);

const accountingOptions: OnboardingListItem[] = useMemo(() => {
const policyAccountingOptions = Object.values(CONST.POLICY.CONNECTIONS.NAME)
Expand Down

0 comments on commit 3b832f8

Please sign in to comment.