import type { MessageDescriptor } from '@lingui/core'; import { msg } from '@lingui/core/macro'; import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; import { motion } from 'framer-motion'; import { AlertTriangle, Plus } from 'lucide-react'; import { useDropzone } from 'react-dropzone'; import { Link } from 'react-router'; import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT, IS_BILLING_ENABLED } from '@documenso/lib/constants/app'; import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions'; import { DocumentDropzoneCardCenterVariants, DocumentDropzoneCardLeftVariants, DocumentDropzoneCardRightVariants, DocumentDropzoneContainerVariants, DocumentDropzoneDisabledCardCenterVariants, DocumentDropzoneDisabledCardLeftVariants, DocumentDropzoneDisabledCardRightVariants, } from '../lib/document-dropzone-constants'; import { cn } from '../lib/utils'; import { Button } from './button'; import { Card, CardContent } from './card'; export type DocumentDropzoneProps = { className?: string; disabled?: boolean; disabledMessage?: MessageDescriptor; onDrop?: (_file: File) => void | Promise; onDropRejected?: () => void | Promise; type?: 'document' | 'template'; [key: string]: unknown; }; export const DocumentDropzone = ({ className, onDrop, onDropRejected, disabled, disabledMessage = msg`You cannot upload documents at this time.`, type = 'document', ...props }: DocumentDropzoneProps) => { const { _ } = useLingui(); const { getRootProps, getInputProps } = useDropzone({ accept: { 'application/pdf': ['.pdf'], }, multiple: false, disabled, onDrop: ([acceptedFile]) => { if (acceptedFile && onDrop) { void onDrop(acceptedFile); } }, onDropRejected: () => { if (onDropRejected) { void onDropRejected(); } }, maxSize: megabytesToBytes(APP_DOCUMENT_UPLOAD_SIZE_LIMIT), }); const heading = { document: disabled ? msg`You have reached your document limit.` : msg`Add a document`, template: msg`Upload Template Document`, }; return ( {disabled ? ( // Disabled State
) : ( // Non Disabled State
)}

{_(heading[type])}

{_(disabled ? disabledMessage : msg`Drag & drop your PDF here.`)}

{disabled && IS_BILLING_ENABLED() && ( )} ); };