App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD OFFLINE] [$250] Workspace - Same user is added multiple times when tapping invite member CTA multiple times in offline

Open kavimuru opened this issue 4 years ago • 71 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:

Precondition: Kill the internet connection

  1. Navigate to the Workspace editor
  2. Navigate back to the Manage members page
  3. Click on invite and enter a user address (you can access to)
  4. Select the member and click on invite
  5. Tap the invite button multiple times
  6. Tap on back button and check added user

Expected Result:

User should be added only 1 time.

Actual Result:

Able to add same user many times when offline. And then selecting one member selects all the members with same name and email

Workaround:

Unknown

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: v1.1.19-0 Reproducible in staging?: Yes Reproducible in production?: Yes Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: ![Bug5366090_Screen_Shot_2021-12-09_at_12 33 58_PM](https://user-images.githubusercontent.com/43996225/145459931-702708f8-84

https://user-images.githubusercontent.com/43996225/145459963-e6699ae4-3c3b-4c04-9b43-2e4f0cf52e4f.mp4

https://user-images.githubusercontent.com/43996225/145459951-0624aedb-8941-4f3e-afd6-690298484e52.mp4

b7-4141-a474-93ebf7b93fed.png)

Expensify/Expensify Issue URL: Issue reported by: Applause Slack conversation: Upwork URL: https://www.upwork.com/jobs/~01d54d4c2a0f4e6417

View all open jobs on GitHub

kavimuru avatar Dec 09 '21 19:12 kavimuru

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

MelvinBot avatar Dec 09 '21 19:12 MelvinBot

@parasharrajat Is this one also related to our offline issues? Not sure if we should leave this one open if the fix will be the same.

pecanoro avatar Dec 09 '21 22:12 pecanoro

@pecanoro I think we can prevent the duplicates without too hassle here. According to the way this component is configured, it should filter exisitng members from the invite list. So when add a new user Policy data trigger a prop update to this component but we are not handling prop changes. Even if user is online, He can click the button multiple times and then duplicate entries will be created but After APi call is successful, we remove all the duplicate entries so It is not visible to the user when online.

In case of offline, API call is never completed thus it is apparant. I think it is still necessary to rerender the component when members in the policy are added so that already added user will be removed from the UI.

The End effect would be that When user presses the Invite button. the user from the list will vanish. If we talk about the video, the only searched user will be remvoed from the search results as soon as it is added to the policy. I think it does not harm in any way.

but Again the fact that invited users are added to the list on the device but not on the backend while offline comes under the offline issues you mentioned Which is not part of this issue anyway.

parasharrajat avatar Dec 10 '21 11:12 parasharrajat

Cool, thanks for the insight, so many offline issues lately that I am getting all of them mixed up! I am going to add the external label then!

pecanoro avatar Dec 10 '21 15:12 pecanoro

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

MelvinBot avatar Dec 10 '21 15:12 MelvinBot

@pecanoro but I am not able to determine what should be done in this issue. What would be the expected behaviour here?

When the user has selected a contact. Should it be removed when added to the policy? or Should we show the loader on the button when an invite call is made?

I think we should first set clear expectations before moving it to external.

parasharrajat avatar Dec 10 '21 16:12 parasharrajat

I am not sure if I am following. If we try to add the same user a second time, we should simply not allow the user to do it, right? Or maybe we should simply not allow inviting member when we are offline.

pecanoro avatar Dec 13 '21 16:12 pecanoro

Aha, got you. I was saying that should we remove that user from the list. For example, you searched for a user and select one, and press invite. Then remove that user from the list. To continue will be disabled automatically. But it may not resolve the issue completely. user can press quickly to add the same user again.

But you are saying to just filter the invited users before adding them so that duplicates are not added. In that case, it would make more sense to show the error for the duplicate users.

parasharrajat avatar Dec 13 '21 16:12 parasharrajat

@trjExpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

MelvinBot avatar Dec 13 '21 19:12 MelvinBot

Sorry guys, I'm a tad unclear on the next steps here?

trjExpensify avatar Dec 14 '21 17:12 trjExpensify

@trjExpensify Export the issue, we can discuss it in the meantime.

@parasharrajat Oh I see, we should remove the user from the list then after being invited, right? I think that would be the best option.

pecanoro avatar Dec 14 '21 17:12 pecanoro

Triggered auto assignment to @parasharrajat (Exported)

MelvinBot avatar Dec 14 '21 23:12 MelvinBot

Triggered auto assignment to @NikkiWines (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Dec 14 '21 23:12 MelvinBot

@trjExpensify Export the issue, we can discuss it in the meantime.

Done, here: https://www.upwork.com/jobs/~01d54d4c2a0f4e6417

trjExpensify avatar Dec 14 '21 23:12 trjExpensify

@pecanoro Yup, I think the same as well. but It is possible that user can click the button multiple times before the list is updated in UI. So we will still need the validation check.

so action Items.

  1. Add validation.
  2. remove the user from the List.

parasharrajat avatar Dec 15 '21 13:12 parasharrajat

I think we should consider the duplicated items of employeeList in Policy#invite instead of just simply concat the employeeList.

https://github.com/Expensify/App/blob/893762107a3691a79256db064181a369f3c50384/src/libs/actions/Policy.js#L287-L294

Both WorkspaceMembersPage and WorkspaceInvitePage depend on the "correct" employeeList.

https://github.com/Expensify/App/blob/893762107a3691a79256db064181a369f3c50384/src/pages/workspace/WorkspaceInvitePage.js#L92-L95

https://github.com/Expensify/App/blob/893762107a3691a79256db064181a369f3c50384/src/pages/workspace/WorkspaceMembersPage.js#L246-L252

Proposal

- policy.employeeList = [...policy.employeeList, ...newEmployeeList];
+ policy.employeeList = _.uniq([...policy.employeeList, ...newEmployeeList], employee => employee.login);

Uniq the employeeList is not only make sense for the UI rendering, but also makes the API parameters more reasonable.

Limitation:

  1. This implementation may have a performance issue since _.uniq is an O(n^2) operation.
  2. It still results in multiple times API call when the user clicks the Invite button quickly.

songlang1994 avatar Dec 15 '21 14:12 songlang1994

Thanks for the proposal @songlang1994 . Based on this. 1 Your proposal satisfies first. We don't need to worry about the complexity here. I don't think a group will ever have thousands of users. 2. Can you think about the second too?

parasharrajat avatar Dec 15 '21 14:12 parasharrajat

@parasharrajat Policy#invite itself is not easy to do this kind of restriction. However, we can handle it from its caller. Like:

https://github.com/Expensify/App/blob/893762107a3691a79256db064181a369f3c50384/src/pages/workspace/WorkspaceInvitePage.js#L61-L65

- this.inviteUser = this.inviteUser.bind(this);
+ this.inviteUser = _.debounce(this.inviteUser.bind(this), 1000, true)
}

songlang1994 avatar Dec 15 '21 15:12 songlang1994

I think this is not what we want. We want the selected user to be removed from the list when it is added to the policy. let me know if you have any questions.

parasharrajat avatar Dec 15 '21 15:12 parasharrajat

proposal

Summary:

My proposal is to keep the UX similar to when the App is online. After clicking Invite on WorkspaceInvitePage, App will immediately goback to WorkspaceMembersPage. App will diplay additional info on member row with unfinished invite request, something similar to :

Example:

The text could be Sending invitation, waiting for connection...

addtional_info or addtional_info_2


Details:

The App needs additional field on already exists onyx policy data. Additional field could be called unfinishedInviteRequest that contains emails of unfinished invite API request.

Adtional field details: The data could be set before this onyx merge in `Policy.invite` function:

https://github.com/Expensify/App/blob/149ed21c36839a53ab4ce16c4b5b505ef792a2e6/src/libs/actions/Policy.js#L300

And on then clause

https://github.com/Expensify/App/blob/149ed21c36839a53ab4ce16c4b5b505ef792a2e6/src/libs/actions/Policy.js#L308

App will remove unfinishedInviteRequest emails when API request is successful. On offline state, the unfinishedInviteRequest will remains and member page will display info similar to image above.

When reconnecting / back to online: On accessing WorkspaceMemberPage again, loadFullPolicy should already update policy data and unfinishedInviteRequest. I think this function should be called each time WorkspaceInitialPage didMounted, to sync policy data between server and local data.


##### prevent double click on invite button (prevent multiple invitation API request and duplicate member displayed in member user list (for online and offline)):

By adding a property to WorkspaceInvitePage for example: isSubmitActive with default to true and check this property in this function:

https://github.com/Expensify/App/blob/149ed21c36839a53ab4ce16c4b5b505ef792a2e6/src/pages/workspace/WorkspaceInvitePage.js#L211

setting the isSubmitActive to false after isSubmitActive check.

K4tsuki avatar Dec 28 '21 15:12 K4tsuki