From 0b03bd3fcebdbdd7f5df4ddfe7c61afe92b70cf4 Mon Sep 17 00:00:00 2001 From: Catalin Pit Date: Thu, 3 Jul 2025 13:07:07 +0300 Subject: [PATCH] chore: remove unedeed file --- .../document/document-history-sheet.tsx | 429 ------------------ 1 file changed, 429 deletions(-) delete mode 100644 apps/remix/app/components/general/document/document-history-sheet.tsx diff --git a/apps/remix/app/components/general/document/document-history-sheet.tsx b/apps/remix/app/components/general/document/document-history-sheet.tsx deleted file mode 100644 index 5320967b0..000000000 --- a/apps/remix/app/components/general/document/document-history-sheet.tsx +++ /dev/null @@ -1,429 +0,0 @@ -import { useMemo, useState } from 'react'; - -import { useLingui } from '@lingui/react'; -import { Trans } from '@lingui/react/macro'; -import { ArrowRightIcon, Loader } from 'lucide-react'; -import { DateTime } from 'luxon'; -import { match } from 'ts-pattern'; -import { UAParser } from 'ua-parser-js'; - -import { DOCUMENT_AUDIT_LOG_EMAIL_FORMAT } from '@documenso/lib/constants/document-audit-logs'; -import { DOCUMENT_AUTH_TYPES } from '@documenso/lib/constants/document-auth'; -import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs'; -import { formatDocumentAuditLogAction } from '@documenso/lib/utils/document-audit-logs'; -import { trpc } from '@documenso/trpc/react'; -import { cn } from '@documenso/ui/lib/utils'; -import { Avatar, AvatarFallback } from '@documenso/ui/primitives/avatar'; -import { Badge } from '@documenso/ui/primitives/badge'; -import { Button } from '@documenso/ui/primitives/button'; -import { Sheet, SheetContent, SheetTrigger } from '@documenso/ui/primitives/sheet'; - -import { DocumentHistorySheetChanges } from './document-history-sheet-changes'; - -export type DocumentHistorySheetProps = { - documentId: number; - userId: number; - isMenuOpen?: boolean; - onMenuOpenChange?: (_value: boolean) => void; - children?: React.ReactNode; -}; - -export const DocumentHistorySheet = ({ - documentId, - userId, - isMenuOpen, - onMenuOpenChange, - children, -}: DocumentHistorySheetProps) => { - const { _, i18n } = useLingui(); - - const [isUserDetailsVisible, setIsUserDetailsVisible] = useState(false); - - const { - data, - isLoading, - isLoadingError, - refetch, - hasNextPage, - fetchNextPage, - isFetchingNextPage, - } = trpc.document.findDocumentAuditLogs.useInfiniteQuery( - { - documentId, - }, - { - getNextPageParam: (lastPage) => lastPage.nextCursor, - placeholderData: (previousData) => previousData, - }, - ); - - const documentAuditLogs = useMemo(() => (data?.pages ?? []).flatMap((page) => page.data), [data]); - - const extractBrowser = (userAgent?: string | null) => { - if (!userAgent) { - return 'Unknown'; - } - - const parser = new UAParser(userAgent); - - parser.setUA(userAgent); - - const result = parser.getResult(); - - return result.browser.name; - }; - - /** - * Applies the following formatting for a given text: - * - Uppercase first lower, lowercase rest - * - Replace _ with spaces - * - * @param text The text to format - * @returns The formatted text - */ - const formatGenericText = (text?: string | string[] | null): string => { - if (!text) { - return ''; - } - - if (Array.isArray(text)) { - return text.map((t) => formatGenericText(t)).join(', '); - } - - return (text.charAt(0).toUpperCase() + text.slice(1).toLowerCase()).replaceAll('_', ' '); - }; - - return ( - - {children && {children}} - - -
-

- Document history -

- -
- - {isLoading && ( -
- -
- )} - - {isLoadingError && ( -
-

- Unable to load document history -

- -
- )} - - {data && ( -
    - {documentAuditLogs.map((auditLog) => ( -
  • -
    - - - {(auditLog?.email ?? auditLog?.name ?? '?').slice(0, 1).toUpperCase()} - - - -
    -

    - {formatDocumentAuditLogAction(_, auditLog, userId).description} -

    -

    - {DateTime.fromJSDate(auditLog.createdAt) - .setLocale(i18n.locales?.[0] || i18n.locale) - .toFormat('d MMM, yyyy HH:MM a')} -

    -
    -
    - - {match(auditLog) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_CREATED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_COMPLETED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_DELETED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_OPENED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_COMPLETED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_RECIPIENT_REJECTED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_SENT }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_MOVED_TO_TEAM }, - () => null, - ) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_CREATED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_DELETED }, - ({ data }) => { - const values = [ - { - key: 'Email', - value: data.recipientEmail, - }, - { - key: 'Role', - value: formatGenericText(data.recipientRole), - }, - ]; - - // Insert the name to the start of the array if available. - if (data.recipientName) { - values.unshift({ - key: 'Name', - value: data.recipientName, - }); - } - - return ; - }, - ) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.RECIPIENT_UPDATED }, ({ data }) => { - if (data.changes.length === 0) { - return null; - } - - return ( - ({ - key: formatGenericText(type), - value: ( - - {type === 'ROLE' ? formatGenericText(from) : from} - - {type === 'ROLE' ? formatGenericText(to) : to} - - ), - }))} - /> - ); - }) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.FIELD_CREATED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.FIELD_DELETED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.FIELD_UPDATED }, - ({ data }) => ( - - ), - ) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACCESS_UPDATED }, - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_GLOBAL_AUTH_ACTION_UPDATED }, - ({ data }) => ( - DOCUMENT_AUTH_TYPES[f]?.value || 'None') - .join(', ') - : DOCUMENT_AUTH_TYPES[data.from || '']?.value || 'None', - }, - { - key: 'New', - value: Array.isArray(data.to) - ? data.to - .map((f) => DOCUMENT_AUTH_TYPES[f]?.value || 'None') - .join(', ') - : DOCUMENT_AUTH_TYPES[data.to || '']?.value || 'None', - }, - ]} - /> - ), - ) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_META_UPDATED }, ({ data }) => { - if (data.changes.length === 0) { - return null; - } - - return ( - ({ - key: formatGenericText(change.type), - value: change.type === 'PASSWORD' ? '*********' : change.to, - }))} - /> - ); - }) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_TITLE_UPDATED }, ({ data }) => ( - - )) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_EXTERNAL_ID_UPDATED }, - ({ data }) => ( - - ), - ) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_FIELD_INSERTED }, ({ data }) => ( - - )) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_FIELD_UNINSERTED }, ({ data }) => ( - - )) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.EMAIL_SENT }, ({ data }) => ( - - )) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_VISIBILITY_UPDATED }, - ({ data }) => ( - - ), - ) - .with({ type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_FIELD_PREFILLED }, ({ data }) => ( - - )) - .with( - { type: DOCUMENT_AUDIT_LOG_TYPE.DOCUMENT_ATTACHMENTS_UPDATED }, - ({ data }) => ( - attachment.label).join(', ') || 'None', - }, - { - key: 'New', - value: - data.to.map((attachment) => attachment.label).join(', ') || 'None', - }, - ]} - /> - ), - ) - .exhaustive()} - - {isUserDetailsVisible && ( - <> -
    - - IP: {auditLog.ipAddress ?? 'Unknown'} - - - - Browser: {extractBrowser(auditLog.userAgent)} - -
    - - )} -
  • - ))} - - {hasNextPage && ( -
    - -
    - )} -
- )} -
-
- ); -};