1 | import React, {useEffect, useState} from "react";
|
---|
2 | import "../shared_css/Modal.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 | import {notifyJobAdApply, notifyJobAdUpdate} from "../../utils/toastUtils";
|
---|
20 |
|
---|
21 |
|
---|
22 | export const ApplicationDetailsModal = (props) => {
|
---|
23 | const {application} = props
|
---|
24 | const [modal, setModal] = useState(false);
|
---|
25 | const dispatch = useDispatch();
|
---|
26 | const auth = useSelector(state => state.auth.currentUser)
|
---|
27 | const [resumeUrl, setResumeUrl] = useState("");
|
---|
28 | const [additionalFileUrls, setAdditionalFileUrls] = useState([]);
|
---|
29 |
|
---|
30 | const [additionalFiles, setAdditionalFiles] = useState(null);
|
---|
31 | const toggleModal = () => {
|
---|
32 | setModal(!modal);
|
---|
33 | };
|
---|
34 |
|
---|
35 | const {register, handleSubmit, control, formState: {errors}} = useForm();
|
---|
36 |
|
---|
37 | useEffect(() => {
|
---|
38 | if (application) {
|
---|
39 | ApplicationActions.downloadResume(application.id, (success, response) => {
|
---|
40 | if (success) {
|
---|
41 | setResumeUrl(response);
|
---|
42 |
|
---|
43 | if (application.additionalFileNames.length > 0) {
|
---|
44 | ApplicationActions.downloadAdditionalFiles(application.id, (success2, response) => {
|
---|
45 | if (success2) {
|
---|
46 | setAdditionalFileUrls(response);
|
---|
47 | }
|
---|
48 | })
|
---|
49 | }
|
---|
50 | }
|
---|
51 | })
|
---|
52 | }
|
---|
53 | }, [])
|
---|
54 |
|
---|
55 | const updateApplication = async () => {
|
---|
56 | try {
|
---|
57 | const formData = new FormData();
|
---|
58 | if (additionalFiles && additionalFiles.length > 0) {
|
---|
59 | for (let i = 0; i < additionalFiles.length; i++) {
|
---|
60 | formData.append('additionalFiles', additionalFiles[i]);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | dispatch(ApplicationActions.updateApplication(application.id, formData, (success) => {
|
---|
65 | if (success) {
|
---|
66 | toggleModal()
|
---|
67 | window.location.reload()
|
---|
68 | }
|
---|
69 | }))
|
---|
70 | } catch (err) {
|
---|
71 | console.error(err)
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | function getFileName(path) {
|
---|
76 | let fileName = path.split('\\').pop().split('/').pop();
|
---|
77 |
|
---|
78 | fileName = fileName.trim();
|
---|
79 |
|
---|
80 | return fileName;
|
---|
81 | }
|
---|
82 |
|
---|
83 | return (<div className="modal-wrap">
|
---|
84 | {auth.role === Roles.RECRUITER ? <button onClick={toggleModal} className="application-button">View
|
---|
85 | application</button> : (application.status === "UNDER_REVIEW" && application.response.length > 0 && additionalFileUrls.length === 0) ?
|
---|
86 | <button onClick={toggleModal} className="application-button">Update application</button> :
|
---|
87 | <button onClick={toggleModal} className="application-button">View application</button>}
|
---|
88 |
|
---|
89 | <Modal open={modal} onClose={toggleModal} center>
|
---|
90 | <div className="head-modal">
|
---|
91 | <h3>{application.jobSeekerName}'s application for {application.jobAdTitle}</h3>
|
---|
92 | <i className="fa-solid fa-x btn-close-modal" onClick={toggleModal}></i>
|
---|
93 | </div>
|
---|
94 |
|
---|
95 | <div className="modal-content">
|
---|
96 | <form onSubmit={handleSubmit(updateApplication)}>
|
---|
97 | <div className="row">
|
---|
98 | <div className="col-md-6 d-flex flex-column gap-4">
|
---|
99 | <div>
|
---|
100 | <label className="label">Why are you interested in joining our company?</label>
|
---|
101 | <textarea disabled type="text" defaultValue={application.questionAnswers[0]} disabled
|
---|
102 | placeholder="Write your answer here..." className="application-textarea"/>
|
---|
103 | </div>
|
---|
104 |
|
---|
105 | <div>
|
---|
106 | <label className="label">What makes you a good fit for this position?</label>
|
---|
107 | <textarea disabled type="text" defaultValue={application.questionAnswers[1]}
|
---|
108 | placeholder="Write your answer here..." className="application-textarea"/>
|
---|
109 | </div>
|
---|
110 |
|
---|
111 | <div>
|
---|
112 | <label className="label">What do you hope to achieve in your first 6 months in this
|
---|
113 | role?</label>
|
---|
114 | <textarea disabled type="text" defaultValue={application.questionAnswers[2]}
|
---|
115 | placeholder="Write your answer here..." className="application-textarea"/>
|
---|
116 | </div>
|
---|
117 |
|
---|
118 |
|
---|
119 | </div>
|
---|
120 | <div className="col-md-6 d-flex flex-column gap-4">
|
---|
121 | <div>
|
---|
122 | <label className="label" htmlFor="start">Curriculum vitae (CV)</label>
|
---|
123 |
|
---|
124 | <a className="resume-link" href={resumeUrl} target="_blank"
|
---|
125 | rel="noopener noreferrer">{getFileName(application.fileName)}</a>
|
---|
126 | </div>
|
---|
127 |
|
---|
128 | <div>
|
---|
129 | <label className="label">Message to the recruiter</label>
|
---|
130 | <textarea disabled type="text" defaultValue={application.message}
|
---|
131 | placeholder="Optional..."
|
---|
132 | className="application-textarea"/>
|
---|
133 | </div>
|
---|
134 |
|
---|
135 |
|
---|
136 | {additionalFileUrls.length > 0 ? (<div>
|
---|
137 | <label className="label" htmlFor="start">Additional documents</label>
|
---|
138 | <ul style={{listStyleType: "none", padding: 0, margin: 0}}>
|
---|
139 | {additionalFileUrls.map((url, index) => (
|
---|
140 | <li style={{marginBottom: 10}} key={index}>
|
---|
141 | <a href={url} className="resume-link" download target="_blank">
|
---|
142 | {getFileName(url)}
|
---|
143 | </a>
|
---|
144 | </li>))}
|
---|
145 | </ul>
|
---|
146 | </div>) : (<div>
|
---|
147 | {(application.status === "UNDER_REVIEW" && application.response.length > 0 && auth.role == Roles.JOBSEEKER) &&
|
---|
148 | <div>
|
---|
149 | <label className="label" htmlFor="start">Additional documents</label>
|
---|
150 | <input
|
---|
151 | className="resume-link"
|
---|
152 | onChange={(e) => setAdditionalFiles(e.target.files)}
|
---|
153 | required type="file"
|
---|
154 | id="fileUpload"
|
---|
155 | accept=".pdf"
|
---|
156 | multiple
|
---|
157 | />
|
---|
158 | </div>}
|
---|
159 | </div>
|
---|
160 | )}
|
---|
161 |
|
---|
162 |
|
---|
163 | </div>
|
---|
164 | </div>
|
---|
165 | {(additionalFileUrls.length === 0 && application.status === "UNDER_REVIEW" && application.response.length > 0 && auth.role == Roles.JOBSEEKER) &&
|
---|
166 | <div className="modal-buttons">
|
---|
167 | <div className="cancel-btn" onClick={toggleModal}> Cancel</div>
|
---|
168 | <button className="submit-btn"> Submit</button>
|
---|
169 | </div>}
|
---|
170 |
|
---|
171 | </form>
|
---|
172 |
|
---|
173 |
|
---|
174 | </div>
|
---|
175 | </Modal>
|
---|
176 | </div>)
|
---|
177 | } |
---|