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:
parent
c7867277d8
commit
64d64d3b0a
@ -71,8 +71,8 @@ export function UploadDocumentsModal({ legalEntityId, versionId, open, onClose,
|
|||||||
message={`Отклонено: ${summary.rejected.length}`}
|
message={`Отклонено: ${summary.rejected.length}`}
|
||||||
description={
|
description={
|
||||||
<ul style={{ margin: 0, paddingLeft: 16 }}>
|
<ul style={{ margin: 0, paddingLeft: 16 }}>
|
||||||
{summary.rejected.map((r) => (
|
{summary.rejected.map((r, i) => (
|
||||||
<li key={r.name}>
|
<li key={`${r.name}-${i}`}>
|
||||||
{r.name} — {r.reason}
|
{r.name} — {r.reason}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const requestRef = useRef(0);
|
const requestRef = useRef(0);
|
||||||
const inFlightRef = useRef(false);
|
const inFlightRef = useRef(false);
|
||||||
|
const errorShownRef = useRef(false);
|
||||||
|
|
||||||
const reload = useCallback(async () => {
|
const reload = useCallback(async () => {
|
||||||
if (!legalEntityId) return;
|
if (!legalEntityId) return;
|
||||||
@ -20,9 +21,16 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const items = await listLegalEntityFiles(legalEntityId);
|
const items = await listLegalEntityFiles(legalEntityId);
|
||||||
if (requestId === requestRef.current) setFiles(items);
|
if (requestId === requestRef.current) {
|
||||||
|
setFiles(items);
|
||||||
|
errorShownRef.current = false;
|
||||||
|
}
|
||||||
} catch (e: unknown) {
|
} 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 {
|
} finally {
|
||||||
if (requestId === requestRef.current) {
|
if (requestId === requestRef.current) {
|
||||||
inFlightRef.current = false;
|
inFlightRef.current = false;
|
||||||
@ -32,14 +40,13 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean)
|
|||||||
}, [legalEntityId]);
|
}, [legalEntityId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) {
|
// при смене ЮЛ / закрытии панели: старые ответы не применяем, файлы прежнего ЮЛ очищаем
|
||||||
void reload();
|
requestRef.current++;
|
||||||
} else {
|
inFlightRef.current = false;
|
||||||
requestRef.current++; // ответы после закрытия не применяем
|
errorShownRef.current = false;
|
||||||
inFlightRef.current = false;
|
setFiles([]);
|
||||||
setFiles([]);
|
if (open && legalEntityId) void reload();
|
||||||
}
|
}, [open, legalEntityId, reload]);
|
||||||
}, [open, reload]);
|
|
||||||
|
|
||||||
const pending = hasPendingFiles(files);
|
const pending = hasPendingFiles(files);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user