diff --git a/src/pages/Contact/Contact.tsx b/src/pages/Contact/Contact.tsx index a0bfccb..bd6d64b 100644 --- a/src/pages/Contact/Contact.tsx +++ b/src/pages/Contact/Contact.tsx @@ -6,17 +6,118 @@ import { Send, X, CheckCircle, + Shield, + Clock, + Calendar, + User, + MessageSquare, } from "lucide-react"; import { ThemeContext } from "../../context/ThemeContext"; import type { ThemeContextType } from "../../context/ThemeContext"; +type FormData = { + name: string; + email: string; + subject: string; + message: string; +}; + +type FormErrors = { + name: string; + email: string; + subject: string; + message: string; +}; + function Contact() { const [showPopup, setShowPopup] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); + + const [formData, setFormData] = useState({ + name: "", + email: "", + subject: "", + message: "", + }); + + const [errors, setErrors] = useState({ + name: "", + email: "", + subject: "", + message: "", + }); + const themeContext = useContext(ThemeContext) as ThemeContextType; const { mode } = themeContext; - const handleSubmit = async () => { + const handleInputChange = ( + e: React.ChangeEvent< + HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement + >, + ) => { + const { name, value } = e.target; + + setFormData((prev) => ({ + ...prev, + [name]: value, + })); + + // Clear error for the current field + if (errors[name as keyof FormErrors]) { + setErrors((prev) => ({ + ...prev, + [name]: "", + })); + } + }; + + const validateForm = () => { + const newErrors: FormErrors = { + name: "", + email: "", + subject: "", + message: "", + }; + + let isValid = true; + + if (!formData.name.trim()) { + newErrors.name = "Full name is required."; + isValid = false; + } + + if (!formData.email.trim()) { + newErrors.email = "Email address is required."; + isValid = false; + } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) { + newErrors.email = "Please enter a valid email address."; + isValid = false; + } + + if (!formData.subject) { + newErrors.subject = "Please select a subject."; + isValid = false; + } + + if (!formData.message.trim()) { + newErrors.message = "Message is required."; + isValid = false; + } else if (formData.message.trim().length < 20) { + newErrors.message = "Please provide at least 20 characters."; + isValid = false; + } + + setErrors(newErrors); + return isValid; + }; + + const handleSubmit = async ( + e?: React.FormEvent | React.MouseEvent, + ) => { + e?.preventDefault(); + + if (!validateForm()) return; + setIsSubmitting(true); // Simulate API call @@ -25,6 +126,14 @@ function Contact() { setIsSubmitting(false); setShowPopup(true); + // Reset form + setFormData({ + name: "", + email: "", + subject: "", + message: "", + }); + // Auto-close popup after 5 seconds setTimeout(() => { setShowPopup(false); @@ -51,7 +160,7 @@ function Contact() {
- {/* Header Section */} + {/* Header Section (unchanged) */}

GitHub Tracker @@ -83,7 +192,7 @@ function Contact() {

- {/* Contact Info Cards */} + {/* Contact Info Cards (unchanged) */}

- We're here to help you track and manage your GitHub - repositories more effectively + We're here to help you track and manage your GitHub repositories + more effectively

@@ -128,8 +237,10 @@ function Contact() { Icon: Github, }, ]; + const { title, iconBg, detail, sub, Icon } = contactTypes[index]; + return (

{title}

{detail}

{sub} @@ -187,7 +290,7 @@ function Contact() {

- {/* Contact Form */} + {/* Enhanced Contact Form */}

Send us a Message

-
-
- {/* Full Name */} -
- - -
+
+
+ {/* Name + Email */} +
+ {/* Full Name */} +
+ +
+ + +
+ {errors.name && ( +

{errors.name}

+ )} +
- {/* Email */} -
- - + {/* Email */} +
+ +
+ + +
+ {errors.email && ( +

+ {errors.email} +

+ )} +
{/* Subject */}
+ {errors.subject && ( +

+ {errors.subject} +

+ )}
{/* Message */} -
+
- - -