Fix User delete button not showing

This commit is contained in:
Deluan 2021-05-02 15:03:15 -04:00
parent b8138ebad6
commit ad153f5f63

View file

@ -29,10 +29,10 @@ const UserTitle = ({ record }) => {
return <Title subTitle={`${resourceName} ${record ? record.name : ''}`} /> return <Title subTitle={`${resourceName} ${record ? record.name : ''}`} />
} }
const UserToolbar = (props) => ( const UserToolbar = ({ showDelete, ...props }) => (
<Toolbar {...props} classes={useStyles()}> <Toolbar {...props} classes={useStyles()}>
<SaveButton disabled={props.pristine} /> <SaveButton disabled={props.pristine} />
{props.permissions === 'admin' && <DeleteUserButton />} {showDelete && <DeleteUserButton />}
</Toolbar> </Toolbar>
) )
@ -40,16 +40,18 @@ const UserEdit = (props) => {
const { permissions } = props const { permissions } = props
const translate = useTranslate() const translate = useTranslate()
const isMyself = props.id === localStorage.getItem('userId')
const getNameHelperText = () => const getNameHelperText = () =>
props.id === localStorage.getItem('userId') && { isMyself && {
helperText: translate('resources.user.helperTexts.name'), helperText: translate('resources.user.helperTexts.name'),
} }
const canDelete = permissions === 'admin' && !isMyself
return ( return (
<Edit title={<UserTitle />} {...props}> <Edit title={<UserTitle />} {...props}>
<SimpleForm <SimpleForm
variant={'outlined'} variant={'outlined'}
toolbar={<UserToolbar />} toolbar={<UserToolbar showDelete={canDelete} />}
redirect={permissions === 'admin' ? 'list' : false} redirect={permissions === 'admin' ? 'list' : false}
> >
{permissions === 'admin' && ( {permissions === 'admin' && (