-
-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathJobApplicationForm.jsx
More file actions
435 lines (407 loc) · 16.4 KB
/
JobApplicationForm.jsx
File metadata and controls
435 lines (407 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// ...existing code...
import React, { useState, useEffect, useRef } from 'react';
import styles from './JobApplicationForm.module.css';
import OneCommunityImage from '../../../assets/images/logo2.png';
import axios from 'axios';
import { ENDPOINTS } from '../../../utils/URL';
import { useSelector } from 'react-redux';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
function JobApplicationForm() {
const [forms, setForms] = useState([]);
const [selectedJob, setSelectedJob] = useState('');
const [answers, setAnswers] = useState([]);
const [jobTitleInput, setJobTitleInput] = useState('');
const [filteredForm, setFilteredForm] = useState(null);
const [showDescription, setShowDescription] = useState(false);
const [applicantName, setApplicantName] = useState('');
const [applicantEmail, setApplicantEmail] = useState('');
const [locationTimezone, setLocationTimezone] = useState('');
const [phone, setPhone] = useState('');
const [companyPosition, setCompanyPosition] = useState('');
const [websiteSocial, setWebsiteSocial] = useState('');
const [resumeFile, setResumeFile] = useState(null);
const [resumeStatus, setResumeStatus] = useState('idle');
// idle | uploading | success | error
const [resumeError, setResumeError] = useState('');
const resumeInputRef = useRef(null);
const darkMode = useSelector(state => state.theme?.darkMode);
useEffect(() => {
async function fetchForms() {
try {
const res = await axios.get(ENDPOINTS.GET_ALL_JOB_FORMS);
const formsArr = Array.isArray(res.data.forms) ? res.data.forms : [];
setForms(formsArr);
const firstWithQuestions = formsArr.find(f => f.questions && f.questions.length > 0);
if (firstWithQuestions) {
setSelectedJob(firstWithQuestions.title);
setFilteredForm(firstWithQuestions);
setAnswers(new Array((firstWithQuestions.questions ?? []).length).fill(''));
} else if (formsArr.length > 0) {
setSelectedJob(formsArr[0].title);
setFilteredForm(formsArr[0]);
setAnswers(new Array((formsArr[0].questions ?? []).length).fill(''));
}
} catch (err) {
setForms([]);
setSelectedJob('');
setFilteredForm(null);
setAnswers([]);
toast.error('Failed to load job forms.');
}
}
fetchForms();
}, []);
useEffect(() => {
if (!selectedJob) return;
const form = forms.find(f => f.title === selectedJob);
setFilteredForm(form);
setAnswers(new Array((form?.questions ?? []).length).fill(''));
}, [selectedJob, forms]);
const handleJobChange = e => {
setSelectedJob(e.target.value);
};
const handleJobTitleInputChange = e => {
setJobTitleInput(e.target.value);
};
const handleGoClick = () => {
const form = forms.find(f => f.title?.toLowerCase() === jobTitleInput.trim().toLowerCase());
if (form) {
setSelectedJob(form.title);
} else {
toast.info('No form matches that job title.');
}
};
const handleAnswerChange = (idx, value) => {
const newAnswers = [...answers];
newAnswers[idx] = value;
setAnswers(newAnswers);
};
const handleShowDescription = e => {
e.preventDefault();
setShowDescription(true);
};
const handleCloseDescription = () => {
setShowDescription(false);
};
const handleResumeChange = e => {
const f = e.target.files?.[0] || null;
if (!f) {
setResumeFile(null);
setResumeStatus('idle');
return;
}
// Basic validation (optional but recommended)
const allowedTypes = [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
];
if (!allowedTypes.includes(f.type)) {
setResumeStatus('error');
setResumeError('Only PDF or Word documents are allowed.');
setResumeFile(null);
toast.error('Invalid file type. Please upload PDF or DOC/DOCX.');
return;
}
setResumeFile(f);
setResumeStatus('success');
setResumeError('');
toast.success(`Resume selected: ${f.name}`);
};
const handleRemoveResume = () => {
setResumeFile(null);
setResumeStatus('idle');
setResumeError('');
if (resumeInputRef.current) resumeInputRef.current.value = '';
};
const validateBeforeSubmit = () => {
const missing = [];
if (!applicantName.trim()) missing.push('Name');
if (!applicantEmail.trim()) missing.push('Email');
if (filteredForm?.questions?.length) {
for (const [idx, q] of filteredForm.questions.entries()) {
const required = q.required ?? false;
if (required && !String(answers[idx] ?? '').trim()) {
missing.push(q.label || q.questionText || `Question ${idx + 1}`);
}
}
}
return missing;
};
const handleSubmit = async e => {
e.preventDefault();
const missing = validateBeforeSubmit();
if (missing.length > 0) {
toast.error(`Please complete required fields: ${missing.join(', ')}`, { autoClose: 7000 });
return;
}
toast.success('Application submitted. A copy will be sent to your email.');
setApplicantName('');
setApplicantEmail('');
setLocationTimezone('');
setPhone('');
setCompanyPosition('');
setWebsiteSocial('');
setResumeFile(null);
setResumeStatus('idle');
setResumeError('');
if (resumeInputRef.current) resumeInputRef.current.value = '';
setAnswers(new Array((filteredForm?.questions ?? []).length).fill(''));
};
return (
<div className={`${styles.container} ${darkMode ? styles.darkMode : ''}`}>
<ToastContainer position="top-right" autoClose={5000} hideProgressBar={false} />
<header className={styles.logo}>
<a
href="https://www.onecommunityglobal.org/collaboration/"
target="_blank"
rel="noreferrer"
>
<img src={OneCommunityImage} alt="One Community Logo" />
</a>
</header>
<main className={styles.header}>
<section className={styles.headerContent}>
<div className={styles.headerLeft}>
<input
type="text"
placeholder="Enter Job Title"
className={styles.jobTitleInput}
value={jobTitleInput}
onChange={handleJobTitleInputChange}
/>
<button className="btn btn-secondary" onClick={handleGoClick} type="button">
Go
</button>
</div>
<div className={styles.headerRight}>
<select className={styles.jobSelect} value={selectedJob} onChange={handleJobChange}>
{forms.map(form => (
<option key={form._id || form.id} value={form.title}>
{form.title}
</option>
))}
</select>
</div>
</section>
<section className={styles.formContainer}>
<h1 className={styles.formTitle}>FORM FOR {selectedJob?.toUpperCase()} POSITION</h1>
<p className={styles.formSubtitle}>
<a href="#learnMore" onClick={handleShowDescription}>
Click to know more about this position
</a>
</p>
{showDescription && filteredForm && (
<div className={styles.popupOverlay}>
<div className={styles.popupContent}>
<button
className={styles.popupCloseBtn}
onClick={handleCloseDescription}
aria-label="Close"
type="button"
>
×
</button>
<h2>{filteredForm.title}</h2>
<p>{filteredForm.description || 'No description available.'}</p>
</div>
</div>
)}
<form className={styles.form} onSubmit={handleSubmit}>
<div>
Here is a questionnaire to apply to work with us. To complete your application and
schedule a Zoom interview, please answer the pre-interview questions below.
</div>
<div className={styles.formContentGroup}>
<div className={styles.formProfileDetailGroup}>
<input
type="text"
placeholder="Name"
className={styles.inputField}
value={applicantName}
onChange={e => setApplicantName(e.target.value)}
/>
<input
type="email"
placeholder="Email"
className={styles.inputField}
value={applicantEmail}
onChange={e => setApplicantEmail(e.target.value)}
/>
<input
type="text"
placeholder="Location & Timezone"
className={styles.inputField}
value={locationTimezone}
onChange={e => setLocationTimezone(e.target.value)}
/>
<input
type="text"
placeholder="Phone Number"
className={styles.inputField}
value={phone}
onChange={e => setPhone(e.target.value)}
/>
<input
type="text"
placeholder="Company & Position"
className={styles.inputField}
value={companyPosition}
onChange={e => setCompanyPosition(e.target.value)}
/>
<input
type="text"
placeholder="Primary Website/Social"
className={styles.inputField}
value={websiteSocial}
onChange={e => setWebsiteSocial(e.target.value)}
/>
<div className={styles.resumeWrapper}>
<label
className={`${styles.resumeLabel} ${
resumeStatus === 'success'
? styles.success
: resumeStatus === 'error'
? styles.error
: ''
}`}
>
{resumeFile ? (
<span className={styles.fileName}>📄 {resumeFile.name}</span>
) : (
'Upload Resume (optional)'
)}
<input
ref={resumeInputRef}
type="file"
accept=".pdf,.doc,.docx"
onChange={handleResumeChange}
/>
</label>
{resumeFile && (
<button
type="button"
className={styles.removeResumeBtn}
onClick={handleRemoveResume}
>
✕
</button>
)}
</div>
</div>
<div className={styles.formGroup}>
<h2>1. How did you hear about One Community?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>2. Are you applying as an individual or organization?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>3. Why are you wanting to volunteer/work/collaborate with us?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>4. What skills/experience do you possess?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>5. How many volunteer hours per week are you willing to commit to?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>6. For how long do you wish to volunteer with us?</h2>
<input type="text" placeholder="Type your response here" />
</div>
<div className={styles.formGroup}>
<h2>7. What is your desired start date?</h2>
<input type="date" className={styles.dateInput} />
</div>
<div className={styles.formGroup}>
<h2>8. Will your volunteer time require documentation of your hours?</h2>
<select className={styles.selectField}>
<option value="">Select an appropriate option</option>
<option value="Yes, I'm volunteering just because I want to">
Yes, I'm volunteering just because I want to
</option>
<option value="Yes, I'm on OPT and don't yet have my EAD Card">
Yes, I'm on OPT and don't yet have my EAD Card
</option>
<option value="Yes, I'm on OPT and this time is for CPT, Co-op, or similar">
Yes, I'm on OPT and this time is for CPT, Co-op, or similar
</option>
<option value="STEM OPT: Sorry, we are 100% volunteer and don't qualify">
STEM OPT: Sorry, we are 100% volunteer and don't qualify
</option>
</select>
</div>
{filteredForm &&
(filteredForm.questions || []).map((q, idx) => (
<div className={styles.formGroup} key={q._id?.$oid || q._id || idx}>
<h2>{q.label || q.questionText}</h2>
{q.type === 'text' || q.questionType === 'textbox' ? (
<input
type="text"
placeholder="Type your response here"
value={answers[idx] || ''}
onChange={e => handleAnswerChange(idx, e.target.value)}
/>
) : null}
{q.type === 'textarea' || q.questionType === 'textarea' ? (
<textarea
placeholder="Type your response here"
value={answers[idx] || ''}
onChange={e => handleAnswerChange(idx, e.target.value)}
/>
) : null}
{q.type === 'date' || q.questionType === 'date' ? (
<input
type="date"
value={answers[idx] || ''}
onChange={e => handleAnswerChange(idx, e.target.value)}
/>
) : null}
{['checkbox', 'radio'].includes(q.type || q.questionType) && q.options && (
<div>
{q.options.map(opt => (
<label key={opt}>
<input
type={q.type || q.questionType}
name={`question-${idx}`}
value={opt}
checked={answers[idx] === opt}
onChange={() => handleAnswerChange(idx, opt)}
/>{' '}
{opt}
</label>
))}
</div>
)}
{q.type === 'dropdown' || q.questionType === 'dropdown' ? (
<select
value={answers[idx] || ''}
onChange={e => handleAnswerChange(idx, e.target.value)}
>
<option value="">Select an option</option>
{q.options &&
q.options.map(opt => (
<option key={opt} value={opt}>
{opt}
</option>
))}
</select>
) : null}
</div>
))}
<button type="submit" className={styles.submitButton}>
Proceed to submit with details
</button>
</div>
</form>
</section>
</main>
</div>
);
}
export default JobApplicationForm;