-
Notifications
You must be signed in to change notification settings - Fork 7
Prevent self deletion in users page - issue 309 #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/services/users.service.ts
Outdated
|
|
||
| async function remove(ids: (string | number)[]): Promise<boolean> { | ||
|
|
||
| const userString = localStorage.getItem("user"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service is responsible only for sending requests
could you move this into component as validation step?
src/services/users.service.ts
Outdated
| const userString = localStorage.getItem("user"); | ||
| if (userString) { | ||
| const user: User = JSON.parse(userString); | ||
| if (ids.includes(user.id)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current user id could be taken from user.context
| payload: userList.filter((user) => !ids.includes(user.id)), | ||
| }); | ||
| .then((value) => { | ||
| if (value.toString().trim().length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you elaborate why we need this condition?
| payload: userList.filter((user) => !ids.includes(user.id)), | ||
| }); | ||
| } else { | ||
| enqueueSnackbar(`You cannot delete yourself.`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider showing error in case ids contains current user id and not sending request with error or filtering it out from array showing warning that current user id was not taken into request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have kept showing an error in case ids contains the current user id. That way, we are giving immediate feedback by explicitly telling the user to remove the current user. Please let me know what you think.
|
Fixed review comments. |
pashidlos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Addresses Visual-Regression-Tracker/Visual-Regression-Tracker#309