Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
276 geraldo 1
import React, { useEffect, useState } from "react";
2
import { axios } from '../../utils';
306 geraldo 3
import List from "./list/List";
4
import Test from "./test/Test";
301 geraldo 5
import Search from "../../shared/search/Search";
6
import Breadcrumbs from "../../shared/breadcrumbs/Breadcrumbs"
276 geraldo 7
 
8
const SelfEvaluation = (props) => {
283 geraldo 9
 
285 geraldo 10
 
282 geraldo 11
    // get props
12
    const { backendVars } = props;
285 geraldo 13
 
276 geraldo 14
    /**
15
     * Init States
16
     */
305 geraldo 17
    const [data, setData] = useState([]);
340 geraldo 18
    const [action, setAction] = useState();
301 geraldo 19
    const [test, setTest] = useState();
276 geraldo 20
    const [loading, setLoading] = useState(true);
21
 
22
    /**
23
     * Get All self evaluation tests
24
     */
282 geraldo 25
    const fetchData = async (searchParam = '') => {
26
        setLoading(true);
341 geraldo 27
        await axios.get(
340 geraldo 28
            "/profile/self-evaluation?search=" + searchParam)
285 geraldo 29
            .then((response) => {
30
                if (response.data.success) {
305 geraldo 31
                    setData(response.data.data);
285 geraldo 32
                }
33
            });
276 geraldo 34
        setLoading(false);
285 geraldo 35
    };
282 geraldo 36
 
301 geraldo 37
    /**
38
     * get info test
39
     * @param {*} url
40
     */
41
    const getTestByUrl = async (url) => {
341 geraldo 42
        await axios.get(url)
301 geraldo 43
            .then((response) => {
573 geraldo 44
                if (response.data.success) {
340 geraldo 45
                    setAction(url);
301 geraldo 46
                    setTest(response.data.data);
47
                }
48
            });
49
    };
285 geraldo 50
 
276 geraldo 51
    /**
305 geraldo 52
     * Search data
282 geraldo 53
     * @param {*} e
54
     */
55
    const handleSearch = async (e) => fetchData(e);
56
 
57
    /**
276 geraldo 58
     * componentDidMount
59
     */
60
    useEffect(() => {
282 geraldo 61
        fetchData();
340 geraldo 62
    }, [test]);
276 geraldo 63
 
64
    return (
65
        <section className="companies-info">
302 geraldo 66
            {!test ? (
301 geraldo 67
                <div className="container">
68
                    <div className="row">
69
                        <Breadcrumbs title={backendVars.LBL_SELF_EVALUATION} />
276 geraldo 70
                    </div>
301 geraldo 71
                    <div className="row">
72
                        <Search handleSearch={handleSearch} backendVars={backendVars} />
276 geraldo 73
                    </div>
305 geraldo 74
                    <div className="row">
75
                        <List
76
                            data={data}
77
                            getTestByUrl={getTestByUrl}
78
                            backendVars={backendVars}
79
                            loading={loading}
80
                        />
301 geraldo 81
                    </div>
82
                </div>
305 geraldo 83
            ) : (
306 geraldo 84
                <div className="container">
85
                    <Test
86
                        backendVars={backendVars}
87
                        loading={loading}
88
                        setTest={setTest}
340 geraldo 89
                        test={test}
341 geraldo 90
                        action={action}
91
                    />
306 geraldo 92
                </div>
301 geraldo 93
            )}
276 geraldo 94
        </section>
95
 
96
    );
97
};
98
 
99
export default SelfEvaluation;