[HOLD OFFLINE] [$250] Workspace - Same user is added multiple times when tapping invite member CTA multiple times in offline
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
- Navigate to the Workspace editor
- Navigate back to the Manage members page
- Click on invite and enter a user address (you can access to)
- Select the member and click on invite
- Tap the invite button multiple times
- 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: 
Expensify/Expensify Issue URL: Issue reported by: Applause Slack conversation: Upwork URL: https://www.upwork.com/jobs/~01d54d4c2a0f4e6417
Triggered auto assignment to @pecanoro (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
@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 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.
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!
Triggered auto assignment to @trjExpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@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.
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.
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.
@trjExpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Sorry guys, I'm a tad unclear on the next steps here?
@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.
Triggered auto assignment to @parasharrajat (Exported)
Triggered auto assignment to @NikkiWines (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
@trjExpensify Export the issue, we can discuss it in the meantime.
Done, here: https://www.upwork.com/jobs/~01d54d4c2a0f4e6417
@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.
- Add validation.
- remove the user from the List.
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:
- This implementation may have a performance issue since
_.uniqis an O(n^2) operation. - It still results in multiple times API call when the user clicks the Invite button quickly.
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 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)
}
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.
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...
or

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.