fix: опрос файлов ЮЛ — без спама ошибок, сброс при смене ЮЛ, уникальные key (I-1, I-2, M-1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EAKRDNzXtRrwmWz9z6PZu3
This commit is contained in:
Andrey Epifancev 2026-10-08 01:11:15 +04:00
parent c7867277d8
commit 64d64d3b0a
2 changed files with 19 additions and 12 deletions

View File

@ -71,8 +71,8 @@ export function UploadDocumentsModal({ legalEntityId, versionId, open, onClose,
message={`Отклонено: ${summary.rejected.length}`}
description={
<ul style={{ margin: 0, paddingLeft: 16 }}>
{summary.rejected.map((r) => (
<li key={r.name}>
{summary.rejected.map((r, i) => (
<li key={`${r.name}-${i}`}>
{r.name} — {r.reason}
</li>
))}

View File

@ -12,6 +12,7 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
const [loading, setLoading] = useState(false);
const requestRef = useRef(0);
const inFlightRef = useRef(false);
const errorShownRef = useRef(false);
const reload = useCallback(async () => {
if (!legalEntityId) return;
@ -20,9 +21,16 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
setLoading(true);
try {
const items = await listLegalEntityFiles(legalEntityId);
if (requestId === requestRef.current) setFiles(items);
if (requestId === requestRef.current) {
setFiles(items);
errorShownRef.current = false;
}
} catch (e: unknown) {
if (requestId === requestRef.current) message.error(e instanceof ApiError ? e.message : 'Не удалось получить файлы');
// при опросе показываем ошибку один раз на серию; флаг сбрасывается после первого успешного ответа
if (requestId === requestRef.current && !errorShownRef.current) {
errorShownRef.current = true;
message.error(e instanceof ApiError ? e.message : 'Не удалось получить файлы');
}
} finally {
if (requestId === requestRef.current) {
inFlightRef.current = false;
@ -32,14 +40,13 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
}, [legalEntityId]);
useEffect(() => {
if (open) {
void reload();
} else {
requestRef.current++; // ответы после закрытия не применяем
inFlightRef.current = false;
setFiles([]);
}
}, [open, reload]);
// при смене ЮЛ / закрытии панели: старые ответы не применяем, файлы прежнего ЮЛ очищаем
requestRef.current++;
inFlightRef.current = false;
errorShownRef.current = false;
setFiles([]);
if (open && legalEntityId) void reload();
}, [open, legalEntityId, reload]);
const pending = hasPendingFiles(files);
useEffect(() => {