| 8401 |
stevensc |
1 |
import React from "react";
|
|
|
2 |
import { useState, useEffect } from "react";
|
|
|
3 |
import { useForm } from "react-hook-form";
|
|
|
4 |
import TagsInput from "../../../shared/TagsInput";
|
|
|
5 |
import SubmitModal from "./SubmitModal";
|
|
|
6 |
import { getData } from "../../../helpers/fetchHelpers"
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
const CategoryModal = ({
|
|
|
10 |
closeModal,
|
|
|
11 |
dataLink
|
|
|
12 |
}) => {
|
|
|
13 |
|
|
|
14 |
const { register, errors } = useForm();
|
|
|
15 |
|
|
|
16 |
const [degreesSelecteds, setDegreesSelecteds] = useState([]);
|
|
|
17 |
const [userDegreesArray, setUserDegreesArray] = useState([]);
|
|
|
18 |
const [degreesOptionsArray, setDegreesOptionsArray] = useState([]);
|
|
|
19 |
const [data, setData] = useState({ "degrees[]": "" });
|
|
|
20 |
|
|
|
21 |
useEffect(() => {
|
|
|
22 |
getData(dataLink)
|
|
|
23 |
.then(res => console.log(res))
|
|
|
24 |
}, []);
|
|
|
25 |
|
|
|
26 |
/* const handleTagsChange = (tags) => {
|
|
|
27 |
if (tags.length) {
|
|
|
28 |
let newTags = [];
|
|
|
29 |
tags.map((tag) => {
|
|
|
30 |
newTags = [...newTags, tag.value];
|
|
|
31 |
});
|
|
|
32 |
setData({ "degrees[]": newTags });
|
|
|
33 |
} else {
|
|
|
34 |
setData({ "degrees[]": "" });
|
|
|
35 |
}
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
useEffect(() => {
|
|
|
39 |
getData(dataLink)
|
|
|
40 |
.then(({ degrees_available, degrees_selected }) => {
|
|
|
41 |
|
|
|
42 |
// Set languages options
|
|
|
43 |
Object.entries(degrees_available).map(([key, value]) => {
|
|
|
44 |
setDegreesOptionsArray(prev => [...prev, { value: key, name: value }])
|
|
|
45 |
})
|
|
|
46 |
|
|
|
47 |
// Set languages selecteds
|
|
|
48 |
setDegreesSelecteds(degrees_selected)
|
|
|
49 |
})
|
|
|
50 |
}, [dataLink]);
|
|
|
51 |
|
|
|
52 |
useEffect(() => {
|
|
|
53 |
degreesSelecteds.map(skill => {
|
|
|
54 |
const userSkill = degreesOptionsArray.find(el => el.value === skill)
|
|
|
55 |
if (userSkill) {
|
|
|
56 |
setUserDegreesArray(prev => [...prev, { value: userSkill.value, name: userSkill.name }])
|
|
|
57 |
}
|
|
|
58 |
})
|
|
|
59 |
}, [degreesSelecteds, degreesOptionsArray]); */
|
|
|
60 |
|
|
|
61 |
return (
|
|
|
62 |
<SubmitModal
|
|
|
63 |
title="Grados"
|
|
|
64 |
submitData={data}
|
|
|
65 |
postLink={dataLink}
|
|
|
66 |
closeModal={closeModal}
|
|
|
67 |
>
|
|
|
68 |
<div className="form-group">
|
|
|
69 |
{/* <TagsInput
|
|
|
70 |
suggestions={degreesOptionsArray}
|
|
|
71 |
settedTags={userDegreesArray}
|
|
|
72 |
onChange={handleTagsChange}
|
|
|
73 |
/>
|
|
|
74 |
{errors.skills && <p>{errors.skills}</p>} */}
|
|
|
75 |
</div>
|
|
|
76 |
</SubmitModal>
|
|
|
77 |
);
|
|
|
78 |
};
|
|
|
79 |
|
|
|
80 |
export default CategoryModal;
|