Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 13006 | Rev 13008 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 13006 Rev 13007
Línea 11... Línea 11...
11
import DeleteModal from '../../../shared/DeleteModal'
11
import DeleteModal from '../../../shared/DeleteModal'
12
import QuestionModal from '../components/QuestionModal'
12
import QuestionModal from '../components/QuestionModal'
Línea 13... Línea 13...
13
 
13
 
14
const sectionTypeOptions = {
14
const sectionTypeOptions = {
15
	open: 'Abierto',
15
	open: 'Abierto',
-
 
16
	simple: 'Simple',
16
	simple: 'Simple'
17
	multiple: 'Multiple'
Línea 17... Línea 18...
17
}
18
}
18
 
19
 
19
const INITIAL_SECTION = {
20
const INITIAL_SECTION = {
Línea 59... Línea 60...
59
 
60
 
60
	const [content, setContent] = useState([])
61
	const [content, setContent] = useState([])
61
	const [status, setStatus] = useState('A')
62
	const [status, setStatus] = useState('A')
62
	const [showDeleteModal, setShowDeleteModal] = useState(false)
63
	const [showDeleteModal, setShowDeleteModal] = useState(false)
-
 
64
	const [deleteType, setDeleteType] = useState('section')
-
 
65
	const deleteSlugsOptions = {
-
 
66
		section: sectionSelected.slug_section,
-
 
67
		question: questionSelected.slug_question
Línea 63... Línea 68...
63
	const [deleteType, setDeleteType] = useState('section')
68
	}
64
 
-
 
65
	const showSectionModal = (section = INITIAL_SECTION, type = 'add') => {
69
 
66
		setIsShowSectionModal(true)
70
	const showSectionModal = (section = INITIAL_SECTION, type = 'add') => {
-
 
71
		setSectionSelected(section)
67
		setSectionSelected(section)
72
		setSectionType(type)
Línea 68... Línea 73...
68
		setSectionType(type)
73
		setIsShowSectionModal(true)
69
	}
74
	}
70
 
75
 
Línea 95... Línea 100...
95
				return currentSection.slug_section !== slug
100
				return currentSection.slug_section !== slug
96
			}),
101
			}),
97
		)
102
		)
98
	}
103
	}
Línea -... Línea 104...
-
 
104
 
-
 
105
	const deleteQuestion = (slug) => {
-
 
106
		setContent(current =>
-
 
107
			current.map(currentSection => {
-
 
108
				if (currentSection.slug_section === sectionSelected.slug_section) {
-
 
109
					return {
-
 
110
						...currentSection,
-
 
111
						questions: currentSection.questions.filter((currentQuestion) => currentQuestion.slug_question !== slug)
-
 
112
					}
-
 
113
				}
-
 
114
				return currentSection
-
 
115
			}),
-
 
116
		)
-
 
117
	}
99
 
118
 
100
	const deleteHandler = (type, slug) => {
119
	const deleteHandler = (type, slug) => {
101
		if (type === 'section') {
120
		if (type === 'section') {
102
			return deleteSection(slug)
121
			return deleteSection(slug)
-
 
122
		}
-
 
123
		if (type === 'question') {
-
 
124
			return deleteQuestion(slug)
103
		}
125
		}
Línea 104... Línea 126...
104
	}
126
	}
105
 
127
 
106
	const editSection = (name, text, slug) => {
128
	const editSection = (name, text, slug) => {
Línea 163... Línea 185...
163
						return currentQuestion
185
						return currentQuestion
164
					})
186
					})
Línea 165... Línea 187...
165
 
187
 
166
					return { ...currentSection, questions: newQuestions }
188
					return { ...currentSection, questions: newQuestions }
167
				}
189
				}
168
				
190
 
169
				return currentSection
191
				return currentSection
170
			})
192
			})
171
		)
193
		)
Línea 308... Línea 330...
308
																								<button className="btn btn-default" onClick={() => showSectionModal(section, 'edit')}>
330
																								<button className="btn btn-default" onClick={() => showSectionModal(section, 'edit')}>
309
																									<i className="fa fa-edit" />
331
																									<i className="fa fa-edit" />
310
																									Editar Sección
332
																									Editar Sección
311
																								</button>
333
																								</button>
312
																								<button className="btn btn-default" onClick={() => {
334
																								<button className="btn btn-default" onClick={() => {
313
																									setShowDeleteModal(true)
-
 
314
																									setDeleteType('section')
-
 
315
																									setSectionSelected(section)
335
																									setSectionSelected(section)
-
 
336
																									setDeleteType('section')
-
 
337
																									setShowDeleteModal(true)
316
																								}}>
338
																								}}>
317
																									<i className="fa fa-ban" />
339
																									<i className="fa fa-ban" />
318
																									Borrar Sección
340
																									Borrar Sección
319
																								</button>
341
																								</button>
320
																								<button className="btn btn-default" onClick={() => {
342
																								<button className="btn btn-default" onClick={() => {
321
																									showQuestionModal()
-
 
322
																									setSectionSelected(section)
343
																									setSectionSelected(section)
-
 
344
																									showQuestionModal()
323
																								}}>
345
																								}}>
324
																									<i className="fa fa-plus" />
346
																									<i className="fa fa-plus" />
325
																									Agregar  Pregunta
347
																									Agregar  Pregunta
326
																								</button>
348
																								</button>
327
																							</td>
349
																							</td>
Línea 336... Línea 358...
336
																									<td className="text-capitalize">
358
																									<td className="text-capitalize">
337
																										{sectionTypeOptions[question.type]}
359
																										{sectionTypeOptions[question.type]}
338
																									</td>
360
																									</td>
339
																									<td>
361
																									<td>
340
																										<button className="btn btn-default btn-edit-question" onClick={() => {
362
																										<button className="btn btn-default btn-edit-question" onClick={() => {
341
																											showQuestionModal(question, 'edit')
-
 
342
																											setSectionSelected(section)
363
																											setSectionSelected(section)
-
 
364
																											showQuestionModal(question, 'edit')
343
																										}}>
365
																										}}>
344
																											<i className="fa fa-edit" /> Editar Pregunta
366
																											<i className="fa fa-edit" /> Editar Pregunta
345
																										</button>
367
																										</button>
346
																										<button className="btn btn-default btn-delete-question" onClick={() => {
368
																										<button className="btn btn-default btn-delete-question" onClick={() => {
347
																											setQuestionSelected(question)
369
																											setQuestionSelected(question)
Línea 400... Línea 422...
400
				onSubmit={questionType === 'add' ? addQuestion : editQuestion}
422
				onSubmit={questionType === 'add' ? addQuestion : editQuestion}
401
			/>
423
			/>
402
			<DeleteModal
424
			<DeleteModal
403
				isOpen={showDeleteModal}
425
				isOpen={showDeleteModal}
404
				closeModal={() => setShowDeleteModal(false)}
426
				closeModal={() => setShowDeleteModal(false)}
405
				onComplete={() => deleteHandler(deleteType, sectionSelected.slug_section)}
427
				onComplete={() => deleteHandler(deleteType, deleteSlugsOptions[deleteType])}
406
				message="Registro eliminado"
428
				message="Registro eliminado"
407
			/>
429
			/>
408
		</>
430
		</>
409
	)
431
	)
410
}
432
}