Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 443 | Rev 453 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
452 geraldo 1
import React, { useState } from "react";
306 geraldo 2
import Option from "../option/Option";
3
 
4
const Question = (props) => {
310 geraldo 5
 
452 geraldo 6
 
7
 
8
 
306 geraldo 9
    // get props
340 geraldo 10
    const { question, backendVars, handleAnswer } = props;
452 geraldo 11
    const [input] = useState(question.value);
306 geraldo 12
 
13
    return (
313 geraldo 14
        <div className="col-md-12 col-sm-12 col-xs-12 np-padding">
310 geraldo 15
            <div className="form-group" >
333 geraldo 16
                <h6>{backendVars.LBL_QUESTION} #{question.position + 1}</h6>
310 geraldo 17
                <div
18
                    dangerouslySetInnerHTML={{ __html: question.text }}
19
                    className="title"
20
                />
21
            </div>
306 geraldo 22
            {question.type == 'open' &&
310 geraldo 23
                <div className="form-group">
306 geraldo 24
                    {question.multiline == 1 ? (
25
                        <textarea
26
                            className="form-control"
27
                            rows="5"
452 geraldo 28
                            value={input}
306 geraldo 29
                            maxLength={question.maxlength}
30
                            name={question.slug_question}
342 geraldo 31
                            onChange={e =>
32
                                handleAnswer(question.slug_section, question.slug_question, e.target.value)
33
                            }
34
                        />
306 geraldo 35
                    ) : (
36
                        <input
37
                            type="text"
38
                            className="form-control"
442 geraldo 39
                            value={question.answer}
306 geraldo 40
                            maxLength={question.maxlength}
340 geraldo 41
                            name={question.slug_question}
342 geraldo 42
                            onChange={e =>
43
                                handleAnswer(question.slug_section, question.slug_question, e.target.value)
44
                            }
45
                        />
306 geraldo 46
                    )}
47
                </div>
48
            }
49
            {question.type == 'rating-range' &&
310 geraldo 50
                <div className="form-group">
334 geraldo 51
                    {[...Array(parseInt(question.range))].map((x, i) => {
306 geraldo 52
                        return (
333 geraldo 53
                            <div className="checkbox"
54
                                key={i}>
306 geraldo 55
                                <input
56
                                    type="radio"
443 geraldo 57
                                    checked={question.answer == i + 1}
306 geraldo 58
                                    name={question.slug_question}
342 geraldo 59
                                    value={i + 1}
60
                                    onChange={() =>
61
                                        handleAnswer(question.slug_section, question.slug_question, i + 1)
62
                                    }
63
                                />
333 geraldo 64
                                <div className="option">
336 geraldo 65
                                    {i + 1}
333 geraldo 66
                                </div>
306 geraldo 67
                            </div>
68
                        )
69
                    })}
70
                </div>
71
            }
333 geraldo 72
            {(question.type == 'simple' || question.type == 'rating-open' || question.type == 'multiple') &&
310 geraldo 73
                <div className="form-group">
323 geraldo 74
                    {question.options.length > 0 &&
340 geraldo 75
                        <Option
76
                            question={question}
77
                            handleAnswer={handleAnswer} />
306 geraldo 78
                    }
79
                </div>
80
            }
81
        </div>
82
    )
83
}
84
 
85
export default Question;