| import ReCAPTCHA from 'react-google-recaptcha'; | import ReCAPTCHA from 'react-google-recaptcha'; | ||||
| import axios from 'axios'; | import axios from 'axios'; | ||||
| export default function ClientForm() { | |||||
| export default function ClientForm({ mg }) { | |||||
| //search context for prevous entry TODO | //search context for prevous entry TODO | ||||
| const { clientForm, setClientForm } = useContext(ClientFormContext); | const { clientForm, setClientForm } = useContext(ClientFormContext); | ||||
| const [sucMsg, setSucMsg] = useState(false); | const [sucMsg, setSucMsg] = useState(false); | ||||
| setSucMsg(true); | setSucMsg(true); | ||||
| if (res.data.data.success) { | if (res.data.data.success) { | ||||
| setMsgText('Submission Succesful! Thank you!'); | 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!'); | } else setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | ||||
| }) | }) | ||||
| .catch(error => { | .catch(error => { |
| import Wrapper from '../../layout/Wrapper'; | import Wrapper from '../../layout/Wrapper'; | ||||
| import { UIContext } from './../../context/index'; | 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) { | export default function Contact(props) { | ||||
| const [tab, setTab] = useState(true); | const [tab, setTab] = useState(true); | ||||
| <Tab.Panels className="w-full mt-2 mx-auto"> | <Tab.Panels className="w-full mt-2 mx-auto"> | ||||
| <Tab.Panel className={classNames('py-3', 'outline-none')}> | <Tab.Panel className={classNames('py-3', 'outline-none')}> | ||||
| <ClientFormContext.Provider value={{ clientForm, setClientForm }}> | <ClientFormContext.Provider value={{ clientForm, setClientForm }}> | ||||
| <ClientForm /> | |||||
| <ClientForm mg={mg} /> | |||||
| </ClientFormContext.Provider> | </ClientFormContext.Provider> | ||||
| </Tab.Panel> | </Tab.Panel> | ||||
| <Tab.Panel className={classNames('py-3', 'outline-none')}> | <Tab.Panel className={classNames('py-3', 'outline-none')}> | ||||
| <JobForm | <JobForm | ||||
| cntCareers={cntCareers} | cntCareers={cntCareers} | ||||
| defaultPositionSelection={defaultPositionSelection} | defaultPositionSelection={defaultPositionSelection} | ||||
| mg={mg} | |||||
| /> | /> | ||||
| </JobFormContext.Provider> | </JobFormContext.Provider> | ||||
| </Tab.Panel> | </Tab.Panel> |
| setErrorMsg('CV is Required'); | setErrorMsg('CV is Required'); | ||||
| } else { | } else { | ||||
| setErrorMsg(''); | 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(); | const token = captchaRef.current.getValue(); | ||||
| captchaRef.current.reset(); | captchaRef.current.reset(); | ||||
| if (token.length === 0) { | if (token.length === 0) { | ||||
| setSucMsg(true); | setSucMsg(true); | ||||
| setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | ||||
| setSucMsg(true); | setSucMsg(true); | ||||
| if (res.data.data.success) { | if (res.data.data.success) { | ||||
| setMsgText('Submission Succesful! Thank you!'); | 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 | } else | ||||
| setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | setMsgText('Please fill reCAPTCHA and try again. Thank you!'); | ||||
| }) | }) | ||||
| console.log(error); | console.log(error); | ||||
| }); | }); | ||||
| } | } | ||||
| }); | |||||
| } | |||||
| } | } | ||||
| ReactGA.event('contact', { | ReactGA.event('contact', { | ||||
| category: 'Contact', | category: 'Contact', |
| </svg> | </svg> | ||||
| ); | ); | ||||
| const onDrop = useCallback(acceptedFiles => { | |||||
| const onDrop = useCallback(async acceptedFiles => { | |||||
| if (acceptedFiles && acceptedFiles.length > 0) { | if (acceptedFiles && acceptedFiles.length > 0) { | ||||
| if (acceptedFiles[0] !== 'undefined' && acceptedFiles[0].type !== 'undefined') { | if (acceptedFiles[0] !== 'undefined' && acceptedFiles[0].type !== 'undefined') { | ||||
| if (acceptedFiles[0].type === 'application/pdf') { | 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); | setEmpty(false); | ||||
| } | } | ||||
| } | } |