Explorar el Código

tedt

blog-new
Pavle Golubovic hace 3 años
padre
commit
80fb285105

+ 47
- 36
frontend/src/components/shared/ClientForm.jsx Ver fichero

let data = {}; let data = {};


const fetchData = async () => { const fetchData = async () => {
axios.get(`${api_url}/api/job-submissions?filters[Email][$eq]=${values.email}`)
axios.get(`${api_url}/api/client-submissions?filters[Email][$eq]=${values.email}`)
.then((res) => { .then((res) => {
data = res.data.data[0]; data = res.data.data[0];
console.log(data);
if (typeof data == 'undefined') {
}
const submitDate = new Date(data.attributes.SubmitDate); const submitDate = new Date(data.attributes.SubmitDate);
const now = new Date(); const now = new Date();
if ((now.getMonth() - submitDate.getMonth()) < 1) if ((now.getMonth() - submitDate.getMonth()) < 1)
{ {
setErrorMsg('You Already sent an email'); setErrorMsg('You Already sent an email');
//console.log('email already sent');
return false; return false;
} }
else { else {
fetch(`${api_url}/api/job-submissions/${data.id}`, {
fetch(`${api_url}/api/client-submissions/${data.id}`, {
method: "PUT", method: "PUT",
headers: { headers: {
"Content-type": "application/json; charset=UTF-8", "Content-type": "application/json; charset=UTF-8",
} }
}) })
}).then(r => r.json()).then(d => { }).then(r => r.json()).then(d => {
setErrorMsg('');
return true
setErrorMsg('');
const val = {
Tag: values.tag,
Subject: values.subject,
Email: values.email,
Firstname: values.firstName,
Lastname: values.lastName,
Description: values.description,
}
// emailjs
// .send(
// process.env.REACT_APP_SERVICE_ID,
// process.env.REACT_APP_CLIENT_TEMPLATE_ID,
// val,
// process.env.REACT_APP_USER_ID,
// )
// .then(
// result => {
// console.log(result.text);
// setSucMsg(true);
// },
// error => {
// console.log(error.text);
// },
// );
}).catch(err => { }).catch(err => {
console.log(err) console.log(err)
return false return false
}); });
}
});
};
}
})
}
fetchData();
}}



if (fetchData()){
const val = {
Tag: values.tag,
Subject: values.subject,
Email: values.email,
Firstname: values.firstName,
Lastname: values.lastName,
Description: values.description,
};
emailjs
.send(
process.env.REACT_APP_SERVICE_ID,
process.env.REACT_APP_CLIENT_TEMPLATE_ID,
val,
process.env.REACT_APP_USER_ID,
)
.then(
result => {
console.log(result.text);
setSucMsg(true);
},
error => {
console.log(error.text);
},
);
}}
}
> >
{props => ( {props => (
{sucMsg && <div className={'text-sm text-right text-dg-primary-900'}> {sucMsg && <div className={'text-sm text-right text-dg-primary-900'}>
Submission Succesful! Thank you! Submission Succesful! Thank you!
</div> } </div> }
{errorMsg !== '' && <div className={'text-sm text-right text-red-700'}>
{errorMsg}
</div> }
</div> </div>



+ 20
- 17
frontend/src/components/shared/JobForm.jsx Ver fichero

onChange={changeFormHandler} onChange={changeFormHandler}
onSubmit={values => { onSubmit={values => {


setSucMsg(false);

//prep file //prep file
const prepFile = async file => { const prepFile = async file => {
if (file.size >= 2000000) { if (file.size >= 2000000) {
}); });
}; };


console.log(fetchData());


if (jobForm.file === '') { if (jobForm.file === '') {
setErrorMsg('CV is Required'); setErrorMsg('CV is Required');
Link: values.link, Link: values.link,
File: res, 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);
},
);
// 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);
// },
// );
}); });
} }

Cargando…
Cancelar
Guardar