File size: 23,400 Bytes
8b105ad 051fc03 8b105ad 051fc03 8b105ad 553dc7c 051fc03 8b105ad 553dc7c 8b105ad 553dc7c 8b105ad 553dc7c 8b105ad |
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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
import React, { useState, useRef } from 'react';
import { FaMapPin, FaCalendarAlt, FaBriefcase } from 'react-icons/fa';
import styled from 'styled-components';
import { createGlobalStyle } from 'styled-components';
import IntlTelInput from 'intl-tel-input/reactWithUtils';
import 'intl-tel-input/styles';
import axios from 'axios';
import privacyPolicyData from "../../data/privacyPolicyData";
import { showCustomAlert, showCustomError, showCustomSuccess } from '../../utils/showalerts';
const GlobalStyles = createGlobalStyle`
.iti__country {
color: #333;
background-color: #f8f9fa;
}
.iti__country:hover {
background-color: #3f7ad3;
color: white;
}
.iti__country.iti__active {
background-color: #3f7ad3;
color: white;
}
.flexer {
display: grid;
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.flexer {
grid-template-columns: 60% 40%;
gap: 2rem;
}
}
ul li::before {
content: "\f00c";
font-family: "Font Awesome 5 Free";
font-weight: 900;
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
color: green;
}
`;
const FormContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
max-width: 900px;
margin-top: 2rem;
width: 100%;
`;
const Form = styled.form`
display: flex;
flex-direction: column;
gap: 1rem;
width: 80%;
max-height: fit-content !important;
align-self: center;
justify-self: center;
background-color: #2d3748;
padding: 24px;
border-radius: 0.375rem;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
`;
const Input = styled.input`
width: 100%;
padding: 0.75rem 1rem;
font-size: 1rem;
border: 3px solid ${(props) => (props.invalid ? '#de493e' : '#3267B9')};
border-radius: 0.375rem;
background-origin: border-box;
color: black;
&:focus {
outline: none;
box-shadow: 0 0 8px rgba(63, 122, 211, 0.5);
}
`;
const IntlTelInputWrapper = styled.div`
width: 100%;
.iti {
width: 100%;
color: black;
}
input {
width: 100%;
padding: 0.75rem 1rem;
font-size: 1rem;
border: 3px solid ${(props) => (props.invalid ? '#de493e' : '#3267B9')};
border-radius: 0.375rem;
background-origin: border-box;
color: black;
&:focus {
outline: none;
box-shadow: 0 0 8px rgba(63, 122, 211, 0.5);
}
}
`;
const Textarea = styled.textarea`
width: 100%;
padding: 0.75rem 1rem;
font-size: 1rem;
border: 3px solid #3267B9;
border-radius: 0.375rem;
color: black;
&:focus {
outline: none;
box-shadow: 0 0 8px rgba(63, 122, 211, 0.8);
}
`;
const Select = styled.select`
width: 100%;
padding: 0.75rem 1rem;
font-size: 1rem;
border: 3px solid #3267B9;
border-radius: 0.375rem;
color: black;
&:focus {
outline: none;
box-shadow: 0 0 8px rgba(63, 122, 211, 0.5);
}
`;
const SubmitButton = styled.button`
width: 100%;
padding: 0.75rem 1.5rem;
background: #3267B9;
color: white;
font-weight: 600;
border-radius: 0.375rem;
transition: background 0.3s;
&:hover {
background: #3f7ad3;
}
`;
const FileInputWrapper = styled.div`
position: relative;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
`;
const FileInputButton = styled.label`
display: inline-block;
padding: 0.75rem 1.5rem;
background-color: #3f7ad3;
color: white;
border-radius: 30px;
cursor: pointer;
text-align: center;
width: 100%;
max-width: 250px;
text-transform: uppercase;
font-weight: 500;
transition: background-color 0.3s ease;
&:hover {
background-color: #669df0;
}
`;
const FileInput = styled.input`
display: none;
`;
const FileNameDisplay = styled.span`
margin-top: 0.5rem;
font-size: 0.875rem;
color: #A0AEC0;
`;
const ConsentWrapper = styled.div`
display: grid;
grid-template-columns: auto 1fr;
gap: 0.5rem;
color: #d5d5d5;
`;
const JobPageSection = ({ job }) => {
const {
title,
location,
status,
postedDate,
description,
responsibilities = [],
skillsRequired = [],
desirableSkills = [],
perks = []
} = job;
const [phone, setPhone] = useState('');
const [isValid, setIsValid] = useState(false);
const [fileName, setFileName] = useState('');
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [experience, setExperience] = useState('');
const [role, setRole] = useState(title); // Set initial role as the job title
const [linkedin, setLinkedin] = useState('');
const [consent, setConsent] = useState(false); // State to track consent
const [errors, setErrors] = useState({}); // State for storing error messages
const fieldRefs = useRef({
name: React.createRef(),
email: React.createRef(),
phone: React.createRef(),
linkedin: React.createRef(),
experience: React.createRef(),
});
const validateName = (name) => name.length >= 3;
const validateEmail = (email) => /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email);
const validatePhone = () => isValid;
const validateLinkedin = (linkedin) => /^https?:\/\/(www\.)?linkedin\.com\//.test(linkedin);
const formatStatus = (status) => status === "OPENED" ? "Open" : "Closed";
const formatDate = (date) => {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(date).toLocaleDateString(undefined, options);
};
const handleInputChange = (e, setter, fieldName) => {
setter(e.target.value);
setErrors({});
};
const handleBlur = (fieldName) => {
const validationErrors = {};
if (fieldName === 'name' && !validateName(name)) {
validationErrors.name = 'Name should be at least 3 characters long.';
}
if (fieldName === 'email' && !validateEmail(email)) {
validationErrors.email = 'Invalid email format.';
}
if (fieldName === 'phone' && !validatePhone()) {
validationErrors.phone = 'Please enter a valid phone number.';
}
if (fieldName === 'linkedin' && !validateLinkedin(linkedin)) {
validationErrors.linkedin = "LinkedIn URL should start with 'https://www.linkedin.com'.";
}
setErrors(validationErrors);
console.log(isValid);
if (Object.keys(validationErrors).length > 0) {
console.log(fieldRefs.current[fieldName]);
fieldRefs.current[fieldName].current.focus();
}
};
const handleFileChange = (e) => {
const file = e.target.files[0];
const validExtensions = ['pdf', 'docx', 'doc'];
if (file) {
const fileExtension = file.name.split('.').pop().toLowerCase();
if (!validExtensions.includes(fileExtension)) {
showCustomError("Invalid file type. Please upload a .pdf, .docx, or .doc file.");
setFileName('');
e.target.value = '';
return;
}
setFileName(file.name);
}
};
const handleSubmit = async (e) => {
e.preventDefault();
if (!name || !email || !phone || !experience || !fileName || !linkedin) {
showCustomError("Please fill out all required fields.");
return;
}
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email)) {
showCustomError("Please enter a valid email address.");
return;
}
if (!isValid) {
showCustomError("Please enter a valid phone number.");
return;
}
//Set the policy version number
const policyVersion = privacyPolicyData.version;
try {
const formData = new FormData();
formData.append('name', name);
formData.append('email', email);
formData.append('phone', phone);
formData.append('experience', experience);
formData.append('linkedin', linkedin);
formData.append('consent', consent);
formData.append('policyVersion', policyVersion);
formData.append('role', role); // Add role to the form data
formData.append('resume', document.getElementById('fileInput').files[0]);
showCustomAlert("Please wait.... Your submission is in progress");
const response = await axios.post('/api/submit-job-application', formData, {
headers: { 'Content-Type': 'multipart/form-data' }
});
if (response.status >= 200 && response.status < 300) {
// Assuming the backend sends a success message in the response data
const successMessage = response.data.message || "Your application has been submitted successfully!";
showCustomSuccess(successMessage);
// Optionally clear the form fields here
// setYourState('');
} else {
// Handle cases where the response status is not successful
const errorMessage = response.data?.message || "An unexpected error occurred. Please try again.";
showCustomError(errorMessage);
}
// Reset form fields
setName('');
setEmail('');
setPhone('');
setExperience('');
setFileName('');
setLinkedin('');
setConsent(false);
document.getElementById("fileInput").value = '';
} catch (error) {
console.error('Error:', error);
// Reset form fields
setName('');
setEmail('');
setPhone('');
setExperience('');
setFileName('');
setLinkedin('');
setConsent(false);
if (error.response.data.error ==="Unable to send email for the confirmation of submission, but the application was received suvvessfully!"){
showCustomAlert("Unable to send email for the confirmation of submission, but the application was received suvvessfully!");
}else{
showCustomError(error.response.data.error || "An unexpected error occurred. Please try again.");
}
}
};
return (
<>
<GlobalStyles />
<div className="container" style={{ margin: "0 auto", padding: "24px" }}>
<h2
style={{
fontSize: "2.5rem",
fontWeight: "600",
color: "#3267B9",
marginBottom: "1rem",
}}
data-testid="job-title"
>
{title}
</h2>
<div
style={{
display: "flex",
gap: "1rem",
color: "#A0AEC0",
marginBottom: "2rem",
fontSize: "0.875rem",
}}
>
<p style={{ display: "flex", alignItems: "center" }}>
<FaMapPin style={{ marginRight: "0.5rem" }} />
{location}
</p>
<p style={{ display: "flex", alignItems: "center" }}>
<FaBriefcase style={{ marginRight: "0.5rem" }} />
{formatStatus(status)}
</p>
<p style={{ display: "flex", alignItems: "center" }}>
<FaCalendarAlt style={{ marginRight: "0.5rem" }} />
Posted on {formatDate(postedDate)}
</p>
</div>
<div className="flexer">
<div>
<div>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
Job Description
</h3>
<p style={{ fontSize: "1rem", color: "#A0AEC0" }}>
{description}
</p>
</div>
<div
className="pt-5"
style={{ display: "flex", flexDirection: "column", gap: "2rem" }}
>
<div>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
Responsibilities
</h3>
<ul
style={{
paddingLeft: "1.5rem",
listStyleType: "disc",
color: "#A0AEC0",
}}
>
{responsibilities.map((item, index) => (
<li key={index} style={{ marginBottom: "0.75rem" }}>
{item}
</li>
))}
</ul>
</div>
<div>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
Skills Required
</h3>
<ul
style={{
paddingLeft: "1.5rem",
listStyleType: "disc",
color: "#A0AEC0",
}}
>
{skillsRequired.map((item, index) => (
<li key={index} style={{ marginBottom: "0.75rem" }}>
{item}
</li>
))}
</ul>
</div>
<div>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
Desirable Skills
</h3>
<ul
style={{
paddingLeft: "1.5rem",
listStyleType: "disc",
color: "#A0AEC0",
}}
>
{desirableSkills.map((item, index) => (
<li key={index} style={{ marginBottom: "0.75rem" }}>
{item}
</li>
))}
</ul>
</div>
<div>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
What We Offer
</h3>
<ul
style={{
paddingLeft: "1.5rem",
listStyleType: "disc",
color: "#A0AEC0",
}}
>
{perks.map((item, index) => (
<li key={index} style={{ marginBottom: "0.75rem" }}>
{item}
</li>
))}
</ul>
</div>
</div>
</div>
{status === "OPENED" && (
<div style={{ flex: 1, minWidth: "200px" }}>
<div style={{ alignItems: "center", textAlign: "center" }}>
<h3
style={{
fontSize: "1.5rem",
fontWeight: "600",
color: "white",
marginBottom: "1rem",
}}
>
Apply for This Position
</h3>
<p
style={{
fontSize: "0.875rem",
color: "#A0AEC0",
marginBottom: "1.5rem",
}}
>
Fill in your details and upload your resume.
</p>
</div>
<FormContainer>
<Form onSubmit={handleSubmit}>
<label style={{ display: "flex" }}>
Name{" "}
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<Input
ref={fieldRefs.current.name}
type="text"
value={name}
placeholder="Your Full Name"
onChange={(e) => {
// Only allow letters (including spaces and accented characters)
const regex = /^[A-Za-z\s]*$/;
if (regex.test(e.target.value) || e.target.value === '') {
handleInputChange(e, setName, 'name');
}
}}
invalid={errors.name}
onBlur={() => handleBlur('name')}
required
/>
{errors.name && <span style={{ color: '#de493e', fontSize: '0.875rem' }}>{errors.name}</span>}
<label style={{ display: "flex" }}>
E-Mail{" "}
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<Input
ref={fieldRefs.current.email}
type="email"
value={email}
onChange={(e) => handleInputChange(e, setEmail, 'email')}
invalid={errors.email}
onBlur={() => handleBlur('email')}
placeholder="Your Email Address"
required
/>
{errors.email && <span style={{ color: '#de493e', fontSize: '0.875rem' }}>{errors.email}</span>}
<label style={{ display: "flex" }}>
Phone Number{" "}
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<IntlTelInputWrapper invalid={errors.phone}>
<IntlTelInput
value={phone}
onChangeNumber={setPhone}
onChangeValidity={setIsValid}
initOptions={{
initialCountry: "in",
separateDialCode: true,
}}
inputProps={{
placeholder: "Contact Number",
required: true,
style: { width: "100%" },
}}
onPhoneBlur={() => handleBlur('phone')}
/>
</IntlTelInputWrapper>
{errors.phone && <span style={{ color: '#de493e', fontSize: '0.875rem' }}>{errors.phone}</span>}
<label style={{ display: "flex" }}>Experience <div style={{ color: "red", marginLeft: "10px" }}>*</div> </label>{" "}
{/*<div style={{color:'red', marginLeft:"10px"}}>*</div> */}
<Textarea
value={experience}
onChange={(e) => setExperience(e.target.value)}
placeholder="Relevant Experience"
></Textarea>
{/* Role Selection Dropdown */}
<div style={{ marginBottom: "1.5rem" }}>
<label
style={{
display: "flex",
fontSize: "1rem",
color: "#EDF2F7",
}}
>
Role
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<Select
value={role}
onChange={(e) => setRole(e.target.value)}
disabled
>
<option value="Head of Sales">Head of Sales</option>
<option value="Web Designer & Developer">
Web Designer & Developer
</option>
<option value="Senior Software Developer">
Senior Software Developer
</option>
<option value="System Administrator (Part-time)">
System Administrator (Part-time)
</option>
<option value="Scientific Curators">
Scientific Curators
</option>
</Select>
</div>
{/* strategy Field */}
<label
style={{
display: "flex",
fontSize: "1rem",
color: "#EDF2F7",
}}
>
LinkedIn Profile URL
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<Input
ref={fieldRefs.current.linkedin}
type="text"
value={linkedin}
onChange={(e) => handleInputChange(e, setLinkedin, 'linkedin')}
invalid={errors.linkedin}
onBlur={() => handleBlur('linkedin')}
placeholder="Provide us your LinkedIn to know you more"
required
></Input>
{errors.linkedin && <span style={{ color: '#de493e', fontSize: '0.875rem' }}>{errors.linkedin}</span>}
<div style={{ marginBottom: "1.5rem" }}>
<label
style={{
display: "flex",
fontSize: "1rem",
color: "#EDF2F7",
}}
>
Upload Resume{" "}
<div style={{ color: "red", marginLeft: "10px" }}>*</div>
</label>
<FileInputWrapper>
<FileInputButton htmlFor="fileInput">
Choose File
</FileInputButton>
<FileInput
id="fileInput"
data-testid="file-input"
type="file"
accept=".pdf,.docx,.doc"
onChange={handleFileChange}
required
/>
{fileName && (
<FileNameDisplay>{fileName}</FileNameDisplay>
)}
</FileInputWrapper>
</div>
{/* Consent Checkbox */}
<ConsentWrapper>
<Input
type="checkbox"
id="gdpr-consent"
checked={consent}
onChange={() => setConsent(!consent)}
required
/>
<label htmlFor="gdpr-consent">
I consent to the processing of my submitted data in accordance with the{' '}
<a href="/privacy-policy" target="_blank" rel="noopener noreferrer">
<i style={{ color: "#3f7ad3" }}>Privacy Policy</i>
</a>.{' '}
<span style={{ color: "red", marginLeft: "5px" }}>*</span>
</label>
</ConsentWrapper>
<SubmitButton type="submit" data-testid="submit-btn">
Submit Application
</SubmitButton>
</Form>
</FormContainer>
</div>
)}
</div>
</div>
</>
);
};
export default JobPageSection; |