From 4e2bf7b9635a970b14ad37ccc8e7f6c6663bd51b Mon Sep 17 00:00:00 2001 From: Om Kadu Date: Mon, 8 Sep 2025 14:34:04 +0530 Subject: [PATCH] integrated emailjs --- package.json | 1 + src/pages/Contact/Contact.tsx | 226 ++++++++++++++++++---------------- 2 files changed, 119 insertions(+), 108 deletions(-) diff --git a/package.json b/package.json index f2d89f5..287a6b5 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "docker:prod": "docker compose --profile prod up -d --build" }, "dependencies": { + "@emailjs/browser": "^4.4.1", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.6", diff --git a/src/pages/Contact/Contact.tsx b/src/pages/Contact/Contact.tsx index a0bfccb..04919bd 100644 --- a/src/pages/Contact/Contact.tsx +++ b/src/pages/Contact/Contact.tsx @@ -1,14 +1,15 @@ -import { useState, useContext } from "react"; +import emailjs from "@emailjs/browser"; import { + CheckCircle, Github, Mail, Phone, Send, X, - CheckCircle, } from "lucide-react"; -import { ThemeContext } from "../../context/ThemeContext"; +import { useContext, useRef, useState } from "react"; import type { ThemeContextType } from "../../context/ThemeContext"; +import { ThemeContext } from "../../context/ThemeContext"; function Contact() { const [showPopup, setShowPopup] = useState(false); @@ -16,15 +17,41 @@ function Contact() { const themeContext = useContext(ThemeContext) as ThemeContextType; const { mode } = themeContext; - const handleSubmit = async () => { + // Refs for form fields + const nameRef = useRef(null); + const emailRef = useRef(null); + const subjectRef = useRef(null); + const messageRef = useRef(null); + + + const handleSubmit = async (e?: React.MouseEvent) => { + if (e) e.preventDefault(); setIsSubmitting(true); - // Simulate API call - await new Promise((resolve) => setTimeout(resolve, 1500)); + // EmailJS config (replace with your own) + const serviceId = import.meta.env.VITE_EMAILJS_SERVICE_ID; + const templateId = import.meta.env.VITE_EMAILJS_TEMPLATE_ID + const publicKey = import.meta.env.VITE_EMAILJS_USER_ID; - setIsSubmitting(false); - setShowPopup(true); + const templateParams = { + from_name: nameRef.current?.value || "", + from_email: emailRef.current?.value || "", + subject: subjectRef.current?.value || "", + message: messageRef.current?.value || "", + }; + try { + await emailjs.send(serviceId, templateId, templateParams, publicKey); + setShowPopup(true); + // Optionally clear fields + if (nameRef.current) nameRef.current.value = ""; + if (emailRef.current) emailRef.current.value = ""; + if (subjectRef.current) subjectRef.current.value = ""; + if (messageRef.current) messageRef.current.value = ""; + } catch (error) { + // Optionally handle error (show error popup, etc.) + } + setIsSubmitting(false); // Auto-close popup after 5 seconds setTimeout(() => { setShowPopup(false); @@ -37,11 +64,10 @@ function Contact() { return (
{/* Animated background elements */}
@@ -55,9 +81,8 @@ function Contact() {

Get in touch with us to discuss your project tracking needs or report any issues @@ -87,16 +111,14 @@ function Contact() {

Let's Connect

We're here to help you track and manage your GitHub repositories more effectively @@ -133,49 +155,44 @@ function Contact() { return (

{title}

{detail}

{sub}

@@ -189,16 +206,14 @@ function Contact() { {/* Contact Form */}

Send us a Message

@@ -208,11 +223,10 @@ function Contact() { {/* Full Name */}
@@ -220,22 +234,21 @@ function Contact() { type="text" placeholder="Enter your full name" required - className={`w-full p-2 sm:p-3 rounded-lg sm:rounded-xl text-sm sm:text-base transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500 ${ - mode === "dark" - ? "bg-white/5 border border-white/20 text-white placeholder-gray-400" - : "bg-gray-50 border border-gray-300 text-gray-800 placeholder-gray-500" - }`} + ref={nameRef} + className={`w-full p-2 sm:p-3 rounded-lg sm:rounded-xl text-sm sm:text-base transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500 ${mode === "dark" + ? "bg-white/5 border border-white/20 text-white placeholder-gray-400" + : "bg-gray-50 border border-gray-300 text-gray-800 placeholder-gray-500" + }`} />
{/* Email */}
@@ -243,33 +256,32 @@ function Contact() { type="email" placeholder="your.email@example.com" required - className={`w-full p-2 sm:p-3 rounded-lg sm:rounded-xl text-sm sm:text-base transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500 ${ - mode === "dark" - ? "bg-white/5 border border-white/20 text-white placeholder-gray-400" - : "bg-gray-50 border border-gray-300 text-gray-800 placeholder-gray-500" - }`} + ref={emailRef} + className={`w-full p-2 sm:p-3 rounded-lg sm:rounded-xl text-sm sm:text-base transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-purple-500 ${mode === "dark" + ? "bg-white/5 border border-white/20 text-white placeholder-gray-400" + : "bg-gray-50 border border-gray-300 text-gray-800 placeholder-gray-500" + }`} />
{/* Subject */}