import { Paperclip, Eye, Download } from "lucide-react"; import { useState } from "react"; import type { AttachmentNote, ContactNote, DealNote } from "../types"; import { DocumentViewer } from "../misc/DocumentViewer"; import { Button } from "@/components/ds/ui/button"; export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => { const [selectedAttachment, setSelectedAttachment] = useState(null); if (!note.attachments || note.attachments.length === 0) { return null; } const imageAttachments = note.attachments.filter( (attachment: AttachmentNote) => isImageMimeType(attachment.type), ); const otherAttachments = note.attachments.filter( (attachment: AttachmentNote) => !isImageMimeType(attachment.type), ); return (
{imageAttachments.length > 0 && (
{imageAttachments.map((attachment: AttachmentNote, index: number) => (
{attachment.title} setSelectedAttachment(attachment)} />
))}
)} {otherAttachments.length > 0 && otherAttachments.map((attachment: AttachmentNote, index: number) => (
))} {selectedAttachment && ( !open && setSelectedAttachment(null)} url={selectedAttachment.src} title={selectedAttachment.title} type={selectedAttachment.type} file={selectedAttachment.rawFile} /> )}
); }; const isImageMimeType = (mimeType?: string): boolean => { if (!mimeType) { return false; } return mimeType.startsWith("image/"); };