94 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-06-07 17:48:07 +03:00
import React, { useState, useEffect } from 'react';
2021-06-30 17:21:55 +03:00
import { useDispatch, useSelector } from 'react-redux';
2021-06-01 15:25:01 +03:00
import Outstaffing from '../Outstaffing/Outstaffing';
import Description from '../Description/Description';
2021-06-02 18:25:25 +03:00
import front from '../../images/front_end.png';
import back from '../../images/back_end.png';
import design from '../../images/design.png';
2021-06-29 17:58:15 +03:00
import { fetchProfile, fetchSkills } from '../../server/server';
2021-06-30 17:21:55 +03:00
import { profiles, selectProfiles, tags, candidates, selectCandidates, selectTab } from '../../redux/outstaffingSlice';
2021-06-07 17:48:07 +03:00
2021-06-29 17:58:15 +03:00
const Home = ({ getCandidate }) => {
2021-06-30 17:21:55 +03:00
const [count, setCount] = useState(2);
2021-06-03 17:15:22 +03:00
2021-06-30 17:21:55 +03:00
const dispatch = useDispatch();
const profilesArr = useSelector(selectProfiles);
const candidatesArr = useSelector(selectCandidates);
const selectedTab = useSelector(selectTab);
2021-06-28 17:57:28 +03:00
2021-06-30 17:21:55 +03:00
useEffect(() => {
2021-06-29 17:58:15 +03:00
fetchProfile('https://guild.craft-group.xyz/api/profile')
2021-06-30 17:21:55 +03:00
.then((profileArr) => dispatch(profiles(profileArr)))
2021-06-29 17:58:15 +03:00
.catch((e) => console.log(e));
2021-06-30 17:21:55 +03:00
fetchSkills('https://guild.craft-group.xyz/api/skills/skills-on-main-page').then((skills) => {
const keys = Object.keys(skills);
const values = Object.values(skills);
const tempTags = values.map((value, index) =>
value.map((val) => {
return { id: val.id, value: val.tags, name: keys[index] };
})
);
dispatch(tags(tempTags));
});
}, [dispatch]);
2021-06-28 17:57:28 +03:00
2021-06-07 17:48:07 +03:00
useEffect(() => {
2021-06-30 17:21:55 +03:00
dispatch(
candidates(
profilesArr.map((profile) => {
2021-06-29 17:58:15 +03:00
let skillsName = '';
let img;
2021-06-30 17:21:55 +03:00
let header;
2021-06-14 17:47:37 +03:00
2021-06-29 17:58:15 +03:00
if (Number(profile.position_id) === 1) {
skillsName = 'Frontend';
img = front;
2021-06-30 17:21:55 +03:00
header = 'Фронтенд';
2021-06-29 17:58:15 +03:00
} else if (Number(profile.position_id) === 2) {
skillsName = 'Backend';
img = back;
2021-06-30 17:21:55 +03:00
header = 'Бэкенд';
2021-06-29 17:58:15 +03:00
} else if (Number(profile.position_id) === 3) {
skillsName = 'Marketer';
img = design;
2021-06-30 17:21:55 +03:00
header = 'Дизайн';
2021-06-29 17:58:15 +03:00
}
2021-06-22 18:00:52 +03:00
2021-06-29 17:58:15 +03:00
return {
id: profile.id,
profileId: profile.position_id,
name: profile.fio,
skills: profile.skillValues,
2021-06-30 17:21:55 +03:00
skillsName,
img,
header,
2021-06-29 17:58:15 +03:00
};
})
2021-06-30 17:21:55 +03:00
)
);
}, [profilesArr, dispatch]);
2021-06-15 17:08:06 +03:00
2021-06-30 17:21:55 +03:00
const shorthandArray = candidatesArr.slice(0, count);
2021-06-29 17:58:15 +03:00
const loadMore = (count) => {
2021-06-30 17:21:55 +03:00
setCount((prev) => prev + count);
2021-06-03 17:15:22 +03:00
};
2021-06-07 17:48:07 +03:00
2021-05-26 13:35:57 +03:00
return (
2021-05-26 15:59:00 +03:00
<>
2021-06-30 17:21:55 +03:00
<Outstaffing selected={selectedTab} candidatesArray={candidatesArr} />
2021-06-07 17:48:07 +03:00
<Description
2021-06-29 17:58:15 +03:00
candidatesListArr={
2021-06-30 17:21:55 +03:00
selectedTab ? candidatesArr.filter((item) => item.skillsName === selectedTab) : shorthandArray
2021-06-29 17:58:15 +03:00
}
getCandidate={getCandidate}
onLoadMore={loadMore}
2021-06-07 17:48:07 +03:00
/>
2021-05-26 15:59:00 +03:00
</>
2021-05-26 13:35:57 +03:00
);
};
export default Home;