'use client'; import { DateTime } from 'luxon'; import type { DateTimeFormatOptions } from 'luxon'; import { UAParser } from 'ua-parser-js'; import { APP_I18N_OPTIONS } from '@documenso/lib/constants/i18n'; import type { TDocumentAuditLog } from '@documenso/lib/types/document-audit-logs'; import { formatDocumentAuditLogAction } from '@documenso/lib/utils/document-audit-logs'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@documenso/ui/primitives/table'; export type AuditLogDataTableProps = { logs: TDocumentAuditLog[]; }; const dateFormat: DateTimeFormatOptions = { ...DateTime.DATETIME_SHORT, hourCycle: 'h12', }; export const AuditLogDataTable = ({ logs }: AuditLogDataTableProps) => { const parser = new UAParser(); const uppercaseFistLetter = (text: string) => { return text.charAt(0).toUpperCase() + text.slice(1); }; return ( Time User Action IP Address Browser {logs.map((log, i) => ( {DateTime.fromJSDate(log.createdAt) .setLocale(APP_I18N_OPTIONS.defaultLocale) .toLocaleString(dateFormat)} {log.name || log.email ? (
{log.name && (

{log.name}

)} {log.email && (

{log.email}

)}
) : (

N/A

)}
{uppercaseFistLetter(formatDocumentAuditLogAction(log).description)} {log.ipAddress} {log.userAgent ? parser.setUA(log.userAgent).getBrowser().name : 'N/A'}
))}
); };