"use client"; import { RiAttachment2, RiCloseLine } from "@remixicon/react"; import { useRef } from "react"; import { toast } from "sonner"; import { ALLOWED_MIME_TYPES, DEFAULT_MAX_FILE_SIZE_MB, } from "@/features/transactions/attachments-config"; import { Button } from "@/shared/components/ui/button"; interface AttachmentFilePickerProps { file: File | null; onChange: (file: File | null) => void; maxSizeMb?: number; } export function AttachmentFilePicker({ file, onChange, maxSizeMb = DEFAULT_MAX_FILE_SIZE_MB, }: AttachmentFilePickerProps) { const maxFileSizeBytes = maxSizeMb * 1024 * 1024; const inputRef = useRef(null); function handleFileChange(e: React.ChangeEvent) { const selected = e.target.files?.[0]; if (inputRef.current) inputRef.current.value = ""; if (!selected) return; if ( !ALLOWED_MIME_TYPES.includes( selected.type as (typeof ALLOWED_MIME_TYPES)[number], ) ) { toast.error( "Tipo de arquivo não suportado. Use PDF ou imagem (JPEG, PNG, WebP).", ); return; } if (selected.size > maxFileSizeBytes) { toast.error(`O arquivo deve ter no máximo ${maxSizeMb}MB.`); return; } onChange(selected); } return (

Anexo

{file ? (
{file.name}
) : ( )}
); }