diff --git a/frontend/src/components/form/Step1Phone.tsx b/frontend/src/components/form/Step1Phone.tsx index 1bd3051..54bc176 100644 --- a/frontend/src/components/form/Step1Phone.tsx +++ b/frontend/src/components/form/Step1Phone.tsx @@ -100,34 +100,38 @@ export default function Step1Phone({ }) }); - const crmResult = await crmResponse.json(); + let crmResult = await crmResponse.json(); - console.log('🔥 N8N CRM Response:', crmResult); - console.log('🔥 claim_id from n8n:', crmResult.claim_id); - console.log('🔥 Array check:', Array.isArray(crmResult), crmResult[0]); + // ✅ n8n может вернуть массив - берём первый элемент + if (Array.isArray(crmResult) && crmResult.length > 0) { + crmResult = crmResult[0]; + } - if (crmResponse.ok) { - addDebugEvent?.('crm', 'success', `✅ Контакт создан/найден в CRM`, crmResult); - - // Если n8n вернул массив - берём первый элемент - const data = Array.isArray(crmResult) ? crmResult[0] : crmResult; + console.log('🔥 N8N CRM Response (after array check):', crmResult); + + if (crmResponse.ok && crmResult.success) { + // n8n возвращает: {success: true, result: {claim_id, contact_id, ...}} + const result = crmResult.result || crmResult; + console.log('🔥 Extracted result:', result); console.log('🔥 Saving to formData:', { phone, - contact_id: data.contact_id, - claim_id: data.claim_id, - is_new_contact: data.is_new_contact + contact_id: result.contact_id, + claim_id: result.claim_id, + is_new_contact: result.is_new_contact }); + addDebugEvent?.('crm', 'success', `✅ Контакт создан/найден в CRM`, result); + // Сохраняем данные из CRM в форму updateFormData({ phone, - contact_id: data.contact_id, - claim_id: data.claim_id, - is_new_contact: data.is_new_contact + contact_id: result.contact_id, + claim_id: result.claim_id, + is_new_contact: result.is_new_contact }); - message.success(crmResult.is_new_contact ? 'Контакт создан!' : 'Контакт найден!'); + message.success(result.is_new_contact ? 'Контакт создан!' : 'Контакт найден!'); onNext(); } else { addDebugEvent?.('crm', 'error', '❌ Ошибка создания контакта в CRM', crmResult);