2022-12-27 01:57:59 +01:00
|
|
|
import {
|
|
|
|
Table,
|
|
|
|
TableHeader,
|
|
|
|
TableBody,
|
|
|
|
TableRow,
|
|
|
|
TableCell,
|
|
|
|
TableColumn,
|
|
|
|
Button,
|
|
|
|
Icon,
|
2023-01-25 16:42:46 +01:00
|
|
|
Icons,
|
|
|
|
Flexbox,
|
|
|
|
Text,
|
2022-12-27 01:57:59 +01:00
|
|
|
} from 'react-basics';
|
2023-01-28 06:53:13 +01:00
|
|
|
import { useIntl } from 'react-intl';
|
2023-01-25 16:42:46 +01:00
|
|
|
import { ROLES } from 'lib/constants';
|
|
|
|
import { labels } from 'components/messages';
|
2023-01-31 06:44:07 +01:00
|
|
|
import useUser from 'hooks/useUser';
|
2023-01-10 08:59:26 +01:00
|
|
|
|
2023-02-02 20:59:38 +01:00
|
|
|
export default function TeamMembersTable({ data = [], readOnly }) {
|
2023-01-25 16:42:46 +01:00
|
|
|
const { formatMessage } = useIntl();
|
2023-01-31 06:44:07 +01:00
|
|
|
const { user } = useUser();
|
2023-01-25 16:42:46 +01:00
|
|
|
|
|
|
|
const columns = [
|
2023-01-31 06:44:07 +01:00
|
|
|
{ name: 'username', label: formatMessage(labels.username), style: { flex: 2 } },
|
|
|
|
{ name: 'role', label: formatMessage(labels.role), style: { flex: 1 } },
|
|
|
|
{ name: 'action', label: '', style: { flex: 1 } },
|
2023-01-25 16:42:46 +01:00
|
|
|
];
|
|
|
|
|
2022-12-27 01:57:59 +01:00
|
|
|
return (
|
2023-01-25 16:42:46 +01:00
|
|
|
<Table columns={columns} rows={data}>
|
2022-12-27 01:57:59 +01:00
|
|
|
<TableHeader>
|
|
|
|
{(column, index) => {
|
|
|
|
return (
|
|
|
|
<TableColumn key={index} style={{ ...column.style }}>
|
|
|
|
{column.label}
|
|
|
|
</TableColumn>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</TableHeader>
|
|
|
|
<TableBody>
|
|
|
|
{(row, keys, rowIndex) => {
|
2023-01-25 16:42:46 +01:00
|
|
|
const rowData = {
|
|
|
|
username: row?.user?.username,
|
|
|
|
role: formatMessage(
|
|
|
|
labels[Object.keys(ROLES).find(key => ROLES[key] === row.role) || labels.unknown],
|
|
|
|
),
|
2023-02-02 20:59:38 +01:00
|
|
|
action: !readOnly && (
|
2023-01-31 06:44:07 +01:00
|
|
|
<Flexbox flex={1} justifyContent="end">
|
2023-02-02 20:59:38 +01:00
|
|
|
<Button disabled={user.id === row?.user?.id || row.role === ROLES.teamOwner}>
|
2023-01-25 16:42:46 +01:00
|
|
|
<Icon>
|
2023-01-28 06:53:13 +01:00
|
|
|
<Icons.Close />
|
2023-01-25 16:42:46 +01:00
|
|
|
</Icon>
|
|
|
|
<Text>{formatMessage(labels.remove)}</Text>
|
|
|
|
</Button>
|
2023-01-31 06:44:07 +01:00
|
|
|
</Flexbox>
|
2023-01-25 16:42:46 +01:00
|
|
|
),
|
|
|
|
};
|
2022-12-27 01:57:59 +01:00
|
|
|
|
|
|
|
return (
|
2023-01-25 16:42:46 +01:00
|
|
|
<TableRow key={rowIndex} data={rowData} keys={keys}>
|
2022-12-27 01:57:59 +01:00
|
|
|
{(data, key, colIndex) => {
|
|
|
|
return (
|
2023-01-25 16:42:46 +01:00
|
|
|
<TableCell key={colIndex} style={{ ...columns[colIndex]?.style }}>
|
2023-01-31 06:44:07 +01:00
|
|
|
<Flexbox flex={1} alignItems="center">
|
2023-01-25 16:42:46 +01:00
|
|
|
{data[key]}
|
|
|
|
</Flexbox>
|
2022-12-27 01:57:59 +01:00
|
|
|
</TableCell>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</TableRow>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
);
|
|
|
|
}
|