import React, { useState } from "react"; import ApplyForAdFirstStage from "./ApplyForAdFirstStage"; import PropTypes from "prop-types"; import briefcaseIcon from "../../assets/images/briefcase1.png"; import xIcon from "../../assets/images/x.png"; import CustomModal from "../UI/CustomModal"; import ApplyForAdSecondStage from "./ApplyForAdSecondStage"; import { setTechnologiesReq } from "../../store/actions/technologies/technologiesActions"; import { selectTechnologies } from "../../store/selectors/technologiesSelectors"; import { useDispatch, useSelector } from "react-redux"; import { useEffect } from "react"; import ApplyForAdThirdStage from "./ApplyForAdThirdStage"; import ApplyForAdFourthStage from "./ApplyForAdFourthStage"; import { applyForAdReq } from "../../store/actions/applyForAd/applyForAdActions"; import { useHistory } from "react-router-dom"; import { ADS_PAGE } from "../../constants/pages"; import { useTranslation } from "react-i18next"; const ApplyForAd = ({ open, title, adId, onCloseModal }) => { const [stage, setStage] = useState(1); const [firstName, setFirstName] = useState(""); const [lastName, setLastName] = useState(""); const [gender, setGender] = useState(""); const [dateOfBirth, setDateOfBirth] = useState(""); const [phoneNumber, setPhoneNumber] = useState(""); const [mappedTechnologies, setMappedTechnologies] = useState([]); const [experience, setExperience] = useState(0); const [professionalQualification, setProfessionalQualification] = useState(""); const [linkedinLink, setLinkedinLink] = useState(""); const [githubLink, setGithubLink] = useState(""); const [email, setEmail] = useState(""); const [bitBucketLink, setBitBucketLink] = useState(""); const [coverLetter, setCoverLetter] = useState(""); const [pdfFile, setPdfFile] = useState(null); const technologies = useSelector(selectTechnologies); const dispatch = useDispatch(); const history = useHistory(); const { t } = useTranslation(); useEffect(() => { dispatch(setTechnologiesReq()); }, []); useEffect(() => { if (technologies && technologies.length > 0) { const tech = technologies.map((t) => ({ ...t, isChecked: false })); setMappedTechnologies(tech); } }, [technologies]); const increaseStageHandler = () => { setStage((oldValue) => oldValue + 1); }; const decreaseStageHandler = () => { setStage((oldValue) => oldValue - 1); }; const handleApiResponseSuccess = () => { onCloseModal(); history.push(ADS_PAGE); }; const finishedFourStagesHandler = () => { const technologiesIds = mappedTechnologies .filter((tech) => tech.isChecked === true) .map((x) => x.technologyId); dispatch( applyForAdReq({ adId, firstName, lastName, gender, dateOfBirth, phoneNumber, technologiesIds, experience, professionalQualification, linkedinLink, githubLink, bitBucketLink, email, coverLetter, pdfFile, handleApiResponseSuccess, }) ); }; return (
plus

{t("ads.signUp")}

| {title}
{stage === 1 && ( )} {stage === 2 && ( )} {stage === 3 && ( )} {stage === 4 && ( )}
); }; ApplyForAd.propTypes = { open: PropTypes.bool, title: PropTypes.string, adId: PropTypes.string, onCloseModal: PropTypes.func, }; export default ApplyForAd;