Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$250] Improve/fix logic for creating a workspace during onboarding flow #53326

Open
carlosmiceli opened this issue Nov 29, 2024 · 39 comments
Open
Assignees
Labels
Daily KSv2 External Added to denote the issue can be worked on by a contributor Improvement Item broken or needs improvement. Reviewing Has a PR in review

Comments

@carlosmiceli
Copy link
Contributor

carlosmiceli commented Nov 29, 2024

We want new users that are taken to the Employee Count screen to have a workspace created automatically (this is currently in place):

image

However, for signups that join via expensify.com and select either vsb or smb as signup qualifier, we want to skip actually creating a workspace at this step because that's going to be created automatically via the API during the account creation. Otherwise we'll be creating one twice. These are the corresponding vsb and smb signup options on expensify.com:

Screenshot 2024-11-29 at 4 03 39 PM

To clarify, the current onboarding flow logic for creating a workspace should still occur for any new user that's taken to the onboarding modal and does NOT have either vsb or smb as a signupQualifier. Those would be:

  • a sign-up on new.expensify.com on web/mWeb
  • a sign-up on the New Expensify mobile app
  • a sign-up on the native Expensify mobile app

Please include videos of all the possible signup cases and confirming that only one workspace is created for each. Also confirm that this bug where we created duplicate workspaces doesn't reoccur (if it's still happening). Finally, we think there may be an extreme edge case where:

  • User downloaded old version of the app
  • Signs up via web
  • Gets deep linked into the app
  • App is on old version
  • Somehow gets two workspaces.

Please include in your proposal a way to prevent this if it could occur.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021862573059516200142
  • Upwork Job ID: 1862573059516200142
  • Last Price Increase: 2024-11-29
Issue OwnerCurrent Issue Owner: @thesahindia
@carlosmiceli carlosmiceli added External Added to denote the issue can be worked on by a contributor Daily KSv2 Improvement Item broken or needs improvement. labels Nov 29, 2024
@carlosmiceli carlosmiceli self-assigned this Nov 29, 2024
@melvin-bot melvin-bot bot changed the title Improve/fix logic for creating a workspace during onboarding flow [$250] Improve/fix logic for creating a workspace during onboarding flow Nov 29, 2024
Copy link

melvin-bot bot commented Nov 29, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021862573059516200142

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 29, 2024
Copy link

melvin-bot bot commented Nov 29, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)

@nkdengineer
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Improve/fix logic for creating a workspace during onboarding flow

What is the root cause of that problem?

This is an improvement

What changes do you think we should make in order to solve the problem?

Instead of creating the policy in the employee step or auto-create a new workspace for vsb onboarding, we can only create the new workspace when the user completes the final step.

  1. We can remove the create a new workspace logic here and here

  2. In here, if the onboardingPurposeSelected is newDotManageTeam, create a new workspace via createWorkspace and then get adminsChatReportID, policyID and pass it to completeOnboarding function

let onboardingAdminsChatReportID; let onboardingPolicyID;
if (onboardingPurposeSelected === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) {
    const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM);
    onboardingAdminsChatReportID =  adminsChatReportID;
    onboardingPolicyID = policyID;
};
Report.completeOnboarding(
    onboardingPurposeSelected,
    CONST.ONBOARDING_MESSAGES[onboardingPurposeSelected],
    undefined,
    undefined,
    onboardingAdminsChatReportID ?? undefined,
    onboardingPolicyID,
    undefined,
    onboardingCompanySize,
    userReportedIntegration,
);

That can make sure the workspace is only created when we complete the onboarding flow with onboardingPurposeSelected as newDotManageTeam

What alternative solutions did you explore? (Optional)

In completeOnboarding function, we can build the optimistic data for new workspace via buildPolicyData function and then add these onyx data in completeOnboarding and from the backend, we will use the onboardingPolicyID to create a new workspace.

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Nov 29, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

If user completed the onboarding flow using OD, two workspaces are created.

What is the root cause of that problem?

  1. if signupQualifier is VSB, we are not showing How many employees do you have? or OnboardingEmployees page, hence this useEffect is added to automatically create a workspace for it.
    // 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]);
  2. if signupQualifier is SMB, it is not considered anywhere in code to skip the workspace creation, workspace is created in any case here.
    if (!onboardingPolicyID) {
    const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM);
    Welcome.setOnboardingAdminsChatReportID(adminsChatReportID);
    Welcome.setOnboardingPolicyID(policyID);
    }

What changes do you think we should make in order to solve the problem?

  1. remove this useEffect, because it is used to create a workspace if signupQualifier is 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]);

  2. add one more condition here in BaseOnboardingEmployees, if the signupQualifier is SMB, then don't create the workspace.
    const isSmb = onboardingValues && 'signupQualifier' in onboardingValues && onboardingValues.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB;

    if (!onboardingPolicyID) {
    const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, '', Policy.generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM);
    Welcome.setOnboardingAdminsChatReportID(adminsChatReportID);
    Welcome.setOnboardingPolicyID(policyID);
    }

as :
if (!onboardingPolicyID && !isSmb) {

  1. and to cover the edge case, we can add the following conditions in above line:
const filteredPolicies = Object.values(allPolicies ?? {}).filter(PolicyUtils.isPaidGroupPolicy);

as:

                  if (!onboardingPolicyID && !isSmb && filteredPolicies.length <=0 ) {

@danielrvidal
Copy link
Contributor

@thesahindia any thoughts on which proposal to go with?

@melvin-bot melvin-bot bot added the Overdue label Dec 2, 2024
@carlosmiceli
Copy link
Contributor Author

Waiting for proposals review.

@carlosmiceli carlosmiceli added Daily KSv2 and removed Daily KSv2 labels Dec 3, 2024
@melvin-bot melvin-bot bot removed the Overdue label Dec 3, 2024
@thesahindia
Copy link
Member

@Shahidullah-Muffakir's proposal will work for all the cases.

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented Dec 3, 2024

Current assignee @carlosmiceli is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@nkdengineer
Copy link
Contributor

@thesahindia I don't think the selected proposal is correct when we sign up from OldDot

  1. It redirects to NewDot and no workspace is created
  2. The employee step will be skipped if we sign with vsb or smb

So we should only create a new workspace at the final step to verify that the workspace is only created when we complete the onboarding flow.

@Shahidullah-Muffakir
Copy link
Contributor

@thesahindia I don't think the selected proposal is correct when we sign up from OldDot

  1. It redirects to NewDot and no workspace is created
  2. The employee step will be skipped if we sign with vsb or smb

So we should only create a new workspace at the final step to verify that the workspace is only created when we complete the onboarding flow.

This is the issue we are trying to solve, we don't want to create aother workspace, as mention in the OP, the api will automatically create workspace for vsb and smb

we want to skip actually creating a workspace at this step because that's going to be created automatically via the API during the account creation.

@nkdengineer
Copy link
Contributor

we want to skip actually creating a workspace at this step because that's going to be created automatically via the API during the account creation.

Actually, no workspace is created after signing up via old dot.

@nkdengineer
Copy link
Contributor

Currently, the NewDot onboarding flow is skipped for accounts created from OldDot

// Onboarding is an array or an empty object for old accounts and accounts created from OldDot
if (Array.isArray(onboarding) || isEmptyObject(onboarding)) {
return true;
}

Then the duplicate workspace case we only need to fix is the user can create multiple workspaces at the employee step if we do not complete the onboarding and login at multiple devices.

@carlosmiceli
Copy link
Contributor Author

carlosmiceli commented Dec 3, 2024

Actually, no workspace is created after signing up via old dot.

What do you mean, can you elaborate further? Are you saying that there's no way for an OD signup to have a workspace created? There could be a case I think for an individual sign up to still go through the workspace creation, but will double check.

the NewDot onboarding flow is skipped for accounts created from OldDot

If this is true, then we need to change this. We shouldn't skip onboarding for OD signups. cc @mountiny @danielrvidal bringing you in to confirm that this is at least part of the issue besides the work here, since we were talking about this modal not showing yesterday.

@carlosmiceli
Copy link
Contributor Author

the NewDot onboarding flow is skipped for accounts created from OldDot

Let's clarify this:

  • If an OD account is migrated to ND, they should skip the onboarding.
  • ALL new OD signups that get redirected should see the onboarding.

I'll update that comment to avoid confusions.

Are we good to proceed @thesahindia or should we still evaluate some of @nkdengineer's comments?

@nkdengineer
Copy link
Contributor

What do you mean, can you elaborate further? Are you saying that there's no way for an OD signup to have a workspace created? There could be a case I think for an individual sign up to still go through the workspace creation, but will double check.

we want to skip actually creating a workspace at this step because that's going to be created automatically via the API during the account creation.

@carlosmiceli In the description, we're saying that a workspace will be created automatically via the API during the account creation. But actually, there's no workspace after the user signs from OD with vsb or smb and redirects to ND. This is a confusing description.

the NewDot onboarding flow is skipped for accounts created from OldDot

I think this is for the old account.

@carlosmiceli
Copy link
Contributor Author

there's no workspace after the user signs from OD with vsb or smb and redirects to ND

That's being worked on in the BE, but the FE needs to be ready beforehand or we will create duplicate workspaces. That's the goal of this issue.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 3, 2024
@carlosmiceli
Copy link
Contributor Author

@Shahidullah-Muffakir are you still seeing this happening? I think this was recently solved, but can you confirm to me that you're seeing this happen now?

@Shahidullah-Muffakir
Copy link
Contributor

@carlosmiceli Yes, I’m still experiencing this issue.

Screen.20Recording.202024-12-06.20at.209.mp4

@carlosmiceli
Copy link
Contributor Author

Gotcha, asking about it, I thought it was solved but apparently not. This should be solved soon, though, can we start working on a PR in the meantime? At least to start getting ahead a bit.

@Shahidullah-Muffakir
Copy link
Contributor

Got it. I’ll start working on the PR in the meantime.

@allgandalf
Copy link
Contributor

@Shahidullah-Muffakir can you please verify if you face the same issue on desktop and native app ?

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Dec 6, 2024

@Shahidullah-Muffakir can you please verify if you face the same issue on desktop and native app ?

@allgandalf I tested on all supported platforms, and it’s working correctly on mWeb, native, and desktop.

However, on macOS Chrome and Safari, the onboarding flow modal doesn’t appear when the browser window size is large(but if I refresh the page after the signup, then the onboarding flow modal appears). If I decrease the window width(narrowLayout), it works fine on both browsers. Considering this, I think it appears to be a frontend issue. I’ll look into it to see if I can find a possible solution.

Given this update, @carlosmiceli, I’ll go ahead and create the PR now since I can proceed with testing.
Thank you.

Screen.20Recording.202024-12-07.20at.201.mp4

@carlosmiceli
Copy link
Contributor Author

@Shahidullah-Muffakir That's great news! I'll create a separate issue and assign you as well so you can fix the onboarding display too, sounds good?

@carlosmiceli
Copy link
Contributor Author

@Shahidullah-Muffakir Here: #53724

@Shahidullah-Muffakir
Copy link
Contributor

@Shahidullah-Muffakir That's great news! I'll create a separate issue and assign you as well so you can fix the onboarding display too, sounds good?

@carlosmiceli Sounds good, thank you! I’ll look into it.

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Dec 7, 2024

@carlosmiceli

When you have time, could you confirm the following:

  1. If a user signs up through OD and selects Manage expenses for a small team (1-9 employees), is the workspace of type team automatically created in the backend? I’ve tested this multiple times, and it seems like no workspace is being created. Alternatively, if the backend is creating the workspace, it might not be sending the newly created workspace in the OpenApp endpoint when the user is redirected to ND.

  2. If a user selects Control expenses for a larger organization (10+ employees) in OD, the user is not redirected to ND. Is this the expected behavior?

Thanks!

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Dec 7, 2024

Also, just to mention, I found the root cause of the issue here: #50759. At that time, the backend changes weren’t ready, so they moved the workspace creation step to the employee step since the first step was being skipped for signups through OD, and the workspace was not being created for users signing up through OD. I think moving the workspace creation step back to the first step is a good idea now because we’re safe with the vsb and smb signupQualifiers skipping that step (Consider it in the PR).

@carlosmiceli
Copy link
Contributor Author

carlosmiceli commented Dec 7, 2024

  1. It is not implemented yet, because if it was, we would be creating twice as many workspaces while we still have the workspace being created in the onboarding modal. It's on hold because we need to merge both the ND and the BE PRs at the same time.
  2. Yes.

@carlosmiceli
Copy link
Contributor Author

I think moving the workspace creation step back to the first step is a good idea now because we’re safe with the vsb and smb signupQualifiers skipping that step

Sorry, not sure I follow, can you explain a bit more?

@Shahidullah-Muffakir
Copy link
Contributor

Sorry, not sure I follow, can you explain a bit more?

In the issue #50758, the problem was that a workspace wasn't being created when a user signed up through OD. This happened because the workspace creation logic was located in BaseOnboardingPurpose.tsx. However, since the onboarding purpose step is skipped for OD signups (as the purpose is pre-selected in OD), the workspace creation logic was also being skipped, leading to the issue.

To address this, the PR moved the workspace creation logic from BaseOnboardingPurpose to BaseOnboardingEmployees. This ensured that for OD signups, the workspace would still be created.

Now that the backend changes are complete, a workspace is automatically created during OD signups by the backend itself. As a result, even if BaseOnboardingPurpose is skipped, a workspace will already exist.

Given this, we can safely move the workspace creation logic back to BaseOnboardingPurpose. Since this step is skipped for OD signups, it won’t cause duplicate workspace creation.

@carlosmiceli
Copy link
Contributor Author

Very clear, thank you! Yes, that sounds correct.

@Shahidullah-Muffakir
Copy link
Contributor

PR #53729 is ready for review, Thank you.

@carlosmiceli
Copy link
Contributor Author

Thank you! Let's wait for @thesahindia to review 💪

@carlosmiceli carlosmiceli added Daily KSv2 and removed Weekly KSv2 labels Dec 9, 2024
Copy link

melvin-bot bot commented Dec 17, 2024

@carlosmiceli, @thesahindia, @Shahidullah-Muffakir Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Dec 19, 2024

@carlosmiceli, @thesahindia, @Shahidullah-Muffakir Huh... This is 4 days overdue. Who can take care of this?

@carlosmiceli
Copy link
Contributor Author

Discussing final details in the PR, specifically best way to set onboardingPolicyID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Daily KSv2 External Added to denote the issue can be worked on by a contributor Improvement Item broken or needs improvement. Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

6 participants