App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-12-06] [Pay on 23rd Nov] User is able to create a second workspace while the first one is being created

Open isagoico opened this issue 5 years ago • 50 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Log in to New Expensify with an account on the free beta
  2. Click the FAB
  3. Click on new workspace
  4. QUICKLY click on the FAB again and in the new workspace button

Expected Result:

User should be limited to 1 Workspace creation

Actual Result:

User is able to create 2 workspaces before the "create new workspace" button is removed.

Workaround:

None needed.

Platform:

Where is this issue occurring?

  • Web

Version Number: 1.1.2-0

Reproducible in staging?: yes Reproducible in production?: yes

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

https://user-images.githubusercontent.com/44479856/135170142-2a231f1b-ffbd-4bb1-8851-59575c9d8cbf.mp4

Expensify/Expensify Issue URL:

Issue reported by: @Hanaffi Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1632765381137200

View all open jobs on GitHub

isagoico avatar Sep 28 '21 21:09 isagoico

Triggered auto assignment to @Julesssss (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Sep 28 '21 21:09 MelvinBot

Proposal

After investigating for a while, This issue happens because the policy creation request wasn't done yet. Whether the internet is slow or the client is offline. To solve this issue we have to disable the button once its clicked.


 constructor(props) {
        this.state = {
            newWorkSpaceButtonClicked:false // NEW
        };
    }

// rest of code
<PopoverMenu
// rest of code
  ...(Permissions.canUseFreePlan(this.props.betas) && !isAdminOfFreePolicy(this.props.allPolicies) && !this.state.newWorkSpaceButtonClicked? [ // NEW
    {
        icon: NewWorkspace,
        iconWidth: 46,
        iconHeight: 40,
        text: this.props.translate('workspace.new.newWorkspace'),
        description: this.props.translate('workspace.new.getTheExpensifyCardAndMore'),
        onSelected: () => {
            this.setState({newWorkSpaceButtonClicked:true}); // NEW
            return create();
        },
    },
] : []),
]}
/>

Hanaffi avatar Sep 28 '21 22:09 Hanaffi

Hi @Hanaffi, thanks for the proposal.

Ideally, the state should be controlled by an Onyx key, rather than state that is tied to the lifecycle of this component. Something like this. Notice that we are setting the state of the button via an Onyx key.

Julesssss avatar Sep 29 '21 17:09 Julesssss

Triggered auto assignment to @adelekennedy (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Oct 04 '21 07:10 MelvinBot

@Julesssss, @adelekennedy Huh... This is 4 days overdue. Who can take care of this?

MelvinBot avatar Oct 04 '21 19:10 MelvinBot

Awaiting proposals (probably after the N6 hold is released)

Julesssss avatar Oct 05 '21 07:10 Julesssss

Created a job in Upwork!

Internal:https://www.upwork.com/ab/applicants/1445523679170768896/job-details External: https://www.upwork.com/jobs/~019a99e91f714c02f7

adelekennedy avatar Oct 05 '21 22:10 adelekennedy

Proposal

@Julesssss In here https://github.com/Expensify/App/blob/04083b154f5171b125fd92a8223e2863db799973/src/pages/home/sidebar/SidebarScreen.js#L185-L190

Instead of directly calling create method in Policy, we can navigate to route ROUTES.WORKSPACE_NEW. Like below

onSelected: () => Navigation.navigate(ROUTES.WORKSPACE_NEW),

We can avoid this issue, and IMO this makes more sense because we already show a loading indicator, once created we will navigate to the workspace.

Santhosh-Sellavel avatar Oct 06 '21 13:10 Santhosh-Sellavel

Please refer to this post for updated information on the n6 hold, we've raised the bonus to $250 for all issues where a PR is created before the N6 hold is lifted.

kadiealexander avatar Oct 08 '21 01:10 kadiealexander

@Julesssss Any thoughts on this proposal here https://github.com/Expensify/App/issues/5573#issuecomment-936228727

Santhosh-Sellavel avatar Oct 15 '21 09:10 Santhosh-Sellavel

Hi @Santhosh-Sellavel, thanks for the bump. I think your solution missing an additional step? No API call is triggered in this case, so at what point would we create the Policy/Workspace?

Julesssss avatar Oct 15 '21 11:10 Julesssss

@Julesssss Sorry for that, when I Proposed there was a WorkspaceNew page that would call create policy https://github.com/Expensify/App/blob/04083b154f5171b125fd92a8223e2863db799973/src/pages/workspace/WorkspaceNew.js#L6-L10

Seems it's removed now. Now we can show a loading page, once create option is clicked.

Santhosh-Sellavel avatar Oct 15 '21 11:10 Santhosh-Sellavel

Would you mind updating the proposal with the full change?

Julesssss avatar Oct 18 '21 13:10 Julesssss

Proposal.

We can call navigate to workspace/new from this below function, https://github.com/Expensify/App/blob/c23c8be432a9a7d741cac3ff6b421fba31dc4117/src/libs/actions/Policy.js#L105-L107

Like shown below.

function create(name = '', shouldAutomaticallyReroute = true) {
    Navigation.navigate(ROUTES.WORKSPACE_NEW);
    let res = null;
    return API.Policy_Create({type: CONST.POLICY.TYPE.FREE, policyName: name})

OR We should just call From here along with the create() call. https://github.com/Expensify/App/blob/c23c8be432a9a7d741cac3ff6b421fba31dc4117/src/pages/home/sidebar/SidebarScreen.js#L193

The result would be like this.

https://user-images.githubusercontent.com/85645967/137784667-17c59871-868a-4962-957d-dc4e367096a8.mov

Santhosh-Sellavel avatar Oct 18 '21 18:10 Santhosh-Sellavel

Thanks for sharing the full solution. Having the temporary loading page is not ideal in my opinion.

Unless we can come up with a simple solution that doesn't change the current UX, I think we should match existing logic which would depend on an Onyx key for managing the 'New Workspace menu option' state.

Julesssss avatar Oct 19 '21 13:10 Julesssss

Proposal

@Julesssss In ONYXKEYS.js, add a new key IS_CREATING_WORKSPACE.

// Set when workspace is created
IS_CREATING_WORKSPACE: 'isCreatingWorkspace',

Set those states as shown below Screenshot 2021-10-19 at 8 43 40 PM

In SidebarScreen.js add a new prop isCreatingWorkspace and read it from onyx using the IS_CREATING_WORKSPACE key.

Use it check along with other conditions as shown below. Screenshot 2021-10-19 at 7 24 40 PM

Fixed Video: https://user-images.githubusercontent.com/85645967/137926080-719f4346-6ec4-436d-8c03-44fa1af3d64d.mov

Santhosh-Sellavel avatar Oct 19 '21 13:10 Santhosh-Sellavel

@Julesssss updated proposal using ONYXKEY.

Santhosh-Sellavel avatar Oct 19 '21 14:10 Santhosh-Sellavel

For this specific task, I think creating an Onyx prop is not much useful. It's just one link totally frontend so I think having a boolean check in the state would be best.

parasharrajat avatar Oct 19 '21 14:10 parasharrajat

It's just one link totally frontend so I think having a boolean check in the state would be best.

Yeah, I agree with you. Seems like we're back to this original proposal.

EDIT: I forgot to add that I still have the concern that this would fail in certain cases. A proposal would need to handle the edge cases (mentioned above by Santhosh)

Julesssss avatar Oct 19 '21 14:10 Julesssss

I still think it would be better to use an onyx prop here. In case of any failure, it would be easier & the best way to manage the state of the button using Onyx Prop.

cc: @Julesssss

Santhosh-Sellavel avatar Oct 19 '21 16:10 Santhosh-Sellavel