'use client' import { useState } from 'react' import { coerceToString } from '@/helpers' import type { PaginationListColumnType } from '@/types' import useDisclosure from '@/hooks/useDisclosure' import PaginatedList from '@/components/PaginatedList' import PageNavbar from '@/components/layouts/PageNavbar' import Button from '@/components/formElements/Button' import Modal from '@/components/modals/Modal' import AdminTableViewButton from '@/components/ui/AdminTableViewButton' import StatusChip from '@/components/ui/StatusChip' import { APP_ROUTES } from '@/constants/routes' import { AUDIT_LOG_METHOD_FILTER_ITEMS, getAuditLogMethod, getHttpStatusCode } from '@/constants/status' import { formatIranianMobile, formatPersianDate, truncateValue } from '@/lib/formatters' import { API_ROUTES } from '@/services/config' interface AuditLogRow { id: string adminUserId?: string | null adminMobile?: string | null method: string path: string params: Record statusCode: number createdAt: string } // Read-only admin activity trail — GET /admin/audit-logs only supports // filtering by adminUserId/method/path and sorting by createdAt (see // backend/src/modules/admin-audit-logs/admin-audit-logs.service.ts, // ALLOWED_FILTER_KEYS / ALLOWED_SORT_FIELDS). Columns that aren't // whitelisted there (params, statusCode) are shown but // not marked filterable/sortable, so the UI never implies a capability // the API doesn't have. const columns: PaginationListColumnType[] = [ { field: 'adminUserId', label: 'ادمین', filterable: true, sortable: false, type: 'text', }, { field: 'method', label: 'متد', filterable: true, sortable: false, type: 'select', filterItems: AUDIT_LOG_METHOD_FILTER_ITEMS, }, { field: 'path', label: 'مسیر', filterable: true, type: 'text', sortable: false, }, { field: 'params', label: 'پارامترها', filterable: false, sortable: false, }, { field: 'statusCode', label: 'کد وضعیت', filterable: false, sortable: false, }, { field: 'createdAt', label: 'زمان', filterable: false, sortable: true, }, { field: 'actions', label: 'عملیات', }, ] const AuditLogsPage = () => { const { isOpen, onOpenChange, onOpen } = useDisclosure() const [activeParams, setActiveParams] = useState | null>(null) const openParamsModal = (params: Record) => { setActiveParams(params) onOpen() } return (
{{ adminUserId: (row) => { const log = row as unknown as AuditLogRow if (!log.adminUserId) { return } return log.adminMobile ? ( {formatIranianMobile(log.adminMobile)} ) : ( ادمین ) }, method: (_row, cellValue) => , path: (_row, cellValue) => ( {coerceToString(cellValue, '—')} ), params: (row) => { const log = row as unknown as AuditLogRow const serialized = JSON.stringify(log.params ?? {}) if (!log.params || Object.keys(log.params).length === 0) { return } return (
{truncateValue(serialized)} {serialized.length > 80 && ( )}
) }, statusCode: (_row, cellValue) => , createdAt: (_row, cellValue) => formatPersianDate(cellValue), actions: (row) => { const log = row as unknown as AuditLogRow if (!log.adminUserId) { return } return ( ) }, }}
          {JSON.stringify(activeParams, null, 2)}
        
) } export default AuditLogsPage