source: jobvista-frontend/src/views/applications/ApplyToJobAdModal.js@ b248810

main
Last change on this file since b248810 was 28b3398, checked in by 223021 <daniel.ilievski.2@…>, 3 weeks ago

Implemented job application functionality, added job advertisement filtering and replaced text areas with editors

  • Property mode set to 100644
File size: 5.5 KB
Line 
1import React, {useState} from "react";
2import "../job_advertisements/Form.css";
3
4import 'react-responsive-modal/styles.css';
5import {Modal} from 'react-responsive-modal';
6import Select from "react-select";
7
8//Validation
9import * as yup from "yup";
10import {yupResolver} from "@hookform/resolvers/yup";
11import {Controller, useForm} from "react-hook-form";
12
13
14import {employmentStatusOptions, industryOptions, jobTypeOptions} from "../selectOptions";
15import {useDispatch, useSelector} from "react-redux";
16import {JobAdvertisementActions} from "../../redux/actions/jobAdvertisementActions";
17import Roles from "../../enumerations/Roles";
18import {ApplicationActions} from "../../redux/actions/applicationActions";
19
20
21export 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}
Note: See TracBrowser for help on using the repository browser.