1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00
unleash.unleash/frontend/src/component/admin/users/UsersList/UserListItem/UserListItem.tsx
Youssef Khedher 4f0ef3d761 fix: mobile view (#801)
* fix: mobile view project roles

* fix: mobile view users
2022-03-24 14:04:42 +01:00

109 lines
3.9 KiB
TypeScript

import {
Avatar,
IconButton,
TableCell,
TableRow,
Typography,
} from '@material-ui/core';
import { Delete, Edit, Lock } from '@material-ui/icons';
import { SyntheticEvent, useContext } from 'react';
import { ADMIN } from '../../../../providers/AccessProvider/permissions';
import ConditionallyRender from '../../../../common/ConditionallyRender';
import AccessContext from '../../../../../contexts/AccessContext';
import { IUser } from '../../../../../interfaces/user';
import { useStyles } from './UserListItem.styles';
import { useHistory } from 'react-router-dom';
import { ILocationSettings } from '../../../../../hooks/useLocationSettings';
import { formatDateYMD } from '../../../../../utils/format-date';
interface IUserListItemProps {
user: IUser;
renderRole: (roleId: number) => string;
openPwDialog: (user: IUser) => (e: SyntheticEvent) => void;
openDelDialog: (user: IUser) => (e: SyntheticEvent) => void;
locationSettings: ILocationSettings;
}
const UserListItem = ({
user,
renderRole,
openDelDialog,
openPwDialog,
locationSettings,
}: IUserListItemProps) => {
const { hasAccess } = useContext(AccessContext);
const history = useHistory();
const styles = useStyles();
return (
<TableRow key={user.id} className={styles.tableRow}>
<TableCell className={styles.hideXS}>
<Avatar
data-loading
alt={user.name}
src={user.imageUrl}
title={`${user.name || user.email || user.username} (id: ${
user.id
})`}
/>
</TableCell>
<TableCell className={styles.hideSM}>
<span data-loading>
{formatDateYMD(user.createdAt, locationSettings.locale)}
</span>
</TableCell>
<TableCell className={styles.leftTableCell}>
<Typography variant="body2" data-loading>
{user.name}
</Typography>
</TableCell>
<TableCell className={`${styles.leftTableCell} ${styles.hideSM}`}>
<Typography variant="body2" data-loading>
{user.username || user.email}
</Typography>
</TableCell>
<TableCell align="center" className={styles.hideXS}>
<Typography variant="body2" data-loading>
{renderRole(user.rootRole)}
</Typography>
</TableCell>
<ConditionallyRender
condition={hasAccess(ADMIN)}
show={
<TableCell align="right">
<IconButton
data-loading
aria-label="Edit"
title="Edit"
onClick={() =>
history.push(`/admin/users/${user.id}/edit`)
}
>
<Edit />
</IconButton>
<IconButton
data-loading
aria-label="Change password"
title="Change password"
onClick={openPwDialog(user)}
>
<Lock />
</IconButton>
<IconButton
data-loading
aria-label="Remove user"
title="Remove user"
onClick={openDelDialog(user)}
>
<Delete />
</IconButton>
</TableCell>
}
elseShow={<TableCell />}
/>
</TableRow>
);
};
export default UserListItem;