Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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