fix: Improve problem_description detection for draft completeness check

Problem:
- problem_description not found in payload, but exists in draft list
- Completeness check fails because hasDescription = false
- Draft not recognized as ready for confirmation

Solution:
1. Enhanced problem_description extraction:
   - Checks multiple locations: body.problem_description, payload.problem_description
   - Also checks payload.body.problem_description for nested structures
   - Added fallback to body.description and payload.description

2. Improved completeness logic:
   - If problem_description not found but wizard_plan and answers exist,
     infer that description was entered (plan is generated from description)
   - This handles cases where description exists but not in expected payload location

3. Better logging:
   - Shows if problem_description was found directly or inferred
   - Logs all payload keys for debugging

Logic:
- hasDescription = !!problemDescription || (!!wizardPlan && !!answers)
- If plan and answers exist → description was entered earlier
- This allows drafts with plan+answers+documents to proceed to confirmation

Files:
- frontend/src/pages/ClaimForm.tsx: Enhanced problem_description detection
This commit is contained in:
AI Assistant
2025-11-24 15:12:29 +03:00
parent 577611c65d
commit 1789dafce2

View File

@@ -417,7 +417,15 @@ export default function ClaimForm() {
// ✅ Извлекаем данные из body (telegram) или напрямую из payload (web_form) // ✅ Извлекаем данные из body (telegram) или напрямую из payload (web_form)
const wizardPlanRaw = body.wizard_plan || payload.wizard_plan; const wizardPlanRaw = body.wizard_plan || payload.wizard_plan;
const answersRaw = body.answers || payload.answers; const answersRaw = body.answers || payload.answers;
const problemDescription = body.problem_description || payload.problem_description || body.description || payload.description; // Ищем problem_description в разных местах (может быть в разных форматах)
const problemDescription =
body.problem_description ||
payload.problem_description ||
body.description ||
payload.description ||
payload.body?.problem_description || // Для вложенных структур
payload.body?.description ||
null;
const documentsMeta = body.documents_meta || payload.documents_meta || []; const documentsMeta = body.documents_meta || payload.documents_meta || [];
// ✅ Парсим wizard_plan и answers, если они строки (JSON) // ✅ Парсим wizard_plan и answers, если они строки (JSON)
@@ -440,7 +448,9 @@ export default function ClaimForm() {
} }
// ✅ Проверяем, заполнены ли все шаги // ✅ Проверяем, заполнены ли все шаги
const hasDescription = !!problemDescription; // Для problem_description: если его нет в payload, но есть wizard_plan и answers,
// значит описание уже было введено ранее (wizard_plan генерируется на основе описания)
const hasDescription = !!problemDescription || (!!wizardPlan && !!answers); // Если есть план и ответы - описание было
const hasWizardPlan = !!wizardPlan; const hasWizardPlan = !!wizardPlan;
const hasAnswers = !!answers && Object.keys(answers).length > 0; const hasAnswers = !!answers && Object.keys(answers).length > 0;
const hasDocuments = Array.isArray(documentsMeta) && documentsMeta.length > 0; const hasDocuments = Array.isArray(documentsMeta) && documentsMeta.length > 0;
@@ -457,9 +467,11 @@ export default function ClaimForm() {
isDraft, isDraft,
allStepsFilled, allStepsFilled,
isReadyForConfirmation, isReadyForConfirmation,
problemDescriptionFound: !!problemDescription,
inferredFromPlan: !problemDescription && !!wizardPlan && !!answers,
}); });
console.log('🔍 problem_description:', problemDescription ? 'есть' : 'нет'); console.log('🔍 problem_description:', problemDescription ? 'есть' : (wizardPlan && answers ? 'выведено из наличия плана и ответов' : 'нет'));
console.log('🔍 wizard_plan:', wizardPlan ? 'есть' : 'нет'); console.log('🔍 wizard_plan:', wizardPlan ? 'есть' : 'нет');
console.log('🔍 answers:', answers ? 'есть' : 'нет'); console.log('🔍 answers:', answers ? 'есть' : 'нет');
console.log('🔍 documents_meta:', documentsMeta.length, 'документов'); console.log('🔍 documents_meta:', documentsMeta.length, 'документов');