From 3a752b88c6235cb5aa2f94d1c64a95e5e7651164 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Sun, 19 Oct 2025 01:43:24 -0300 Subject: [PATCH] Dropzone: clear local items when parent attachments reset (prevents stale 'Pronto' rows after submit) --- src/components/ui/dropzone.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ui/dropzone.tsx b/src/components/ui/dropzone.tsx index de491b6..8c1d2e5 100644 --- a/src/components/ui/dropzone.tsx +++ b/src/components/ui/dropzone.tsx @@ -2,7 +2,7 @@ import { useAction } from "convex/react"; import { api } from "@/convex/_generated/api"; -import { useCallback, useMemo, useRef, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { cn } from "@/lib/utils"; import { Spinner } from "@/components/ui/spinner"; import { Upload, Check, X, AlertCircle } from "lucide-react"; @@ -41,6 +41,17 @@ export function Dropzone({ const remainingSlots = Math.max(0, maxFiles - normalizedFileCount); const perFileLimitMb = Math.max(1, Math.round(maxSize / (1024 * 1024))); + // If the parent cleared all selected attachments after a submit, + // also clear the local status list so we don't keep showing + // items with the "Pronto" badge and remove button. + const prevCountRef = useRef(normalizedFileCount); + useEffect(() => { + if (prevCountRef.current > 0 && normalizedFileCount === 0) { + setItems([]); + } + prevCountRef.current = normalizedFileCount; + }, [normalizedFileCount]); + const infoMessage = useMemo(() => { if (normalizedFileCount === 0) { return `Cada arquivo com até ${perFileLimitMb}MB • Você pode anexar até ${maxFiles} ${maxFiles === 1 ? "arquivo" : "arquivos"}`;