From 40bbe2674edadffa1ad394307674e57683f02228 Mon Sep 17 00:00:00 2001 From: mces58 Date: Fri, 9 Aug 2024 11:31:48 +0300 Subject: [PATCH] feat: optimize Contact component with form submission functionality and animations --- v2/src/components/Contact.jsx | 131 ++++++++++++++++++++++++++++- v2/src/components/canvas/Earth.jsx | 43 ++++++++++ 2 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 v2/src/components/canvas/Earth.jsx diff --git a/v2/src/components/Contact.jsx b/v2/src/components/Contact.jsx index 92e6625..e6c64cf 100644 --- a/v2/src/components/Contact.jsx +++ b/v2/src/components/Contact.jsx @@ -1,7 +1,132 @@ -import React from 'react'; +import { useRef, useState } from 'react'; + +import emailjs from '@emailjs/browser'; +import { motion } from 'framer-motion'; + +import EarthCanvas from '@/components/canvas/Earth'; +import SectionWrapper from '@/hoc/SectionWrapper'; +import { styles } from '@/styles'; +import { slideIn } from '@/utils/motion'; const Contact = () => { - return
Contact
; + const formRef = useRef(); + const [form, setForm] = useState({ + name: '', + email: '', + message: '', + }); + + const [loading, setLoading] = useState(false); + + const handleChange = (e) => { + const { target } = e; + const { name, value } = target; + + setForm({ + ...form, + [name]: value, + }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + setLoading(true); + + emailjs + .send( + import.meta.env.VITE_APP_EMAILJS_SERVICE_ID, + import.meta.env.VITE_APP_EMAILJS_TEMPLATE_ID, + { + from_name: form.name, + to_name: 'JavaScript Mastery', + from_email: form.email, + to_email: 'sujata@jsmastery.pro', + message: form.message, + }, + import.meta.env.VITE_APP_EMAILJS_PUBLIC_KEY + ) + .then( + () => { + setLoading(false); + alert('Thank you. I will get back to you as soon as possible.'); + + setForm({ + name: '', + email: '', + message: '', + }); + }, + (error) => { + setLoading(false); + console.error(error); + + alert('Ahh, something went wrong. Please try again.'); + } + ); + }; + return ( +
+ +

Get in touch

+

Contact.

+ +
+ + +