Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 471 Rev 473
Línea 5... Línea 5...
5
 
5
 
Línea 6... Línea 6...
6
const Test = (props) => {
6
const Test = (props) => {
7
 
7
 
-
 
8
    //init states 
8
    //init states 
9
    const [success, setSuccess] = useState(false);
-
 
10
    const [error, setError] = useState(false);
9
    const [success, setSuccess] = useState(false);
11
    const [draft, setDraft] = useState(false);
Línea 10... Línea 12...
10
    const [draft, setDraft] = useState(false);
12
    const [answers, setAnswers] = useState(0);
11
    const [page, setPage] = useState(0);
13
    const [page, setPage] = useState(0);
Línea 12... Línea 14...
12
 
14
 
13
    // get props
15
    // get props
14
    const { backendVars, test, loading, setTest, action } = props;
16
    const { backendVars, test, loading, setTest, action } = props;
15
 
17
 
-
 
18
    /**
-
 
19
     * Send form data
16
    /**
20
     */
17
     * Send form data
21
    const handleSubmit = async () => {
18
     */
22
 
-
 
23
 
-
 
24
        //set states
-
 
25
        setDraft(false);
19
    const handleSubmit = async () => {
26
        setSuccess(false);
20
        //init form data
27
        setError(false);
21
        setDraft(false);
28
 
22
        setSuccess(false);
-
 
23
        const formData = new FormData();
-
 
24
        formData.append("content", JSON.stringify(test.content));
-
 
25
        formData.append("status", validateForm() ? backendVars.STATUS_PENDING : backendVars.STATUS_DRAFT);
-
 
Línea -... Línea 29...
-
 
29
        // set form data
-
 
30
        const formData = new FormData();
-
 
31
        formData.append("content", JSON.stringify(test.content));
-
 
32
        formData.append("status", validateForm() ? backendVars.STATUS_PENDING : backendVars.STATUS_DRAFT);
-
 
33
 
-
 
34
        // check if the form has at least one response
-
 
35
        answers != 0 ?
26
        await axios.post(action, formData).then((response) =>
36
            await axios.post(action, formData).then((response) =>
-
 
37
                response.data.success && validateForm() ?
-
 
38
                    setSuccess(true) :
27
            response.data.success && validateForm() ?
39
                    setDraft(true)
Línea 28... Línea 40...
28
                setSuccess(true) :
40
 
29
                setDraft(true)
41
            )
30
 
42
            : setError(true)
31
        );
43
 
32
    }
44
    }
33
 
45
 
-
 
46
    /**
34
    /**
47
     * Check if there are questions to answer
35
     * Check if there are questions to answer
48
     * @returns 
36
     * @returns 
49
     */
37
     */
50
    const validateForm = () => {
38
    const validateForm = () => {
51
        let formValid = true;
39
        let formValid = true;
52
        setAnswers(0);
-
 
53
        test.content.map((section) => {
40
        test.content.map((section) => {
54
            section.questions.map((question) => {
41
            section.questions.map((question) => {
55
                //Validate if the answer is empty
42
                //Validate if the answer is empty
56
                !question.answer || question.answer.length == 0 ?
43
                if (!question.answer || question.answer.length == 0) {
57
                    formValid = false :
Línea 126... Línea 140...
126
                                            </button>
140
                                            </button>
127
                                        </div>
141
                                        </div>
128
                                    </div>
142
                                    </div>
129
                                </div>
143
                                </div>
130
                            }
144
                            }
-
 
145
 
-
 
146
                            {error &&
-
 
147
 
-
 
148
                                <div className="col-md-12 col-sm-12 col-xs-12">
-
 
149
                                    <div className="company-title">
-
 
150
                                        <div className="alert alert-danger alert-dismissible fade show" role="alert" >
-
 
151
                                            {backendVars.LBL_ERROR_ANSWER_FORM}
-
 
152
                                            <button
-
 
153
                                                type="button"
-
 
154
                                                className="close"
-
 
155
                                                data-dismiss="alert" aria-label="Close"
-
 
156
                                                onClick={() => setError(false)}
-
 
157
 
-
 
158
                                            >
-
 
159
                                                <span aria-hidden="true">&times;</span>
-
 
160
                                            </button>
-
 
161
                                        </div>
-
 
162
                                    </div>
-
 
163
                                </div>
-
 
164
                            }
-
 
165
 
-
 
166
 
131
                            <div className="col-md-12 col-sm-12 col-xs-12 text-right">
167
                            <div className="col-md-12 col-sm-12 col-xs-12 text-right">
132
                                <div className="company-title">
168
                                <div className="company-title">
133
                                    <button
169
                                    <button
134
                                        type="button"
170
                                        type="button"
135
                                        className="btn btn-secondary"
171
                                        className="btn btn-secondary"