"use client"; import { RiFileAddLine } from "@remixicon/react"; import { useQueryClient } from "@tanstack/react-query"; import { useEffect } from "react"; import { transactionAttachmentsQueryKey, useTransactionAttachments, } from "@/features/transactions/hooks/use-transaction-attachments"; import { Button } from "@/shared/components/ui/button"; import { AttachmentItem } from "./attachment-item"; import { AttachmentUpload } from "./attachment-upload"; interface AttachmentSectionProps { transactionId: string; readonly?: boolean; onLoaded?: (count: number) => void; pendingDetachIds?: string[]; onPendingDetach?: (attachmentId: string) => void; onUndoPendingDetach?: (attachmentId: string) => void; pendingUploadFiles?: File[]; onPendingUpload?: (file: File) => void; onCancelPendingUpload?: (file: File) => void; maxSizeMb?: number; } export function AttachmentSection({ transactionId, readonly = false, onLoaded, pendingDetachIds, onPendingDetach, onUndoPendingDetach, pendingUploadFiles, onPendingUpload, onCancelPendingUpload, maxSizeMb, }: AttachmentSectionProps) { const queryClient = useQueryClient(); const { data: items = [], isLoading, isError, } = useTransactionAttachments(transactionId); useEffect(() => { onLoaded?.(items.length); }, [items.length, onLoaded]); const invalidateAttachments = () => { void queryClient.invalidateQueries({ queryKey: transactionAttachmentsQueryKey(transactionId), }); }; if (isLoading) { return
Carregando...
; } if (isError) { return (Não foi possível carregar os anexos.
); } const hasPendingUploads = (pendingUploadFiles?.length ?? 0) > 0; return (Nenhum anexo.
)} {(items.length > 0 || hasPendingUploads) && ({file.name}
Será adicionado ao salvar