Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ApplyForAd.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import React, { useState } from "react";
  2. import ApplyForAdFirstStage from "./ApplyForAdFirstStage";
  3. import PropTypes from "prop-types";
  4. import briefcaseIcon from "../../assets/images/briefcase1.png";
  5. import xIcon from "../../assets/images/x.png";
  6. import CustomModal from "../UI/CustomModal";
  7. import ApplyForAdSecondStage from "./ApplyForAdSecondStage";
  8. import { setTechnologiesReq } from "../../store/actions/technologies/technologiesActions";
  9. import { selectTechnologies } from "../../store/selectors/technologiesSelectors";
  10. import { useDispatch, useSelector } from "react-redux";
  11. import { useEffect } from "react";
  12. import ApplyForAdThirdStage from "./ApplyForAdThirdStage";
  13. import ApplyForAdFourthStage from "./ApplyForAdFourthStage";
  14. import { applyForAdReq } from "../../store/actions/applyForAd/applyForAdActions";
  15. import { useHistory } from "react-router-dom";
  16. import { ADS_PAGE } from "../../constants/pages";
  17. import { useTranslation } from "react-i18next";
  18. const ApplyForAd = ({ open, title, adId, onCloseModal }) => {
  19. const [stage, setStage] = useState(1);
  20. const [firstName, setFirstName] = useState("");
  21. const [lastName, setLastName] = useState("");
  22. const [gender, setGender] = useState("");
  23. const [dateOfBirth, setDateOfBirth] = useState("");
  24. const [phoneNumber, setPhoneNumber] = useState("");
  25. const [mappedTechnologies, setMappedTechnologies] = useState([]);
  26. const [experience, setExperience] = useState(0);
  27. const [professionalQualification, setProfessionalQualification] =
  28. useState("");
  29. const [linkedinLink, setLinkedinLink] = useState("");
  30. const [githubLink, setGithubLink] = useState("");
  31. const [email, setEmail] = useState("");
  32. const [bitBucketLink, setBitBucketLink] = useState("");
  33. const [coverLetter, setCoverLetter] = useState("");
  34. const [pdfFile, setPdfFile] = useState(null);
  35. const technologies = useSelector(selectTechnologies);
  36. const dispatch = useDispatch();
  37. const history = useHistory();
  38. const { t } = useTranslation();
  39. useEffect(() => {
  40. dispatch(setTechnologiesReq());
  41. }, []);
  42. useEffect(() => {
  43. if (technologies && technologies.length > 0) {
  44. const tech = technologies.map((t) => ({ ...t, isChecked: false }));
  45. setMappedTechnologies(tech);
  46. }
  47. }, [technologies]);
  48. const increaseStageHandler = () => {
  49. setStage((oldValue) => oldValue + 1);
  50. };
  51. const decreaseStageHandler = () => {
  52. setStage((oldValue) => oldValue - 1);
  53. };
  54. const handleApiResponseSuccess = () => {
  55. onCloseModal();
  56. history.push(ADS_PAGE);
  57. };
  58. const finishedFourStagesHandler = () => {
  59. const technologiesIds = mappedTechnologies
  60. .filter((tech) => tech.isChecked === true)
  61. .map((x) => x.technologyId);
  62. dispatch(
  63. applyForAdReq({
  64. adId,
  65. firstName,
  66. lastName,
  67. gender,
  68. dateOfBirth,
  69. phoneNumber,
  70. technologiesIds,
  71. experience,
  72. professionalQualification,
  73. linkedinLink,
  74. githubLink,
  75. bitBucketLink,
  76. email,
  77. coverLetter,
  78. pdfFile,
  79. handleApiResponseSuccess,
  80. })
  81. );
  82. };
  83. return (
  84. <CustomModal open={open} onCloseModal={onCloseModal} classes="apply-for-job">
  85. <div className="apply-for-job-header">
  86. <div className="apply-for-job-header-left">
  87. <div className="apply-for-job-header-left-image">
  88. <img src={briefcaseIcon} alt="plus" />
  89. </div>
  90. <div className="apply-for-job-header-left-image-title">
  91. <p>{t("ads.signUp")}</p>
  92. </div>
  93. <div className="apply-for-job-header-left-image-title-sub">
  94. <sub> | {title}</sub>
  95. </div>
  96. </div>
  97. <div className="apply-for-job-header-right">
  98. <button onClick={onCloseModal}>
  99. <img src={xIcon} alt="x" />
  100. </button>
  101. </div>
  102. </div>
  103. {stage === 1 && (
  104. <ApplyForAdFirstStage
  105. onCloseModal={onCloseModal}
  106. firstName={firstName}
  107. setFirstName={setFirstName}
  108. lastName={lastName}
  109. setLastName={setLastName}
  110. gender={gender}
  111. setGender={setGender}
  112. dateOfBirth={dateOfBirth}
  113. setDateOfBirth={setDateOfBirth}
  114. phoneNumber={phoneNumber}
  115. setPhoneNumber={setPhoneNumber}
  116. onIncreaseStage={increaseStageHandler}
  117. />
  118. )}
  119. {stage === 2 && (
  120. <ApplyForAdSecondStage
  121. technologies={mappedTechnologies}
  122. setTechnologies={setMappedTechnologies}
  123. experience={experience}
  124. professionalQualification={professionalQualification}
  125. setProfessionalQualification={setProfessionalQualification}
  126. setExperience={setExperience}
  127. onIncreaseStage={increaseStageHandler}
  128. onDecreaseStage={decreaseStageHandler}
  129. />
  130. )}
  131. {stage === 3 && (
  132. <ApplyForAdThirdStage
  133. linkedinLink={linkedinLink}
  134. setLinkedinLink={setLinkedinLink}
  135. githubLink={githubLink}
  136. setGithubLink={setGithubLink}
  137. bitBucketLink={bitBucketLink}
  138. setBitBucketLink={setBitBucketLink}
  139. email={email}
  140. setEmail={setEmail}
  141. onIncreaseStage={increaseStageHandler}
  142. onDecreaseStage={decreaseStageHandler}
  143. />
  144. )}
  145. {stage === 4 && (
  146. <ApplyForAdFourthStage
  147. pdfFile={pdfFile}
  148. coverLetter={coverLetter}
  149. setCoverLetter={setCoverLetter}
  150. setPdfFile={setPdfFile}
  151. onDecreaseStage={decreaseStageHandler}
  152. onFinishedFourStages={finishedFourStagesHandler}
  153. />
  154. )}
  155. </CustomModal>
  156. );
  157. };
  158. ApplyForAd.propTypes = {
  159. open: PropTypes.bool,
  160. title: PropTypes.string,
  161. adId: PropTypes.string,
  162. onCloseModal: PropTypes.func,
  163. };
  164. export default ApplyForAd;