Dropzone: clear local items when parent attachments reset (prevents stale 'Pronto' rows after submit)
This commit is contained in:
parent
fc1bdc248b
commit
3a752b88c6
1 changed files with 12 additions and 1 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { useAction } from "convex/react";
|
import { useAction } from "convex/react";
|
||||||
import { api } from "@/convex/_generated/api";
|
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 { cn } from "@/lib/utils";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
import { Upload, Check, X, AlertCircle } from "lucide-react";
|
import { Upload, Check, X, AlertCircle } from "lucide-react";
|
||||||
|
|
@ -41,6 +41,17 @@ export function Dropzone({
|
||||||
const remainingSlots = Math.max(0, maxFiles - normalizedFileCount);
|
const remainingSlots = Math.max(0, maxFiles - normalizedFileCount);
|
||||||
const perFileLimitMb = Math.max(1, Math.round(maxSize / (1024 * 1024)));
|
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<number>(normalizedFileCount);
|
||||||
|
useEffect(() => {
|
||||||
|
if (prevCountRef.current > 0 && normalizedFileCount === 0) {
|
||||||
|
setItems([]);
|
||||||
|
}
|
||||||
|
prevCountRef.current = normalizedFileCount;
|
||||||
|
}, [normalizedFileCount]);
|
||||||
|
|
||||||
const infoMessage = useMemo(() => {
|
const infoMessage = useMemo(() => {
|
||||||
if (normalizedFileCount === 0) {
|
if (normalizedFileCount === 0) {
|
||||||
return `Cada arquivo com até ${perFileLimitMb}MB • Você pode anexar até ${maxFiles} ${maxFiles === 1 ? "arquivo" : "arquivos"}`;
|
return `Cada arquivo com até ${perFileLimitMb}MB • Você pode anexar até ${maxFiles} ${maxFiles === 1 ? "arquivo" : "arquivos"}`;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue