2023-10-15 04:59:54 +00:00
|
|
|
import { GridColumn, GridTable, Icon, Icons, Text, useBreakpoint } from 'react-basics';
|
2023-07-30 07:11:26 +00:00
|
|
|
import LinkButton from 'components/common/LinkButton';
|
2023-08-21 09:06:09 +00:00
|
|
|
import { useMessages } from 'components/hooks';
|
|
|
|
|
import useUser from 'components/hooks/useUser';
|
2023-09-01 12:25:13 +00:00
|
|
|
import { REPORT_TYPES } from 'lib/constants';
|
2023-10-08 01:55:14 +00:00
|
|
|
import ReportDeleteButton from './ReportDeleteButton';
|
2023-06-15 10:27:41 +00:00
|
|
|
|
2023-10-08 01:55:14 +00:00
|
|
|
export function ReportsTable({ data = [], showDomain }) {
|
2023-06-15 10:27:41 +00:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-08-14 05:32:25 +00:00
|
|
|
const { user } = useUser();
|
2023-10-15 04:59:54 +00:00
|
|
|
const breakpoint = useBreakpoint();
|
2023-06-15 10:27:41 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-10-15 04:59:54 +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="description" label={formatMessage(labels.description)} />
|
|
|
|
|
<GridColumn name="type" label={formatMessage(labels.type)}>
|
2023-07-30 07:11:26 +00:00
|
|
|
{row => {
|
2023-09-27 06:20:29 +00:00
|
|
|
return formatMessage(
|
|
|
|
|
labels[Object.keys(REPORT_TYPES).find(key => REPORT_TYPES[key] === row.type)],
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</GridColumn>
|
|
|
|
|
{showDomain && (
|
|
|
|
|
<GridColumn name="domain" label={formatMessage(labels.domain)}>
|
2023-10-15 09:08:29 +00:00
|
|
|
{row => row?.website?.domain}
|
2023-09-27 06:20:29 +00:00
|
|
|
</GridColumn>
|
|
|
|
|
)}
|
|
|
|
|
<GridColumn name="action" label="" alignment="end">
|
|
|
|
|
{row => {
|
|
|
|
|
const { id, name, userId, website } = row;
|
2023-07-30 07:11:26 +00:00
|
|
|
return (
|
2023-10-01 23:11:12 +00:00
|
|
|
<>
|
2023-09-27 06:20:29 +00:00
|
|
|
{(user.id === userId || user.id === website?.userId) && (
|
2023-10-08 01:55:14 +00:00
|
|
|
<ReportDeleteButton reportId={id} reportName={name} />
|
2023-09-27 06:20:29 +00:00
|
|
|
)}
|
2023-10-08 01:55:14 +00:00
|
|
|
<LinkButton href={`/reports/${id}`}>
|
|
|
|
|
<Icon>
|
|
|
|
|
<Icons.ArrowRight />
|
|
|
|
|
</Icon>
|
|
|
|
|
<Text>{formatMessage(labels.view)}</Text>
|
|
|
|
|
</LinkButton>
|
2023-10-01 23:11:12 +00:00
|
|
|
</>
|
2023-07-30 07:11:26 +00:00
|
|
|
);
|
|
|
|
|
}}
|
2023-09-27 06:20:29 +00:00
|
|
|
</GridColumn>
|
|
|
|
|
</GridTable>
|
2023-06-15 10:27:41 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ReportsTable;
|