|
|
|
@@ -13,6 +13,8 @@ import HashPositions from './HashPositions'; |
|
|
|
import ReCAPTCHA from 'react-google-recaptcha'; |
|
|
|
import axios from 'axios'; |
|
|
|
|
|
|
|
const api_url = process.env.REACT_APP_API_URL; |
|
|
|
|
|
|
|
export default function JobForm(props) { |
|
|
|
const [sucMsg, setSucMsg] = useState(false); |
|
|
|
const captchaRef = useRef(null); |
|
|
|
@@ -90,7 +92,11 @@ export default function JobForm(props) { |
|
|
|
initialValues={jobForm} |
|
|
|
validationSchema={validationSchema} |
|
|
|
onChange={changeFormHandler} |
|
|
|
onSubmit={async values => { |
|
|
|
onSubmit={values => { |
|
|
|
|
|
|
|
setSucMsg(false); |
|
|
|
|
|
|
|
//prep file |
|
|
|
const prepFile = async file => { |
|
|
|
if (file.size >= 2000000) { |
|
|
|
setErrorMsg('File too large!'); |
|
|
|
@@ -115,63 +121,42 @@ export default function JobForm(props) { |
|
|
|
}; |
|
|
|
}); |
|
|
|
}; |
|
|
|
if ( |
|
|
|
selectedPosition === '' || |
|
|
|
(otherInputState === false && values.other === '') |
|
|
|
) |
|
|
|
setErrorMsgPosition('Position is Required'); |
|
|
|
else { |
|
|
|
setErrorMsgPosition(''); |
|
|
|
if (jobForm.file === '') { |
|
|
|
setErrorMsg('CV is Required'); |
|
|
|
} else { |
|
|
|
setErrorMsg(''); |
|
|
|
if (jobForm.file.size >= 2000000) { |
|
|
|
setErrorMsg('File too large!'); |
|
|
|
} else { |
|
|
|
const file = { |
|
|
|
filename: 'CV.pdf', |
|
|
|
data: jobForm.file, |
|
|
|
}; |
|
|
|
|
|
|
|
const token = captchaRef.current.getValue(); |
|
|
|
captchaRef.current.reset(); |
|
|
|
if (token.length === 0) { |
|
|
|
setSucMsg(true); |
|
|
|
setMsgText('Please fill reCAPTCHA and try again. Thank you!'); |
|
|
|
} else { |
|
|
|
await axios |
|
|
|
.post(`${process.env.REACT_APP_CAPTCHA_API}/verify-token`, { |
|
|
|
token, |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
setSucMsg(true); |
|
|
|
if (res.data.data.success) { |
|
|
|
setMsgText('Submission Succesful! Thank you!'); |
|
|
|
let data = {}; |
|
|
|
|
|
|
|
props.mg.messages.create('dilig.net', { |
|
|
|
from: `${values.firstName} ${values.lastName} <${values.email}>`, |
|
|
|
to: ['hr@dilig.net'], |
|
|
|
subject: 'Applying for a position', |
|
|
|
text: `Email: ${values.email}, Position:${values.position} ${values.other}, Cover letter: ${values.coverLetter}, Link: ${values.link} `, |
|
|
|
html: `<p>Email: ${values.email}</p><p>Position: ${selectedPosition} ${values.other}</p><p>Cover letter: ${values.coverLetter}</p><p>Link (optional): ${values.link}</p>`, |
|
|
|
attachment: file, |
|
|
|
}); |
|
|
|
} else |
|
|
|
setMsgText('Please fill reCAPTCHA and try again. Thank you!'); |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
console.log(error); |
|
|
|
}); |
|
|
|
const fetchData = async () => { |
|
|
|
axios.get(`${api_url}/api/job-submissions?filters[Email][$eq]=${values.email}`) |
|
|
|
.then((res) => { |
|
|
|
data = res.data.data[0]; |
|
|
|
console.log(data); |
|
|
|
const submitDate = new Date(data.attributes.SubmitDate); |
|
|
|
const now = new Date(); |
|
|
|
if ((now.getMonth() - submitDate.getMonth()) < 1) |
|
|
|
{ |
|
|
|
setErrorMsg('You Already sent an email'); |
|
|
|
return false |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
fetch(`${api_url}/api/job-submissions/${data.id}`, { |
|
|
|
method: "PUT", |
|
|
|
headers: { |
|
|
|
"Content-type": "application/json; charset=UTF-8", |
|
|
|
}, |
|
|
|
body: JSON.stringify({ |
|
|
|
data: { |
|
|
|
SubmitDate: now, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
ReactGA.event('contact', { |
|
|
|
category: 'Contact', |
|
|
|
action: 'Job application', |
|
|
|
}); |
|
|
|
}} |
|
|
|
})}}} |
|
|
|
> |
|
|
|
{props => ( |
|
|
|
<Form onSubmit={props.handleSubmit}> |