Skip to content

Commit c32ad42

Browse files
authored
Merge pull request #52899 from FitseTLT/fix-creating-workspace-in-onboarding-on-refresh
Fix - [CRITICAL] Multiple workspaces get created when someone either refreshes the page, or drops off and returns later.
2 parents 93f7874 + b156a5e commit c32ad42

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import CONST from '@src/CONST';
2828
import type {OnboardingAccounting} from '@src/CONST';
2929
import ONYXKEYS from '@src/ONYXKEYS';
3030
import type {} from '@src/types/onyx/Bank';
31+
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
3132
import type {BaseOnboardingAccountingProps} from './types';
3233

3334
type OnboardingListItem = ListItem & {
@@ -45,7 +46,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding
4546
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
4647
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
4748
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
48-
const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID);
49+
const [onboardingPolicyID, onboardingPolicyIDResult] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID);
4950
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID);
5051
const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE);
5152
const {canUseDefaultRooms} = usePermissions();
@@ -58,14 +59,14 @@ function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboarding
5859
// If the signupQualifier is VSB, the company size step is skip.
5960
// So we need to create the new workspace in the accounting step
6061
useEffect(() => {
61-
if (!isVsb || !!onboardingPolicyID) {
62+
if (!isVsb || !!onboardingPolicyID || isLoadingOnyxValue(onboardingPolicyIDResult)) {
6263
return;
6364
}
6465

6566
const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM);
6667
Welcome.setOnboardingAdminsChatReportID(adminsChatReportID);
6768
Welcome.setOnboardingPolicyID(policyID);
68-
}, [isVsb, onboardingPolicyID]);
69+
}, [isVsb, onboardingPolicyID, onboardingPolicyIDResult]);
6970

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

0 commit comments

Comments
 (0)