diff --git a/components/bookkeeping/JournalEntryAttachments.tsx b/components/bookkeeping/JournalEntryAttachments.tsx index 34044fe7..2334a848 100644 --- a/components/bookkeeping/JournalEntryAttachments.tsx +++ b/components/bookkeeping/JournalEntryAttachments.tsx @@ -31,13 +31,21 @@ function isImageType(type: string | null): boolean { return type?.startsWith('image/') ?? false } +function isPdfType(type: string | null): boolean { + return type === 'application/pdf' +} + +function isPreviewable(type: string | null): boolean { + return isImageType(type) || isPdfType(type) +} + export default function JournalEntryAttachments({ journalEntryId, onCountChange, }: JournalEntryAttachmentsProps) { const [documents, setDocuments] = useState([]) const [loading, setLoading] = useState(true) - const [expandedImage, setExpandedImage] = useState(null) + const [expandedDoc, setExpandedDoc] = useState(null) const [showUpload, setShowUpload] = useState(false) const [uploadFiles, setUploadFiles] = useState([]) @@ -87,8 +95,8 @@ export default function JournalEntryAttachments({ } const handlePreviewToggle = async (doc: DocumentRecord) => { - if (expandedImage === doc.id) { - setExpandedImage(null) + if (expandedDoc === doc.id) { + setExpandedDoc(null) return } @@ -108,7 +116,7 @@ export default function JournalEntryAttachments({ } } - setExpandedImage(doc.id) + setExpandedDoc(doc.id) } if (loading) { @@ -158,12 +166,12 @@ export default function JournalEntryAttachments({ {documents.map((doc) => (
- {isImageType(doc.mime_type) ? ( + {isPreviewable(doc.mime_type) ? (
{/* Image preview */} - {expandedImage === doc.id && doc.download_url && ( + {expandedDoc === doc.id && doc.download_url && isImageType(doc.mime_type) && (
)} + + {/* PDF preview */} + {expandedDoc === doc.id && doc.download_url && isPdfType(doc.mime_type) && ( +
+