|
|
|
@@ -10,6 +10,10 @@ import { motion } from 'framer-motion'; |
|
|
|
|
|
|
|
import MyDropzone from './MyDropzone'; |
|
|
|
import HashPositions from './HashPositions'; |
|
|
|
import useDataApi from '../../hooks/useDataApi'; |
|
|
|
import axios from 'axios'; |
|
|
|
|
|
|
|
const api_url = 'http://localhost:1337'; |
|
|
|
|
|
|
|
export default function JobForm(props) { |
|
|
|
const [sucMsg, setSucMsg] = useState(false); |
|
|
|
@@ -47,6 +51,21 @@ export default function JobForm(props) { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const date = new Date(); |
|
|
|
|
|
|
|
let day = date.getDate().toString().padStart(2, '0'); |
|
|
|
let diffMonth = date.getMonth().toString().padStart(2, '0'); |
|
|
|
let year = date.getFullYear(); |
|
|
|
|
|
|
|
let period = `${year}-${diffMonth}-${day}`; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
//console.log(hookdata); |
|
|
|
}) |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (jobForm.file !== '') { |
|
|
|
setErrorMsg(''); |
|
|
|
@@ -78,6 +97,8 @@ export default function JobForm(props) { |
|
|
|
validationSchema={validationSchema} |
|
|
|
onChange={changeFormHandler} |
|
|
|
onSubmit={values => { |
|
|
|
|
|
|
|
//prep file |
|
|
|
const prepFile = async file => { |
|
|
|
if (file.size >= 2000000) { |
|
|
|
setErrorMsg('File too large!'); |
|
|
|
@@ -88,8 +109,8 @@ export default function JobForm(props) { |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
//convert file |
|
|
|
const convertBase64 = file => { |
|
|
|
//console.log(file); |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const fileReader = new FileReader(); |
|
|
|
fileReader.readAsDataURL(file); |
|
|
|
@@ -103,42 +124,80 @@ export default function JobForm(props) { |
|
|
|
}; |
|
|
|
}); |
|
|
|
}; |
|
|
|
// if (fileInput.current.value === '') { |
|
|
|
// } |
|
|
|
if (jobForm.file === '') { |
|
|
|
setErrorMsg('CV is Required'); |
|
|
|
} else { |
|
|
|
setErrorMsg(''); |
|
|
|
prepFile(jobForm.file).then(res => { |
|
|
|
const newtemplateParams = { |
|
|
|
Position: values.position, |
|
|
|
Other: values.other, |
|
|
|
Firstname: values.firstName, |
|
|
|
Lastname: values.lastName, |
|
|
|
Coverletter: values.coverLetter, |
|
|
|
Email: values.email, |
|
|
|
Link: values.link, |
|
|
|
File: res, |
|
|
|
}; |
|
|
|
|
|
|
|
let data = {}; |
|
|
|
|
|
|
|
// &filters[SubmitDate][$gte]=${period} |
|
|
|
|
|
|
|
//const hookdata = useDataApi(`${api_url}/api/job-submissions?filters[Email][$eq]=${values.email}&filters[SubmitDate][$gte]=${period}`); |
|
|
|
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.attributes.SubmitDate); |
|
|
|
const submitDate = new Date(data.attributes.SubmitDate); |
|
|
|
const now = new Date(); |
|
|
|
if ((now.getMonth() - submitDate.getMonth()) > 1) |
|
|
|
{ |
|
|
|
setErrorMsg('you Already sent an email'); |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
fetch(`${api_url}/api/job-submissions`, { |
|
|
|
method: "PUT", |
|
|
|
headers: { |
|
|
|
"Content-type": "application/json; charset=UTF-8", |
|
|
|
}, |
|
|
|
body: JSON.stringify({ |
|
|
|
data: { |
|
|
|
Email: values.email, |
|
|
|
} |
|
|
|
}) |
|
|
|
}).then(r => r.json()).then(d => { |
|
|
|
console.log("d", d); |
|
|
|
}).catch(err => console.log(err)); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
fetchData(); |
|
|
|
|
|
|
|
// if (jobForm.file === '') { |
|
|
|
// setErrorMsg('CV is Required'); |
|
|
|
// } else { |
|
|
|
|
|
|
|
emailjs |
|
|
|
.send( |
|
|
|
process.env.REACT_APP_SERVICE_ID, |
|
|
|
process.env.REACT_APP_JOB_TEMPLATE_ID, |
|
|
|
newtemplateParams, |
|
|
|
process.env.REACT_APP_USER_ID, |
|
|
|
) |
|
|
|
.then( |
|
|
|
result => { |
|
|
|
console.log(result.text); |
|
|
|
setSucMsg(true); |
|
|
|
}, |
|
|
|
error => { |
|
|
|
console.log(error.text); |
|
|
|
}, |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// setErrorMsg(''); |
|
|
|
// prepFile(jobForm.file).then(res => { |
|
|
|
// const newtemplateParams = { |
|
|
|
// Position: values.position, |
|
|
|
// Other: values.other, |
|
|
|
// Firstname: values.firstName, |
|
|
|
// Lastname: values.lastName, |
|
|
|
// Coverletter: values.coverLetter, |
|
|
|
// Email: values.email, |
|
|
|
// Link: values.link, |
|
|
|
// File: res, |
|
|
|
// }; |
|
|
|
|
|
|
|
// emailjs |
|
|
|
// .send( |
|
|
|
// process.env.REACT_APP_SERVICE_ID, |
|
|
|
// process.env.REACT_APP_JOB_TEMPLATE_ID, |
|
|
|
// newtemplateParams, |
|
|
|
// process.env.REACT_APP_USER_ID, |
|
|
|
// ) |
|
|
|
// .then( |
|
|
|
// result => { |
|
|
|
// console.log(result.text); |
|
|
|
// setSucMsg(true); |
|
|
|
// }, |
|
|
|
// error => { |
|
|
|
// console.log(error.text); |
|
|
|
// }, |
|
|
|
// ); |
|
|
|
// }); |
|
|
|
// } |
|
|
|
}} |
|
|
|
> |
|
|
|
{props => ( |