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

71 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-29 02:33:40 +00:00
import { useMessages } from 'components/hooks';
import { useUser } 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 } = useUser();
const breakpoint = useBreakpoint();
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 => {
2024-01-29 02:33:40 +00:00
const { id } = row;
const isOwner = row.userId === user.id || row.teamId === teamId;
2023-10-11 17:02:32 +00:00
return (
<>
2024-01-29 02:33:40 +00:00
{allowEdit && isOwner && (
<Link href={`/settings/${id}`}>
2023-10-11 17:02:32 +00:00
<Button>
<Icon>
<Icons.Edit />
</Icon>
<Text>{formatMessage(labels.edit)}</Text>
</Button>
</Link>
)}
{allowView && (
2024-01-29 02:33:40 +00:00
<Link href={teamId ? `/team/${teamId}/websites/${id}` : `/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;