64 lines
2.4 KiB
JavaScript
64 lines
2.4 KiB
JavaScript
import { useEffect, useState } from 'react';
|
|
import { Card, CardBody, Container, Table } from 'react-bootstrap';
|
|
import PageBreadcrumb from '@/components/PageBreadcrumb';
|
|
import { api } from '@/lib/api';
|
|
import { showSlashDateTime } from '@/lib/dates';
|
|
|
|
export default function AuditPage() {
|
|
const [items, setItems] = useState([]);
|
|
const [total, setTotal] = useState(0);
|
|
const [page, setPage] = useState(1);
|
|
const [error, setError] = useState('');
|
|
|
|
const load = async () => {
|
|
const data = await api(`/api/audit?page=${page}&limit=25`);
|
|
setItems(data.items || []);
|
|
setTotal(data.total || 0);
|
|
};
|
|
|
|
useEffect(() => {
|
|
load().catch((err) => setError(err.message));
|
|
}, [page]);
|
|
|
|
return (
|
|
<Container fluid>
|
|
<PageBreadcrumb title="Audit log" subtitle="Administration" />
|
|
{error ? <div className="alert alert-danger">{error}</div> : null}
|
|
<Card>
|
|
<CardBody>
|
|
<p className="text-muted">Read-only access events. Patient names and mobiles are never stored here.</p>
|
|
<Table responsive size="sm" className="mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>When</th>
|
|
<th>Actor</th>
|
|
<th>Action</th>
|
|
<th>Resource</th>
|
|
<th>IP</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{items.map((item) => (
|
|
<tr key={item.id}>
|
|
<td className="small">{showSlashDateTime(item.at)}</td>
|
|
<td>{item.actor ? `${item.actor.firstName} ${item.actor.lastName}` : '—'}</td>
|
|
<td>{item.action}</td>
|
|
<td className="small">{[item.resourceType, item.resourceId].filter(Boolean).join(' ')}</td>
|
|
<td className="small">{item.ip || '—'}</td>
|
|
</tr>
|
|
))}
|
|
{!items.length ? <tr><td colSpan={5} className="text-muted">No audit events yet.</td></tr> : null}
|
|
</tbody>
|
|
</Table>
|
|
{total > 25 ? (
|
|
<div className="d-flex gap-2 mt-3">
|
|
<button type="button" className="btn btn-sm btn-light" disabled={page <= 1} onClick={() => setPage((p) => p - 1)}>Previous</button>
|
|
<button type="button" className="btn btn-sm btn-light" disabled={page * 25 >= total} onClick={() => setPage((p) => p + 1)}>Next</button>
|
|
</div>
|
|
) : null}
|
|
</CardBody>
|
|
</Card>
|
|
</Container>
|
|
);
|
|
}
|