From 98271074021f907796e9f7e48e2df00d90c71998 Mon Sep 17 00:00:00 2001 From: Nicolas Caba Date: Mon, 18 Apr 2022 19:10:55 -0300 Subject: [PATCH 1/3] Forms with EmailJS --- src/components/Form/index.js | 104 ++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/src/components/Form/index.js b/src/components/Form/index.js index 453a560..36859cb 100644 --- a/src/components/Form/index.js +++ b/src/components/Form/index.js @@ -1,5 +1,6 @@ import { useState } from 'react'; import styles from './form.module.scss'; +import emailjs from 'emailjs-com'; export const Form = () => { const [type, setType] = useState(null); @@ -27,16 +28,6 @@ export const Form = () => { /> -
- setType(e.target.value)} - type="radio" - id="info" - value="info" - /> - -
@@ -44,8 +35,33 @@ export const Form = () => { }; function FormContent({ type }) { - function onSubmit(e) { + function onSubmitCompany(e) { console.log('submitted'); + e.preventDefault(); + + emailjs.sendForm(process.env.NEXT_PUBLIC_SERVICE_ID, process.env.NEXT_PUBLIC_COMPANY_TEMPLATE_ID, e.target, process.env.NEXT_PUBLIC_USER_ID) + .then((result) => { + console.log(result.text); + alert('Su petición se envio correctamente!!') + location.reload(); + }, (error) => { + alert('Hubo un error, volve a intentarlo.') + console.log(error.text); + }); + } + function onSubmitVolunteer(e) { + console.log('submitted'); + e.preventDefault(); + + emailjs.sendForm(process.env.NEXT_PUBLIC_SERVICE_ID, process.env.NEXT_PUBLIC_VOLUNTEER_TEMPLATE_ID, e.target, process.env.NEXT_PUBLIC_USER_ID) + .then((result) => { + console.log(result.text); + alert('Su petición se envio correctamente!!') + location.reload(); + }, (error) => { + console.log(error.text); + alert('Hubo un error, volve a intentarlo.') + }); } if (type === 'company') { @@ -73,28 +89,36 @@ function FormContent({ type }) { Cualquier inquietud o si es de interés saber más sobre nuestro equipo y tareas, estamos a disposición.

-
+ - - - -