Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 363 Rev 364
Línea 1... Línea 1...
1
import React from "react";
1
import React, { useState } from "react";
2
import Question from "../question/Question";
2
import Question from "../question/Question";
Línea 3... Línea 3...
3
 
3
 
Línea 4... Línea -...
4
const Section = (props) => {
-
 
5
 
-
 
6
 
4
const Section = (props) => {
7
 
5
 
-
 
6
    // get props
-
 
7
    const { section, backendVars, handleAnswer, page, setPage } = props;
-
 
8
 
Línea 8... Línea 9...
8
    // get props
9
    //init states 
9
    const { section, backendVars, handleAnswer, key } = props;
10
    const [error, setError] = useState('');
10
 
11
 
11
    /**
12
    /**
12
     * Check if there are questions to answer
13
     * Check if there are questions to answer
-
 
14
     * @returns 
13
     * @returns 
15
     */
14
     */
16
    const validateSection = () => {
15
    const validateSection = () => {
17
        setError('');
16
        let formValid = true;
18
        let formValid = true;
17
        section.questions.map((question) => {
19
        section.questions.map((question) => {
18
            //Validate if the answer is empty
20
            //Validate if the answer is empty
19
            if (!question.answer) {
21
            if (!question.answer) {
20
                formValid = false;
22
                formValid = false;
21
            }
23
            }
Línea -... Línea 24...
-
 
24
        })
-
 
25
        return formValid;
-
 
26
    }
-
 
27
 
-
 
28
    /**
-
 
29
     * Return to previous section
-
 
30
     * @returns 
-
 
31
     */
-
 
32
    const handlePrevious = () => setPage(page - 1);
-
 
33
 
-
 
34
 
-
 
35
    /**
-
 
36
     * Continue to the next section
-
 
37
     */
-
 
38
    const handleNext = () => {
-
 
39
        if (validateSection()) {
22
        })
40
            setPage(page + 1);
Línea 23... Línea 41...
23
        return formValid;
41
        }
24
    }
42
    }
25
 
43
 
26
    return (
44
    return (
27
 
45
 
28
        <div className="panel-group">
46
        <div className="panel-group" hidden={page == section.position ? false : true}>
Línea 48... Línea 66...
48
                                />;
66
                                />;
49
                            })}
67
                            })}
50
                        </div>
68
                        </div>
51
                        <div className="row">
69
                        <div className="row">
52
                            <div className="col-md-12 text-right np-padding">
70
                            <div className="col-md-12 text-right np-padding">
-
 
71
                                <div class="alert alert-danger" role="alert">
-
 
72
                                    This is a danger alert—check it out!
-
 
73
                                </div>
-
 
74
                            </div>
-
 
75
                            <div className="col-md-12 text-right np-padding">
53
                                <ul class="wizard">
76
                                <ul class="wizard">
54
                                    <li class="previous">
77
                                    <li class="previous">
55
                                        <button
78
                                        <button
56
                                            type="button"
79
                                            type="button"
57
                                            className="btn btn-secondary"
80
                                            className="btn btn-secondary"
-
 
81
                                            onClick={() => handlePrevious()}
58
                                            disabled={section.position == 0}
82
                                            disabled={section.position == 0}
59
                                        >
83
                                        >
60
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_PREVIOUS}
84
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_PREVIOUS}
61
                                        </button>
85
                                        </button>
62
                                    </li>
86
                                    </li>
63
                                    <li class="next">
87
                                    <li class="next">
64
                                        <button
88
                                        <button
65
                                            type="button"
89
                                            type="button"
66
                                            disabled={!validateSection()}
90
                                            onClick={() => handleNext()}
67
                                            className="btn btn-secondary">
91
                                            className="btn btn-secondary">
68
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_NEXT}
92
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_NEXT}
69
                                        </button>
93
                                        </button>
70
                                    </li>
94
                                    </li>
71
                                </ul>
95
                                </ul>