[28b3398] | 1 | import React, {useState} from "react";
|
---|
| 2 | import "../job_advertisements/Form.css";
|
---|
| 3 |
|
---|
| 4 | import 'react-responsive-modal/styles.css';
|
---|
| 5 | import {Modal} from 'react-responsive-modal';
|
---|
| 6 | import Select from "react-select";
|
---|
| 7 |
|
---|
| 8 | //Validation
|
---|
| 9 | import * as yup from "yup";
|
---|
| 10 | import {yupResolver} from "@hookform/resolvers/yup";
|
---|
| 11 | import {Controller, useForm} from "react-hook-form";
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | import {employmentStatusOptions, industryOptions, jobTypeOptions} from "../selectOptions";
|
---|
| 15 | import {useDispatch, useSelector} from "react-redux";
|
---|
| 16 | import {JobAdvertisementActions} from "../../redux/actions/jobAdvertisementActions";
|
---|
| 17 | import Roles from "../../enumerations/Roles";
|
---|
| 18 | import {ApplicationActions} from "../../redux/actions/applicationActions";
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | export const ApplyToJobAdModal = (props) => {
|
---|
| 22 | const {jobAd, role} = props
|
---|
| 23 | const [modal, setModal] = useState(false);
|
---|
| 24 | const dispatch = useDispatch();
|
---|
| 25 | const auth = useSelector(state => state.auth.currentUser)
|
---|
| 26 |
|
---|
| 27 | const [resumeFile, setResumeFile] = useState(null);
|
---|
| 28 | const toggleModal = () => {
|
---|
| 29 | setModal(!modal);
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | const schema = yup.object().shape({
|
---|
| 33 | answerOne: yup.string().required("Please answer the question"),
|
---|
| 34 | answerTwo: yup.string().required("Please answer the question"),
|
---|
| 35 | answerThree: yup.string().required("Please answer the question"),
|
---|
| 36 | messageToRecruiter: yup.string(),
|
---|
| 37 | })
|
---|
| 38 |
|
---|
| 39 | const {register, handleSubmit, control, formState: {errors}} = useForm({
|
---|
| 40 | resolver: yupResolver(schema),
|
---|
| 41 | });
|
---|
| 42 |
|
---|
| 43 | const submitApplication = async (values) => {
|
---|
| 44 | try {
|
---|
| 45 | const formData = new FormData();
|
---|
| 46 | formData.append('jobSeekerId', auth.id);
|
---|
| 47 | formData.append('jobAdId', jobAd.id);
|
---|
| 48 | formData.append('resumeFile', resumeFile);
|
---|
| 49 | formData.append('answerOne', values.answerOne);
|
---|
| 50 | formData.append('answerTwo', values.answerTwo);
|
---|
| 51 | formData.append('answerThree', values.answerThree);
|
---|
| 52 | formData.append('messageToRecruiter', values.messageToRecruiter);
|
---|
| 53 |
|
---|
| 54 | dispatch(ApplicationActions.submitApplication(
|
---|
| 55 | formData,(success, response) => {
|
---|
| 56 | if(success) {
|
---|
| 57 | console.log("Job Advertisement added")
|
---|
| 58 | toggleModal()
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | ))
|
---|
| 62 | } catch (err) {
|
---|
| 63 | console.error(err)
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | let minimumDate = new Date();
|
---|
| 67 | minimumDate.setDate(minimumDate.getDate() + 1);
|
---|
| 68 |
|
---|
| 69 | return (<div className="modal-wrap">
|
---|
| 70 | {role===Roles.JOBSEEKER &&
|
---|
| 71 | <>
|
---|
| 72 | {jobAd.active && <button onClick={toggleModal} className="card-button apply">Apply now</button> }
|
---|
| 73 | {!jobAd.active && <button className="card-button apply disabled">Apply now</button> }
|
---|
| 74 | </>
|
---|
| 75 | }
|
---|
| 76 | <Modal open={modal} onClose={toggleModal} center >
|
---|
| 77 | <div className="head-modal">
|
---|
| 78 | <h3>Applying to {jobAd.title} at {jobAd.recruiterName}</h3>
|
---|
| 79 | <i className="fa-solid fa-x btn-close-modal" onClick={toggleModal}></i>
|
---|
| 80 | </div>
|
---|
| 81 |
|
---|
| 82 | <div className="modal-content" >
|
---|
| 83 | <form onSubmit={handleSubmit(submitApplication)}>
|
---|
| 84 | <div className="row">
|
---|
| 85 | <div className="col-md-6">
|
---|
| 86 | <label className="label">Why are you interested in joining our company?</label>
|
---|
| 87 | <textarea type="text" placeholder="Write your answer here..."
|
---|
| 88 | {...register("answerOne")} className="applictaion-textarea"/>
|
---|
| 89 | <p style={{color: "red"}}>{errors.answerOne?.message}</p>
|
---|
| 90 |
|
---|
| 91 | <label className="label">What makes you a good fit for this position?</label>
|
---|
| 92 | <textarea type="text" placeholder="Write your answer here..."
|
---|
| 93 | {...register("answerTwo")} className="applictaion-textarea"/>
|
---|
| 94 | <p style={{color: "red"}}>{errors.answerTwo?.message}</p>
|
---|
| 95 |
|
---|
| 96 | <label className="label">What do you hope to achieve in your first 6 months in this role?</label>
|
---|
| 97 | <textarea type="text" placeholder="Write your answer here..."
|
---|
| 98 | {...register("answerThree")} className="applictaion-textarea"/>
|
---|
| 99 | <p style={{color: "red"}}>{errors.answerThree?.message}</p>
|
---|
| 100 |
|
---|
| 101 | </div>
|
---|
| 102 | <div className="col-md-6">
|
---|
| 103 | <label htmlFor="start">Curriculum vitae (CV)</label>
|
---|
| 104 | <br/>
|
---|
| 105 | <input {...register("file")} onChange={(e) => setResumeFile(e.target.files[0])} required type="file" id="fileUpload" accept=".pdf"/>
|
---|
| 106 |
|
---|
| 107 | <br/>
|
---|
| 108 | <label className="label">Message to the recruiter</label>
|
---|
| 109 | <textarea type="text" placeholder="Optional..."
|
---|
| 110 | {...register("messageToRecruiter")} className="applictaion-textarea"/>
|
---|
| 111 |
|
---|
| 112 | <br/><br/>
|
---|
| 113 | <p style={{color: "red"}}>Please note that your personal data from your account will be used to identify and process your application.</p>
|
---|
| 114 | </div>
|
---|
| 115 | </div>
|
---|
| 116 |
|
---|
| 117 | <div className="aligned">
|
---|
| 118 | <button className="submit-btn"> Submit</button>
|
---|
| 119 | </div>
|
---|
| 120 |
|
---|
| 121 | </form>
|
---|
| 122 | </div>
|
---|
| 123 | </Modal>
|
---|
| 124 | </div>)
|
---|
| 125 | } |
---|