From 678a8cd24b27df2e623212d6b35e08a4206e7ffc Mon Sep 17 00:00:00 2001 From: ronalds Date: Fri, 21 Nov 2025 02:28:27 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20Corregir=20l=C3=B3gica=20de=20preguntas?= =?UTF-8?q?=20condicionales=20-=20frontend=20v1.0.20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sin valor por defecto en respuestas (usuario debe elegir) - setAnswers funcional para evitar condiciones de carrera - visibleQuestions actualizado en tiempo real - Sub-preguntas se muestran/ocultan dinámicamente según respuesta padre --- docker-compose.hub.yml | 2 +- frontend/src/App.jsx | 77 ++++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/docker-compose.hub.yml b/docker-compose.hub.yml index 0f79624..b583c54 100644 --- a/docker-compose.hub.yml +++ b/docker-compose.hub.yml @@ -38,7 +38,7 @@ services: command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4 frontend: - image: dymai/syntria-frontend:1.0.19 + image: dymai/syntria-frontend:1.0.20 container_name: syntria-frontend-prod restart: always depends_on: diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c5c9bd2..25fe85d 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -2015,11 +2015,11 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { console.log('Questions loaded:', questionsData.length, 'questions') setQuestions(questionsData) - // Initialize answers object + // Initialize answers object - empty values to force user interaction const initialAnswers = {} questionsData.forEach(q => { initialAnswers[q.id] = { - value: q.type === 'pass_fail' ? 'pass' : '', + value: '', // No default value - user must choose observations: '', photos: [] } @@ -2102,7 +2102,7 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { const question = questions.find(q => q.id === questionId) const answer = answers[questionId] - if (!answer?.value) return // Don't save empty answers + if (!answer?.value && answer?.value !== '') return // Don't save if no value try { const token = localStorage.getItem('token') @@ -2155,10 +2155,10 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { } // Mark as saved - setAnswers({ - ...answers, - [questionId]: { ...answers[questionId], saved: true } - }) + setAnswers(prev => ({ + ...prev, + [questionId]: { ...prev[questionId], saved: true } + })) } } catch (error) { console.error('Error saving answer:', error) @@ -2415,7 +2415,9 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { } } - const currentQuestion = questions[currentQuestionIndex] + // Get visible questions based on conditional logic + const visibleQuestions = getVisibleQuestions() + const currentQuestion = visibleQuestions[currentQuestionIndex] return (
@@ -2641,10 +2643,11 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { value="pass" checked={answers[currentQuestion.id]?.value === 'pass'} onChange={(e) => { - setAnswers({ - ...answers, - [currentQuestion.id]: { ...answers[currentQuestion.id], value: e.target.value } - }) + const newValue = e.target.value + setAnswers(prev => ({ + ...prev, + [currentQuestion.id]: { ...prev[currentQuestion.id], value: newValue } + })) setTimeout(() => saveAnswer(currentQuestion.id), 500) }} className="mr-2" @@ -2657,10 +2660,11 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { value="fail" checked={answers[currentQuestion.id]?.value === 'fail'} onChange={(e) => { - setAnswers({ - ...answers, - [currentQuestion.id]: { ...answers[currentQuestion.id], value: e.target.value } - }) + const newValue = e.target.value + setAnswers(prev => ({ + ...prev, + [currentQuestion.id]: { ...prev[currentQuestion.id], value: newValue } + })) setTimeout(() => saveAnswer(currentQuestion.id), 500) }} className="mr-2" @@ -2674,10 +2678,11 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { setAnswers({ - ...answers, - [currentQuestion.id]: { ...answers[currentQuestion.id], value: e.target.value } - })} + onChange={(e) => setAnswers(prev => ({ + ...prev, + [currentQuestion.id]: { ...prev[currentQuestion.id], value: e.target.value } + }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500" > @@ -2722,10 +2727,10 @@ function InspectionModal({ checklist, user, onClose, onComplete }) { {currentQuestion.type === 'text' && (