Rick Baker
Rick Baker

Reputation: 903

Cannot get react-admin permission checks to work in List Actions

Wanting to show a custom button at the top of the page only if the user is an admin. This works for showing/hiding certain fields on the same page. But for some reason I cannot get it to work within List Actions.

Code:

const UserListActions = ({ permissions, ...props }) => (  
  <CardActions> . 
      <RefreshButton />  
      {permissions === 'admin' &&   
        <Button color="primary"> . 
          <SyncIcon /> Sync Users . 
        </Button> . 
      } . 
  </CardActions> . 
);

export const UserList = ({ permissions, ...props }) => (
  <List actions={<UserListActions />} title="All users" {...props} bulkActions={false}>

Upvotes: 2

Views: 694

Answers (1)

Rick Baker
Rick Baker

Reputation: 903

Figured this out. I was missing a key piece in passing permissions into the actions property of the List

const RoleListActions = ({ basePath, permissions }) => (
  <CardActions>
    {permissions === 'admin' && <SyncAwsRolesButton color="primary" />}
    {permissions === 'admin' && <CreateButton basePath={basePath} />}
    <RefreshButton />
  </CardActions>
);

export const RoleList = ({ permissions, ...props }) => (
  <List title="All roles" actions={<RoleListActions permissions={permissions} />} {...props} bulkActions={false}>
                                                    ^^ This bit right here

Upvotes: 2

Related Questions