Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ApplyForAd.js 5.2KB

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