[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
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:
- Log in to New Expensify with an account on the free beta
- Click the FAB
- Click on new workspace
- 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
Triggered auto assignment to @Julesssss (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
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();
},
},
] : []),
]}
/>
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.
Triggered auto assignment to @adelekennedy (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@Julesssss, @adelekennedy Huh... This is 4 days overdue. Who can take care of this?
Awaiting proposals (probably after the N6 hold is released)
Created a job in Upwork!
Internal:https://www.upwork.com/ab/applicants/1445523679170768896/job-details External: https://www.upwork.com/jobs/~019a99e91f714c02f7
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.
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.
@Julesssss Any thoughts on this proposal here https://github.com/Expensify/App/issues/5573#issuecomment-936228727
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
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.
Would you mind updating the proposal with the full change?
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
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.
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

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.

Fixed Video: https://user-images.githubusercontent.com/85645967/137926080-719f4346-6ec4-436d-8c03-44fa1af3d64d.mov
@Julesssss updated proposal using ONYXKEY.
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.
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)
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