From 6f3a6d40f42736b1b250c83d1ce79a284ac744f3 Mon Sep 17 00:00:00 2001
From: ronalds
Date: Thu, 27 Nov 2025 01:14:21 -0300
Subject: [PATCH] Edicion de preguntas
---
frontend/src/App.jsx | 146 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 134 insertions(+), 12 deletions(-)
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 4da3aa0..e896132 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -916,6 +916,7 @@ function QuestionsManagerModal({ checklist, onClose }) {
const [questions, setQuestions] = useState([])
const [loading, setLoading] = useState(true)
const [showCreateForm, setShowCreateForm] = useState(false)
+ const [editingQuestion, setEditingQuestion] = useState(null)
const [formData, setFormData] = useState({
section: '',
text: '',
@@ -1012,6 +1013,93 @@ function QuestionsManagerModal({ checklist, onClose }) {
}
}
+ const handleEditQuestion = (question) => {
+ setEditingQuestion(question)
+ setShowCreateForm(false)
+ setFormData({
+ section: question.section || '',
+ text: question.text,
+ type: question.type,
+ points: question.points || 1,
+ options: question.options || {
+ type: question.type,
+ choices: [
+ { value: 'pass', label: 'Pasa', points: 1, status: 'ok' },
+ { value: 'fail', label: 'Falla', points: 0, status: 'critical' }
+ ]
+ },
+ allow_photos: question.allow_photos ?? true,
+ max_photos: question.max_photos || 3,
+ requires_comment_on_fail: question.requires_comment_on_fail || false,
+ send_notification: question.send_notification || false,
+ parent_question_id: question.parent_question_id || null,
+ show_if_answer: question.show_if_answer || '',
+ ai_prompt: question.ai_prompt || ''
+ })
+ }
+
+ const handleUpdateQuestion = async (e) => {
+ e.preventDefault()
+
+ try {
+ const token = localStorage.getItem('token')
+ const API_URL = import.meta.env.VITE_API_URL || ''
+
+ const response = await fetch(`${API_URL}/api/questions/${editingQuestion.id}`, {
+ method: 'PUT',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${token}`
+ },
+ body: JSON.stringify({
+ checklist_id: checklist.id,
+ section: formData.section,
+ text: formData.text,
+ type: formData.type,
+ points: parseInt(formData.points),
+ options: formData.options,
+ allow_photos: formData.allow_photos,
+ max_photos: parseInt(formData.max_photos),
+ requires_comment_on_fail: formData.requires_comment_on_fail,
+ send_notification: formData.send_notification,
+ parent_question_id: formData.parent_question_id || null,
+ show_if_answer: formData.show_if_answer || null,
+ ai_prompt: formData.ai_prompt || null
+ })
+ })
+
+ if (response.ok) {
+ setEditingQuestion(null)
+ setFormData({
+ section: '',
+ text: '',
+ type: 'boolean',
+ points: 1,
+ options: {
+ type: 'boolean',
+ choices: [
+ { value: 'pass', label: 'Pasa', points: 1, status: 'ok' },
+ { value: 'fail', label: 'Falla', points: 0, status: 'critical' }
+ ]
+ },
+ allow_photos: true,
+ max_photos: 3,
+ requires_comment_on_fail: false,
+ send_notification: false,
+ parent_question_id: null,
+ show_if_answer: '',
+ ai_prompt: ''
+ })
+ loadQuestions()
+ } else {
+ alert('Error al actualizar pregunta')
+ }
+ } catch (error) {
+ console.error('Error:', error)
+ alert('Error al actualizar pregunta')
+ }
+ }
+
const handleDeleteQuestion = async (questionId) => {
if (!confirm('¿Estás seguro de eliminar esta pregunta?')) return
@@ -1071,17 +1159,43 @@ function QuestionsManagerModal({ checklist, onClose }) {
- {/* Create Form */}
- {showCreateForm && (
+ {/* Create/Edit Form */}
+ {(showCreateForm || editingQuestion) && (
-
+
+
+
+
)
})}