Click here to Skip to main content
15,436,765 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I’m a beginner using Typescript and React. On the UI of the application, there is a defect that does not allow a user to delete their own account when logged in. So like if I was logged in I could delete other accounts created, but not my own. To fix this, in the code shown, I think I need to add a function under “disabled” that checks if the user being selected to delete also belongs to the logged in user. If it does, the disabled should run true. Can someone please help with this and show how to do it?


TypeScript
const deleteAction = {
  children: (
    <TableMenuItem
      data-testid="delete-user-button"
      disabled={
        !hasAnyPermission(
          [
            KnownPermissions.IdentityUsersDeleteAllAccounts,
            KnownPermissions.IdentityUsersDeleteCurrentAccount,
          ],
          permissions
        )
      }
      onClick={() => handleDeleteUser(user)}
      iconId={'delete'}
      label={'Delete'}
    />
  ),
  dataTestId: 'delete-user-button',
  disabled: !hasAnyPermission(
    [
      KnownPermissions.IdentityUsersDeleteAllAccounts,
      KnownPermissions.IdentityUsersDeleteCurrentAccount,
    ],
    permissions
  ),
  iconId: 'delete',
  key: 'delete',
  onclick: () => handleDeleteUser(user),
  tooltip: 'Delete user',
};


What I have tried:

Can someone please help with this and show how to do it?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900