import { msg } from '@lingui/core/macro'; import { useLingui } from '@lingui/react'; 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', }; /** * DO NOT USE TRANS. YOU MUST USE _ FOR THIS FILE AND ALL CHILDREN COMPONENTS. */ export const InternalAuditLogTable = ({ logs }: AuditLogDataTableProps) => { const { _ } = useLingui(); const parser = new UAParser(); const uppercaseFistLetter = (text: string) => { return text.charAt(0).toUpperCase() + text.slice(1); }; return ( {_(msg`Time`)} {_(msg`User`)} {_(msg`Action`)} {_(msg`IP Address`)} {_(msg`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'}
))}
); };