Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 591 Rev 625
Línea 1... Línea 1...
1
import React, { useState, useEffect } from "react";
1
import React, { useState, useEffect } from "react";
2
import { axios } from '../../../utils';
2
import { axios } from '../../../utils';
3
import Section from "./section/Section";
3
import Section from "./section/Section";
4
import Spinner from "../../../shared/loading-spinner/Spinner";
4
import Spinner from "../../../shared/loading-spinner/Spinner";
-
 
5
import ConfirmModal from "../../../shared/confirm-modal/ConfirmModal";
Línea 5... Línea 6...
5
 
6
 
Línea 6... Línea 7...
6
const Test = (props) => {
7
const Test = (props) => {
-
 
8
 
7
 
9
    //init states 
8
    //init states 
10
    const [confirmModalShow, setConfirmModalShow] = useState(true);
9
    const [success, setSuccess] = useState(false);
11
    const [success, setSuccess] = useState(false);
10
    const [error, setError] = useState(false);
12
    const [error, setError] = useState(false);
Línea 20... Línea 22...
20
    const handleSubmit = async () => {
22
    const handleSubmit = async () => {
21
        //set states
23
        //set states
22
        setDraft(false);
24
        setDraft(false);
23
        setSuccess(false);
25
        setSuccess(false);
24
        setError(false);
26
        setError(false);
-
 
27
        // check if the form has at least one response
-
 
28
        if (leastOneAnswer()) {
-
 
29
            sendData();
-
 
30
        } else {
-
 
31
            setError(true);
-
 
32
        }
-
 
33
    }
-
 
34
    
-
 
35
 
-
 
36
    const sendData = async () => {
25
        // set form data
37
        // set form data
26
        const formData = new FormData();
38
        const formData = new FormData();
27
        formData.append("content", JSON.stringify(test.content));
39
        formData.append("content", JSON.stringify(test.content));
28
        formData.append("status",
40
        formData.append("status",
29
            formCompleted() ?
41
            formCompleted() ?
30
                backendVars.STATUS_PENDING :
42
                backendVars.STATUS_PENDING :
31
                backendVars.STATUS_DRAFT);
43
                backendVars.STATUS_DRAFT);
32
        // check if the form has at least one response
-
 
33
        if (leastOneAnswer()) {
-
 
34
            await axios.post(action, formData).then((response) => {
44
        await axios.post(action, formData).then((response) => {
35
                if (response.data.success) {
45
            if (response.data.success) {
36
                    formCompleted() ?
46
                formCompleted() ?
37
                        setSuccess(true) :
47
                    setSuccess(true) :
38
                        setDraft(true)
48
                    setDraft(true)
39
                }
-
 
40
            })
49
            }
41
        } else {
-
 
42
            setError(true);
-
 
43
        }
50
        })
44
    }
51
    }
-
 
52
 
-
 
53
 
-
 
54
 
-
 
55
 
45
    /**
56
    /**
46
     * Check if there are options to answer
57
     * Check if there are options to answer
47
     * @returns 
58
     * @returns 
48
     */
59
     */
49
    const formCompleted = () => {
60
    const formCompleted = () => {
Línea 99... Línea 110...
99
     */
110
     */
100
    useEffect(() => {
111
    useEffect(() => {
101
        setPage(0);
112
        setPage(0);
102
    }, [action]);
113
    }, [action]);
Línea -... Línea 114...
-
 
114
 
-
 
115
    /**
-
 
116
     * Click cancel modal
-
 
117
     * @returns 
-
 
118
     */
-
 
119
    const handleConfirmModalShow = () => setConfirmModalShow(!confirmModalShow);
-
 
120
 
-
 
121
 
-
 
122
    /**
-
 
123
     * Click accept modal
-
 
124
     * @returns 
-
 
125
     */
-
 
126
     const handleConfirmModalAccept = async () => sendData();
-
 
127
 
-
 
128
    
103
 
129
 
104
    return (
130
    return (
105
        <div>
131
        <div>
106
            {loading ? (
132
            {loading ? (
107
                <div className="row">
133
                <div className="row">
Línea 110... Línea 136...
110
            ) : (
136
            ) : (
111
                <div>
137
                <div>
112
                    {!success ? (
138
                    {!success ? (
113
                        <div className="row test-section">
139
                        <div className="row test-section">
Línea -... Línea 140...
-
 
140
 
-
 
141
                            <ConfirmModal
-
 
142
                                show={confirmModalShow}
-
 
143
                                onClose={handleConfirmModalShow}
-
 
144
                                onAccept={handleConfirmModalAccept}
-
 
145
                            />
114
 
146
 
115
                            <div className="col-md-12 col-sm-12 col-xs-12">
147
                            <div className="col-md-12 col-sm-12 col-xs-12">
116
                                <div className="company-title">
148
                                <div className="company-title">
117
                                    <div className="section_admin_title_buttons">
149
                                    <div className="section_admin_title_buttons">
118
                                        <h1 className="title">{test.name}</h1>
150
                                        <h1 className="title">{test.name}</h1>