Убран дублирующий useEffect для создания блоков документов

This commit is contained in:
Fedor
2025-11-25 23:33:59 +03:00
parent 796316d969
commit f058ca91ad

View File

@@ -338,47 +338,6 @@ export default function StepWizardPlan({
setProgressState({ done, total });
}, [formValues, questions]);
// Автоматически создаём блоки для обязательных документов при ответе "Да"
useEffect(() => {
if (!plan || !formValues) return;
questions.forEach((question) => {
const visible = evaluateCondition(question.ask_if, formValues);
if (!visible) return;
const questionValue = formValues?.[question.name];
if (!isAffirmative(questionValue)) return;
const questionDocs = documentGroups[question.name] || [];
questionDocs.forEach((doc) => {
if (!doc.required) return;
const docKey = doc.id || doc.name || `doc_${question.name}`;
// Не создаём блок, если документ пропущен
if (skippedDocuments.has(docKey)) return;
const existingBlocks = questionFileBlocks[docKey] || [];
// Если блока ещё нет, создаём его автоматически
if (existingBlocks.length === 0) {
const category = doc.id && !doc.id.includes('_exist') ? doc.id : docKey;
handleDocumentBlocksChange(docKey, (blocks) => [
...blocks,
{
id: generateBlockId(docKey),
fieldName: docKey,
description: '',
category: category,
docLabel: doc.name,
files: [],
},
]);
}
});
});
}, [formValues, plan, questions, documentGroups, questionFileBlocks, handleDocumentBlocksChange, skippedDocuments]);
// Автоматически создаём блоки для ВСЕХ документов из плана при загрузке
useEffect(() => {
if (!plan || !documents || documents.length === 0) return;