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

main
Last change on this file was 4d97b63, checked in by 223021 <daniel.ilievski.2@…>, 3 months ago

Implemented Google login, additional file uploads, response messages and email notifications

  • Property mode set to 100644
File size: 5.5 KB
Line 
1import React, {useState} from "react";
2import "../shared_css/Modal.css";
3
4import 'react-responsive-modal/styles.css';
5import {Modal} from 'react-responsive-modal';
6
7//Validation
8import * as yup from "yup";
9import {yupResolver} from "@hookform/resolvers/yup";
10import {Controller, useForm} from "react-hook-form";
11
12
13import {useDispatch, useSelector} from "react-redux";
14import Roles from "../../enumerations/Roles";
15import {ApplicationActions} from "../../redux/actions/applicationActions";
16import {notifyJobAdApply} from "../../utils/toastUtils";
17
18
19export 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(
53 formData, (success) => {
54 if (success) {
55 toggleModal()
56 notifyJobAdApply()
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">
68 {role === Roles.JOBSEEKER &&
69 <>
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>}
72 </>
73 }
74 <Modal open={modal} onClose={toggleModal} center>
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
80 <div className="modal-content">
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..."
86 {...register("answerOne")} className="application-textarea"/>
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..."
91 {...register("answerTwo")} className="application-textarea"/>
92 <p style={{color: "red"}}>{errors.answerTwo?.message}</p>
93
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"/>
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/>
104 <input {...register("file")} className="resume-link"
105 onChange={(e) => setResumeFile(e.target.files[0])} required type="file"
106 id="fileUpload" accept=".pdf"/>
107 <br/>
108 <label className="label">Message to the recruiter</label>
109 <textarea type="text" placeholder="Optional..."
110 {...register("messageToRecruiter")} className="application-textarea"/>
111
112 <br/><br/>
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>
115 </div>
116 </div>
117
118 <div className="modal-buttons">
119 <div className="cancel-btn" onClick={toggleModal}> Cancel</div>
120 <button className="submit-btn"> Submit</button>
121 </div>
122
123 </form>
124 </div>
125 </Modal>
126 </div>)
127}
Note: See TracBrowser for help on using the repository browser.