fix Summary skills

This commit is contained in:
Никита Губарь 2024-07-26 15:22:53 +03:00
parent ca0a509077
commit 9909101660

View File

@ -58,6 +58,25 @@ export const Summary = () => {
});
}, []);
const addSkill = (skill) => {
const isSkillFound = selectedSkills.some(
(item) => item.skill_id == skill.id
);
if (!isSkillFound) {
setSelectedSkills((prevValue) => [
...prevValue,
{ skill: skill, skill_id: skill.id }
]);
}
};
const deleteSkill = (skill) => {
setSelectedSkills((prevValue) =>
prevValue.filter((item) => item.skill_id !== skill.skill_id)
);
};
function setSkills() {
apiRequest("/resume/edit-skills", {
method: "PUT",
@ -157,13 +176,7 @@ export const Summary = () => {
<img
src={deleteIcon}
alt="deleteIcon"
onClick={() =>
setSelectedSkills((prevValue) =>
prevValue.filter(
(item) => item.skill_id !== skill.skill_id
)
)
}
onClick={() => deleteSkill(skill)}
/>
</span>
);
@ -184,12 +197,7 @@ export const Summary = () => {
{skillsList.map((skill) => {
return (
<p
onClick={() =>
setSelectedSkills((prevValue) => [
...prevValue,
{ skill: skill, skill_id: skill.id }
])
}
onClick={() => addSkill(skill)}
key={skill.id}
className="select-skills__item"
>
@ -205,7 +213,7 @@ export const Summary = () => {
<div className="skills__section__items__wrapper">
{selectedSkills &&
selectedSkills.map((skill, index) => (
<span key={skill.id} className="skill_item">
<span key={skill.skill_id} className="skill_item">
{skill.skill.name}
{selectedSkills.length > index + 1 && ","}
</span>