| @@ -11,7 +11,7 @@ import ReactGA from 'react-ga4'; | |||
| import ReCAPTCHA from 'react-google-recaptcha'; | |||
| import axios from 'axios'; | |||
| export default function ClientForm() { | |||
| export default function ClientForm({ mg }) { | |||
| //search context for prevous entry TODO | |||
| const { clientForm, setClientForm } = useContext(ClientFormContext); | |||
| const [sucMsg, setSucMsg] = useState(false); | |||
| @@ -80,29 +80,13 @@ export default function ClientForm() { | |||
| setSucMsg(true); | |||
| if (res.data.data.success) { | |||
| setMsgText('Submission Succesful! Thank you!'); | |||
| // mg.messages.create('dilig.net', { | |||
| // from: `${values.firstName} ${values.lastName} <${values.email}>`, | |||
| // to: ['nikola.tasic@dilig.net'], | |||
| // subject: `${values.subject}`, | |||
| // text: `${values.description}`, | |||
| // html: `<p>${values.description}</p>`, | |||
| // }); | |||
| emailjs | |||
| .send( | |||
| process.env.REACT_APP_SERVICE_ID, | |||
| process.env.REACT_APP_CLIENT_TEMPLATE_ID, | |||
| data, | |||
| process.env.REACT_APP_USER_ID, | |||
| ) | |||
| .then( | |||
| result => { | |||
| console.log(result.text); | |||
| setSucMsg(true); | |||
| }, | |||
| error => { | |||
| console.log(error.text); | |||
| }, | |||
| ); | |||
| mg.messages.create('dilig.net', { | |||
| from: `${values.firstName} ${values.lastName} <${values.email}>`, | |||
| to: ['hr@dilig.net'], | |||
| subject: `${values.subject}`, | |||
| text: `${values.description}`, | |||
| html: `<p>${values.description}</p>`, | |||
| }); | |||
| } else setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | |||
| }) | |||
| .catch(error => { | |||
| @@ -16,15 +16,15 @@ import PageTitle from './PageTitle'; | |||
| import Wrapper from '../../layout/Wrapper'; | |||
| import { UIContext } from './../../context/index'; | |||
| // import Mailgun from 'mailgun.js'; | |||
| // import FormData from 'form-data'; | |||
| import Mailgun from 'mailgun.js'; | |||
| import FormData from 'form-data'; | |||
| // const mailgun = new Mailgun(FormData); | |||
| // const mg = mailgun.client({ | |||
| // username: 'api', | |||
| // key: process.env.REACT_APP_MAILGUN_API_KEY, | |||
| // url: 'https://api.eu.mailgun.net', | |||
| // }); | |||
| const mailgun = new Mailgun(FormData); | |||
| const mg = mailgun.client({ | |||
| username: 'api', | |||
| key: process.env.REACT_APP_MAILGUN_API_KEY, | |||
| url: 'https://api.eu.mailgun.net', | |||
| }); | |||
| export default function Contact(props) { | |||
| const [tab, setTab] = useState(true); | |||
| @@ -170,7 +170,7 @@ export default function Contact(props) { | |||
| <Tab.Panels className="w-full mt-2 mx-auto"> | |||
| <Tab.Panel className={classNames('py-3', 'outline-none')}> | |||
| <ClientFormContext.Provider value={{ clientForm, setClientForm }}> | |||
| <ClientForm /> | |||
| <ClientForm mg={mg} /> | |||
| </ClientFormContext.Provider> | |||
| </Tab.Panel> | |||
| <Tab.Panel className={classNames('py-3', 'outline-none')}> | |||
| @@ -178,6 +178,7 @@ export default function Contact(props) { | |||
| <JobForm | |||
| cntCareers={cntCareers} | |||
| defaultPositionSelection={defaultPositionSelection} | |||
| mg={mg} | |||
| /> | |||
| </JobFormContext.Provider> | |||
| </Tab.Panel> | |||
| @@ -117,61 +117,16 @@ export default function JobForm(props) { | |||
| 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!'); | |||
| // props.mg.messages.create('dilig.net', { | |||
| // from: `${values.firstName} ${values.lastName} <${values.email}>`, | |||
| // to: ['hr@dilig.net'], | |||
| // subject: 'Applying for a position', | |||
| // text: `Position:${values.position} ${values.other}, Cover letter: ${values.coverLetter}, Link: ${values.link} `, | |||
| // html: `<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); | |||
| // }); | |||
| //} | |||
| //} | |||
| prepFile(jobForm.file).then(async 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, | |||
| 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!'); | |||
| @@ -184,22 +139,15 @@ export default function JobForm(props) { | |||
| setSucMsg(true); | |||
| if (res.data.data.success) { | |||
| setMsgText('Submission Succesful! Thank you!'); | |||
| 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.mg.messages.create('dilig.net', { | |||
| from: `${values.firstName} ${values.lastName} <${values.email}>`, | |||
| to: ['hr@dilig.net'], | |||
| subject: 'Applying for a position', | |||
| text: `Position:${values.position} ${values.other}, Cover letter: ${values.coverLetter}, Link: ${values.link} `, | |||
| html: `<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!'); | |||
| }) | |||
| @@ -207,7 +155,7 @@ export default function JobForm(props) { | |||
| console.log(error); | |||
| }); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| ReactGA.event('contact', { | |||
| category: 'Contact', | |||
| @@ -27,16 +27,13 @@ export default function MyDropzone(props) { | |||
| </svg> | |||
| ); | |||
| const onDrop = useCallback(acceptedFiles => { | |||
| const onDrop = useCallback(async acceptedFiles => { | |||
| if (acceptedFiles && acceptedFiles.length > 0) { | |||
| if (acceptedFiles[0] !== 'undefined' && acceptedFiles[0].type !== 'undefined') { | |||
| if (acceptedFiles[0].type === 'application/pdf') { | |||
| // const files = Array.from(acceptedFiles); | |||
| // const fileBuffer = await files[0]; | |||
| // setFile(fileBuffer); | |||
| acceptedFiles.map(file => { | |||
| setFile(file); | |||
| }); | |||
| const files = Array.from(acceptedFiles); | |||
| const fileBuffer = await files[0]; | |||
| setFile(fileBuffer); | |||
| setEmpty(false); | |||
| } | |||
| } | |||