umami/src/app/(main)/settings/websites/WebsitesTable.tsx

70 lines
2 KiB
TypeScript
Raw Normal View History

2024-01-29 02:33:40 +00:00
import { ReactNode } from 'react';
import Link from 'next/link';
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
2024-01-30 08:10:25 +00:00
import { useMessages, useLogin, useNavigation } from 'components/hooks';
2023-01-21 01:12:53 +00:00
2023-12-03 11:07:03 +00:00
export interface WebsitesTableProps {
data: any[];
showActions?: boolean;
allowEdit?: boolean;
allowView?: boolean;
2024-01-29 02:33:40 +00:00
teamId?: string;
2023-12-03 11:07:03 +00:00
children?: ReactNode;
}
2023-10-04 08:46:00 +00:00
export function WebsitesTable({
data = [],
showActions,
2023-10-08 01:55:14 +00:00
allowEdit,
allowView,
2024-01-29 02:33:40 +00:00
teamId,
2023-10-04 08:46:00 +00:00
children,
2023-12-03 11:07:03 +00:00
}: WebsitesTableProps) {
2023-08-25 18:54:44 +00:00
const { formatMessage, labels } = useMessages();
const { user } = useLogin();
const breakpoint = useBreakpoint();
2024-01-30 08:10:25 +00:00
const { renderTeamUrl } = useNavigation();
2023-08-25 18:54:44 +00:00
return (
<GridTable data={data} cardMode={['xs', 'sm', 'md'].includes(breakpoint)}>
<GridColumn name="name" label={formatMessage(labels.name)} />
<GridColumn name="domain" label={formatMessage(labels.domain)} />
2023-10-11 17:02:32 +00:00
{showActions && (
<GridColumn name="action" label=" " alignment="end">
{row => {
const { id, userId } = row;
2023-10-11 17:02:32 +00:00
return (
<>
{allowEdit && !teamId && user.id === userId && (
<Link href={`/settings/websites/${id}`}>
2023-10-11 17:02:32 +00:00
<Button>
<Icon>
<Icons.Edit />
</Icon>
<Text>{formatMessage(labels.edit)}</Text>
</Button>
</Link>
)}
{allowView && (
2024-01-30 08:10:25 +00:00
<Link href={renderTeamUrl(`/websites/${id}`)}>
2023-10-11 17:02:32 +00:00
<Button>
<Icon>
<Icons.External />
</Icon>
<Text>{formatMessage(labels.view)}</Text>
</Button>
</Link>
)}
</>
);
}}
</GridColumn>
)}
2023-10-04 08:46:00 +00:00
{children}
</GridTable>
);
}
2023-04-21 15:00:42 +00:00
export default WebsitesTable;