2023-12-06 03:22:14 +00:00
|
|
|
import { ReactNode, useContext } from 'react';
|
2022-12-27 00:57:59 +00:00
|
|
|
import Link from 'next/link';
|
2023-10-12 23:13:14 +00:00
|
|
|
import { Button, Text, Icon, Icons, GridTable, GridColumn, useBreakpoint } from 'react-basics';
|
2023-08-21 09:06:09 +00:00
|
|
|
import useMessages from 'components/hooks/useMessages';
|
|
|
|
|
import useUser from 'components/hooks/useUser';
|
2023-12-06 03:22:14 +00:00
|
|
|
import SettingsContext from '../SettingsContext';
|
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;
|
|
|
|
|
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,
|
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();
|
2023-10-12 23:13:14 +00:00
|
|
|
const breakpoint = useBreakpoint();
|
2023-12-13 05:23:12 +00:00
|
|
|
const { settingsPath, websitesPath } = useContext(SettingsContext);
|
2023-08-25 18:54:44 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-10-12 23:13:14 +00:00
|
|
|
<GridTable data={data} cardMode={['xs', 'sm', 'md'].includes(breakpoint)}>
|
2023-09-27 06:20:29 +00:00
|
|
|
<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,
|
|
|
|
|
user: { id: ownerId },
|
|
|
|
|
} = row;
|
2023-09-27 06:20:29 +00:00
|
|
|
|
2023-10-11 17:02:32 +00:00
|
|
|
return (
|
|
|
|
|
<>
|
2024-01-19 00:46:40 +00:00
|
|
|
{allowEdit && ownerId === user.id && (
|
2023-12-13 05:23:12 +00:00
|
|
|
<Link href={`${settingsPath}/${id}`}>
|
2023-10-11 17:02:32 +00:00
|
|
|
<Button>
|
|
|
|
|
<Icon>
|
|
|
|
|
<Icons.Edit />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.edit)}</Text>
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
{allowView && (
|
2023-12-13 05:23:12 +00:00
|
|
|
<Link href={`${websitesPath}/${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}
|
2023-09-27 06:20:29 +00:00
|
|
|
</GridTable>
|
2022-12-27 00:57:59 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default WebsitesTable;
|