Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
3.59k stars 2.92k forks source link

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

Open carlosmiceli opened 3 days ago

carlosmiceli commented 3 days ago

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:

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:

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
melvin-bot[bot] commented 3 days ago

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

melvin-bot[bot] commented 3 days ago

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

nkdengineer commented 3 days ago

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,
);

https://github.com/Expensify/App/blob/f12b73c3aff5fea8cb8d41f111d52d5bfd187eb1/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx#L158

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 commented 3 days ago

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. https://github.com/Expensify/App/blob/f12b73c3aff5fea8cb8d41f111d52d5bfd187eb1/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx#L61-L73

  2. if signupQualifier is SMB, it is not considered anywhere in code to skip the workspace creation, workspace is created in any case here. https://github.com/Expensify/App/blob/f12b73c3aff5fea8cb8d41f111d52d5bfd187eb1/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx#L66-L70

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

  3. remove this useEffect, because it is used to create a workspace if signupQualifier is VSB https://github.com/Expensify/App/blob/f12b73c3aff5fea8cb8d41f111d52d5bfd187eb1/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx#L61-L73

  4. 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; https://github.com/Expensify/App/blob/f12b73c3aff5fea8cb8d41f111d52d5bfd187eb1/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx#L66-L70

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 commented 1 hour ago

@thesahindia any thoughts on which proposal to go with?