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