49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { redirect } from 'next/navigation'
|
|
import { calcPagination, parseListParams } from '@/lib/admin-helpers'
|
|
import { canAccess, getAdminContext, PERMS } from '@/lib/permissions'
|
|
import { getAuditLogs } from '@/lib/services/audit'
|
|
import { AuditTable } from './audit-table'
|
|
|
|
export default async function AuditLogsPage({
|
|
params: paramsPromise,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ locale: string }>
|
|
searchParams: Promise<Record<string, string>>
|
|
}) {
|
|
await paramsPromise
|
|
const { session, permissions } = await getAdminContext()
|
|
if (!canAccess(permissions, PERMS.LOGS_VIEW, session.user.rank)) {
|
|
redirect('/admin')
|
|
}
|
|
|
|
const params = await searchParams
|
|
const sp = new URLSearchParams(params)
|
|
const { search, perPage, page } = parseListParams(sp)
|
|
|
|
const result = await getAuditLogs({ search, page, perPage })
|
|
|
|
const pagination = calcPagination(result.total, result.page, result.perPage)
|
|
|
|
const rows = result.rows.map((r) => ({
|
|
id: r.id,
|
|
username: r.username,
|
|
action: r.action,
|
|
target: r.target,
|
|
targetId: r.targetId,
|
|
diff: r.diff,
|
|
createdAt: r.createdAt,
|
|
}))
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<div>
|
|
<h1 className="text-3xl font-bold tracking-tight">Audit Logs</h1>
|
|
<p className="text-muted-foreground">Track admin actions and changes</p>
|
|
</div>
|
|
|
|
<AuditTable data={{ rows, ...pagination }} />
|
|
</div>
|
|
)
|
|
}
|