Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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