2023-09-29 12:29:22 +00:00
|
|
|
'use client';
|
2023-10-12 23:13:14 +00:00
|
|
|
import { Button, GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
2024-01-29 02:33:40 +00:00
|
|
|
import Link from 'next/link';
|
2024-01-29 09:32:05 +00:00
|
|
|
import { useMessages, useLogin } from 'components/hooks';
|
2024-01-29 02:33:40 +00:00
|
|
|
import { ROLES } from 'lib/constants';
|
2023-09-29 12:29:22 +00:00
|
|
|
|
2023-12-03 11:07:03 +00:00
|
|
|
export function TeamsTable({ data = [] }: { data: any[] }) {
|
2023-09-29 12:29:22 +00:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2024-01-29 09:32:05 +00:00
|
|
|
const { user } = useLogin();
|
2023-10-12 23:13:14 +00:00
|
|
|
const breakpoint = useBreakpoint();
|
2023-09-29 12:29:22 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-10-12 23:13:14 +00:00
|
|
|
<GridTable data={data} cardMode={['xs', 'sm', 'md'].includes(breakpoint)}>
|
2023-09-29 12:29:22 +00:00
|
|
|
<GridColumn name="name" label={formatMessage(labels.name)} />
|
|
|
|
|
<GridColumn name="owner" label={formatMessage(labels.owner)}>
|
|
|
|
|
{row => row.teamUser.find(({ role }) => role === ROLES.teamOwner)?.user?.username}
|
|
|
|
|
</GridColumn>
|
2024-01-26 07:20:53 +00:00
|
|
|
<GridColumn name="websites" label={formatMessage(labels.websites)}>
|
|
|
|
|
{row => row._count.website}
|
|
|
|
|
</GridColumn>
|
|
|
|
|
<GridColumn name="members" label={formatMessage(labels.members)}>
|
|
|
|
|
{row => row._count.teamUser}
|
|
|
|
|
</GridColumn>
|
2023-09-29 12:29:22 +00:00
|
|
|
<GridColumn name="action" label=" " alignment="end">
|
|
|
|
|
{row => {
|
2024-01-29 02:33:40 +00:00
|
|
|
const { id, teamUser } = row;
|
2023-09-29 12:29:22 +00:00
|
|
|
const owner = teamUser.find(({ role }) => role === ROLES.teamOwner);
|
2023-10-08 05:42:49 +00:00
|
|
|
const isOwner = user.id === owner?.userId;
|
2023-09-29 12:29:22 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-10-01 23:11:12 +00:00
|
|
|
<>
|
2024-01-29 02:33:40 +00:00
|
|
|
{isOwner && (
|
|
|
|
|
<Link href={`/settings/teams/${id}`}>
|
|
|
|
|
<Button>
|
|
|
|
|
<Icon>
|
|
|
|
|
<Icons.Edit />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.edit)}</Text>
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
<Link href={`/teams/${id}`}>
|
2023-09-29 12:29:22 +00:00
|
|
|
<Button>
|
2024-01-29 02:33:40 +00:00
|
|
|
<Icon>
|
|
|
|
|
<Icons.External />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.view)}</Text>
|
2023-09-29 12:29:22 +00:00
|
|
|
</Button>
|
|
|
|
|
</Link>
|
2023-10-01 23:11:12 +00:00
|
|
|
</>
|
2023-09-29 12:29:22 +00:00
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</GridColumn>
|
|
|
|
|
</GridTable>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TeamsTable;
|