94 lines
2.7 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-07-02 16:02:47 +03:00
import { fetchProfile, fetchSkills } from '../../server/server';
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-07-03 17:37:30 +03:00
// import { profiles, selectProfiles, tags, candidates, selectCandidates, selectTab } from '../../redux/outstaffingSlice';
import { profiles, selectProfiles, tags, candidates } from '../../redux/outstaffingSlice';
2021-06-07 17:48:07 +03:00
2021-07-02 16:02:47 +03:00
const Home = () => {
const [index, setIndex] = 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);
2021-07-02 16:02:47 +03:00
2021-07-03 17:37:30 +03:00
// const candidatesArr = useSelector(selectCandidates);
2021-07-02 16:02:47 +03:00
2021-07-03 17:37:30 +03:00
// const selectedTab = useSelector(selectTab);
2021-06-28 17:57:28 +03:00
2021-06-30 17:21:55 +03:00
useEffect(() => {
2021-07-02 16:02:47 +03:00
fetchProfile(`https://guild.craft-group.xyz/api/profile?limit=`, index)
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));
});
2021-07-02 16:02:47 +03:00
}, [dispatch, index]);
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 = '';
2021-06-30 17:21:55 +03:00
let header;
2021-07-02 16:02:47 +03:00
let img;
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;
} else if (Number(profile.position_id) === 2) {
skillsName = 'Backend';
img = back;
} else if (Number(profile.position_id) === 3) {
skillsName = 'Marketer';
img = design;
}
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-07-02 16:02:47 +03:00
level: profile.level,
2021-07-03 17:37:30 +03:00
text: profile.vc_text,
2021-06-30 17:21:55 +03:00
skillsName,
header,
2021-07-02 16:02:47 +03:00
img,
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-29 17:58:15 +03:00
const loadMore = (count) => {
2021-07-02 16:02:47 +03:00
setIndex((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-07-01 14:25:17 +03:00
<Outstaffing />
2021-07-03 17:37:30 +03:00
{/* <Description
2021-06-29 17:58:15 +03:00
candidatesListArr={
2021-07-02 16:02:47 +03:00
selectedTab ? candidatesArr.filter((item) => item.skillsName === selectedTab) : candidatesArr
2021-06-29 17:58:15 +03:00
}
onLoadMore={loadMore}
2021-07-03 17:37:30 +03:00
/> */}
<Description onLoadMore={loadMore} />
2021-05-26 15:59:00 +03:00
</>
2021-05-26 13:35:57 +03:00
);
};
export default Home;