Reputation: 903
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
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