"use client"; import { RiDeleteBinLine, RiDownloadLine, RiExternalLinkLine, RiFileImageLine, RiFilePdf2Line, } from "@remixicon/react"; import { useState, useTransition } from "react"; import { toast } from "sonner"; import { detachTransactionAttachmentAction } from "@/features/transactions/actions/attachments"; import { Button } from "@/shared/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog"; function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } function AttachmentIcon({ mimeType }: { mimeType: string }) { if (mimeType === "application/pdf") return ; if (mimeType.startsWith("image/")) return ; } function AttachmentPreview({ open, onOpenChange, fileName, mimeType, url, }: { open: boolean; onOpenChange: (open: boolean) => void; fileName: string; mimeType: string; url: string; }) { const isPdf = mimeType === "application/pdf"; const isImage = mimeType.startsWith("image/"); return (
{fileName}
{isPdf && (