Skip to content

Conversation

@suratdas
Copy link
Collaborator

@suratdas suratdas commented Oct 8, 2021

@suratdas suratdas requested a review from pashidlos October 8, 2021 01:39
@suratdas suratdas changed the title Prevent self deletion in users page Prevent self deletion in users page - issue 309 Oct 8, 2021

async function remove(ids: (string | number)[]): Promise<boolean> {

const userString = localStorage.getItem("user");
Copy link
Member

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?

const userString = localStorage.getItem("user");
if (userString) {
const user: User = JSON.parse(userString);
if (ids.includes(user.id)) {
Copy link
Member

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) {
Copy link
Member

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.`, {
Copy link
Member

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

Copy link
Collaborator Author

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.

@suratdas
Copy link
Collaborator Author

suratdas commented Oct 8, 2021

Fixed review comments.

@suratdas suratdas requested a review from pashidlos October 8, 2021 18:55
Copy link
Member

@pashidlos pashidlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pashidlos pashidlos merged commit bc8db9b into master Oct 13, 2021
@pashidlos pashidlos deleted the prevent-self-deletion branch October 13, 2021 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants