您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AdsCandidatesPage.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import React, { useEffect } from "react";
  2. import arrow_left from "../../assets/images/arrow_left.png";
  3. import arrow_right from "../../assets/images/arrow_right.png";
  4. import adImage from "../../assets/images/.net_icon.png";
  5. import Slider from "react-slick";
  6. import useDynamicRefs from "use-dynamic-refs";
  7. import { fetchAdsCandidates } from "../../store/actions/candidates/candidatesActions";
  8. import { useDispatch, useSelector } from "react-redux";
  9. import CandidateCard from "../../components/Candidates/CandidateCard";
  10. import PropTypes from "prop-types";
  11. import { useTheme } from "@mui/system";
  12. import { useMediaQuery } from "@mui/material";
  13. import { selectAdsCandidates } from "../../store/selectors/candidatesSelectors";
  14. import { useTranslation } from "react-i18next";
  15. const AdsCandidatesPage = ({ history, search }) => {
  16. const dispatch = useDispatch();
  17. const adsCandidates = useSelector(selectAdsCandidates);
  18. const [getRef, setRef] = useDynamicRefs();
  19. const theme = useTheme();
  20. const matches = useMediaQuery(theme.breakpoints.down("361"));
  21. const {t} = useTranslation()
  22. useEffect(() => {
  23. dispatch(
  24. fetchAdsCandidates({
  25. currentPage: 0,
  26. pageSize: 0,
  27. minExperience: 0,
  28. maxExperience: 0,
  29. employmentType: "",
  30. minDateOfApplication: "",
  31. maxDateOfApplication: "",
  32. technologies: [],
  33. })
  34. );
  35. }, [dispatch]);
  36. var settings = {
  37. dots: false,
  38. infinite: false,
  39. speed: 400,
  40. slidesToShow: 3,
  41. slidesToScroll: 3,
  42. initialSlide: 0,
  43. arrows: true,
  44. variableWidth: true,
  45. responsive: [
  46. {
  47. breakpoint: 1024,
  48. settings: {
  49. slidesToShow: 2,
  50. slidesToScroll: 2,
  51. infinite: true,
  52. dots: false,
  53. },
  54. },
  55. {
  56. breakpoint: 900,
  57. settings: {
  58. slidesToShow: 1,
  59. slidesToScroll: 1,
  60. initialSlide: 0,
  61. },
  62. },
  63. {
  64. breakpoint: 480,
  65. settings: {
  66. slidesToShow: 1,
  67. slidesToScroll: 1,
  68. initialSlide: 0,
  69. },
  70. },
  71. ],
  72. };
  73. const getDummyCandidates = (len) => {
  74. const candidates = [];
  75. for (let i = 0; i < 4 - len + 1; i++) {
  76. candidates.push(
  77. <CandidateCard key={i} className="hiddenAd" history={history} />
  78. );
  79. }
  80. return candidates;
  81. };
  82. const activeAdsArrowLeftHandler = (index) => {
  83. getRef(index.toString()).current.slickPrev();
  84. };
  85. const activeAdsArrowRightHandler = (index) => {
  86. getRef(index.toString()).current.slickNext();
  87. };
  88. const filterByName = (adCandidates) => {
  89. return adCandidates.applicants.filter((candidate) =>
  90. (candidate.firstName + " " + candidate.lastName)
  91. .toLowerCase()
  92. .includes(search.toLowerCase())
  93. );
  94. };
  95. return (
  96. <div className="jobs-candidates-container top-cnd">
  97. {adsCandidates.map((adCandidates, index) => (
  98. <div className="jobs-candidates" key={index}>
  99. <div className="jobs-candidates-top-container">
  100. <img src={adImage} className="jobs-candidates-image" />
  101. <p className="jobs-candidates-title">{adCandidates.title}</p>
  102. <p className="jobs-candidates-numberOfApplicants">
  103. | {adCandidates.nubmerOfApplicants} {t("ads.registered")}
  104. </p>
  105. </div>
  106. <div className="jobs-candidates-slider">
  107. {filterByName(adCandidates).length > 4 && (
  108. <div
  109. className="active-jobs-jobs-arrows"
  110. style={matches ? { marginLeft: 36 } : { marginLeft: 0 }}
  111. >
  112. <button onClick={() => activeAdsArrowLeftHandler(index)}>
  113. <img src={arrow_left} alt="arrow-left" />
  114. </button>
  115. <button
  116. onClick={() => activeAdsArrowRightHandler(index)}
  117. className="kp"
  118. >
  119. <img src={arrow_right} alt="arrow-right" />
  120. </button>
  121. </div>
  122. )}
  123. <Slider
  124. {...settings}
  125. ref={setRef(index.toString())}
  126. className={`left-move-candidateAd-page ${
  127. matches
  128. ? filterByName(adCandidates).length > 4
  129. ? "cls1"
  130. : "cls2"
  131. : filterByName(adCandidates).length > 4
  132. ? "cls3"
  133. : "cls4"
  134. }`}
  135. >
  136. {filterByName(adCandidates).map((candidate, index) => (
  137. <CandidateCard
  138. key={index}
  139. candidate={candidate}
  140. history={history}
  141. />
  142. ))}
  143. {filterByName(adCandidates).length <= 4 &&
  144. getDummyCandidates(adCandidates.applicants.length)}
  145. </Slider>
  146. </div>
  147. </div>
  148. ))}
  149. </div>
  150. );
  151. };
  152. AdsCandidatesPage.propTypes = {
  153. history: PropTypes.shape({
  154. replace: PropTypes.func,
  155. push: PropTypes.func,
  156. location: PropTypes.shape({
  157. pathname: PropTypes.string,
  158. }),
  159. }),
  160. search: PropTypes.string,
  161. };
  162. export default AdsCandidatesPage;