2023-07-30 09:11:26 +02:00
|
|
|
import { useState } from 'react';
|
|
|
|
import { Flexbox, Icon, Icons, Text, Button, Modal } from 'react-basics';
|
|
|
|
import LinkButton from 'components/common/LinkButton';
|
2023-06-15 12:27:41 +02:00
|
|
|
import SettingsTable from 'components/common/SettingsTable';
|
2023-07-30 09:11:26 +02:00
|
|
|
import ConfirmDeleteForm from 'components/common/ConfirmDeleteForm';
|
|
|
|
import { useMessages } from 'hooks';
|
2023-06-15 12:27:41 +02:00
|
|
|
|
2023-07-30 09:11:26 +02:00
|
|
|
export function ReportsTable({ data = [], onDelete = () => {} }) {
|
|
|
|
const [report, setReport] = useState(null);
|
2023-06-15 12:27:41 +02:00
|
|
|
const { formatMessage, labels } = useMessages();
|
|
|
|
|
|
|
|
const columns = [
|
|
|
|
{ name: 'name', label: formatMessage(labels.name) },
|
|
|
|
{ name: 'description', label: formatMessage(labels.description) },
|
2023-06-23 10:19:08 +02:00
|
|
|
{ name: 'type', label: formatMessage(labels.type) },
|
2023-06-15 12:27:41 +02:00
|
|
|
{ name: 'action', label: ' ' },
|
|
|
|
];
|
|
|
|
|
2023-07-30 09:11:26 +02:00
|
|
|
const handleConfirm = () => {
|
|
|
|
onDelete(report.id);
|
|
|
|
};
|
|
|
|
|
2023-06-15 12:27:41 +02:00
|
|
|
return (
|
2023-07-30 09:11:26 +02:00
|
|
|
<>
|
|
|
|
<SettingsTable columns={columns} data={data}>
|
|
|
|
{row => {
|
|
|
|
const { id } = row;
|
2023-06-15 12:27:41 +02:00
|
|
|
|
2023-07-30 09:11:26 +02:00
|
|
|
return (
|
|
|
|
<Flexbox gap={10}>
|
|
|
|
<LinkButton href={`/reports/${id}`}>{formatMessage(labels.view)}</LinkButton>
|
|
|
|
<Button onClick={() => setReport(row)}>
|
|
|
|
<Icon>
|
|
|
|
<Icons.Trash />
|
|
|
|
</Icon>
|
|
|
|
<Text>{formatMessage(labels.delete)}</Text>
|
|
|
|
</Button>
|
|
|
|
</Flexbox>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</SettingsTable>
|
|
|
|
{report && (
|
|
|
|
<Modal>
|
|
|
|
<ConfirmDeleteForm
|
|
|
|
name={report.name}
|
|
|
|
onConfirm={handleConfirm}
|
|
|
|
onClose={() => setReport(null)}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
)}
|
|
|
|
</>
|
2023-06-15 12:27:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReportsTable;
|