Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useEffect, useState } from "react";
import { api, handleError } from "../../lib/utils";
import {
Table,
TableBody,
TableCell,
TableColumn,
TableHeader,
TableRow,
} from "@nextui-org/react";
type AuditLogAction = "BAN_CREATE" | "BAN_UPDATE" | "BAN_DELETE";
type AuditLog = {
id: number;
userId: string;
action: AuditLogAction;
reason?: string;
comment?: string;
banId?: number;
createdAt: string;
updatedAt?: string;
};
export const AuditLog = () => {
const [auditLogs, setAuditLogs] = useState<AuditLog[]>([]);
useEffect(() => {
api<{ auditLogs: AuditLog[] }>("/api/admin/audit", "GET").then(
({ status, data }) => {
if (status === 200) {
if (data.success) {
setAuditLogs(data.auditLogs);
} else {
handleError(status, data);
}
} else {
handleError(status, data);
}
}
);
}, []);
return (
<>
<h4 className="text-l font-semibold">Audit Log</h4>
<div className="relative">
<Table>
<TableHeader>
<TableColumn>ID</TableColumn>
<TableColumn>User ID</TableColumn>
<TableColumn>Action</TableColumn>
<TableColumn>Reason</TableColumn>
<TableColumn>Comment</TableColumn>
<TableColumn>Created At / Updated At</TableColumn>
</TableHeader>
<TableBody>
{auditLogs.map((log) => (
<TableRow key={log.id}>
<TableCell>{log.id}</TableCell>
<TableCell>{log.userId}</TableCell>
<TableCell>{log.action}</TableCell>
<TableCell>{log.reason}</TableCell>
<TableCell>{log.comment}</TableCell>
<TableCell>
{log.createdAt} / {log.updatedAt}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</>
);
};