-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from Puskar-Roy/dev
Dev
- Loading branch information
Showing
2 changed files
with
188 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,92 @@ | ||
// Import necessary modules from React | ||
import React, { useState } from 'react'; | ||
import { FaMapMarkerAlt, FaPhone, FaEnvelope } from 'react-icons/fa'; | ||
|
||
// Interface to define the props for ContactForm | ||
interface ContactFormProps { | ||
onClose: () => void; // Function to handle modal close event | ||
onClose: () => void; | ||
} | ||
|
||
// Functional component definition for ContactForm | ||
const ContactForm: React.FC<ContactFormProps> = ({ onClose }) => { | ||
// State to manage form data (name, email, and message) | ||
const [formData, setFormData] = useState({ name: '', email: '', message: '' }); | ||
|
||
// State to track if the form has been submitted | ||
const [submitted, setSubmitted] = useState(false); | ||
|
||
// Event handler for input and textarea changes | ||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => { | ||
const { name, value } = e.target; // Destructure name and value from the target element | ||
setFormData((prev) => ({ ...prev, [name]: value })); // Update the form state dynamically | ||
const { name, value } = e.target; | ||
setFormData((prev) => ({ ...prev, [name]: value })); | ||
}; | ||
|
||
// Event handler for form submission | ||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); // Prevent default form submission behavior | ||
console.log(formData); // Log form data (can be replaced with API call) | ||
setSubmitted(true); // Set the submitted state to true | ||
setFormData({ name: '', email: '', message: '' }); // Reset form fields after submission | ||
e.preventDefault(); | ||
console.log(formData); | ||
setSubmitted(true); | ||
setFormData({ name: '', email: '', message: '' }); | ||
}; | ||
|
||
return ( | ||
<div className="modal"> | ||
<div className="modal-content dark-theme"> | ||
{/* Close button for the modal */} | ||
<span className="close" onClick={onClose}>×</span> | ||
|
||
{/* Conditional rendering based on form submission status */} | ||
{submitted ? ( | ||
<div className="success-message">Thank you for contacting us!</div> | ||
) : ( | ||
<form onSubmit={handleSubmit}> | ||
<h2 className="form-title neon-title">Contact Us</h2> | ||
|
||
{/* Name Input Field */} | ||
<label htmlFor="name">Name:</label> | ||
<input | ||
type="text" | ||
id="name" | ||
name="name" | ||
value={formData.name} | ||
onChange={handleChange} | ||
required | ||
className="form-input neon-input" | ||
/> | ||
|
||
{/* Email Input Field */} | ||
<label htmlFor="email">Email:</label> | ||
<input | ||
type="email" | ||
id="email" | ||
name="email" | ||
value={formData.email} | ||
onChange={handleChange} | ||
required | ||
className="form-input neon-input" | ||
/> | ||
|
||
{/* Message Textarea */} | ||
<label htmlFor="message">Message:</label> | ||
<textarea | ||
id="message" | ||
name="message" | ||
value={formData.message} | ||
onChange={handleChange} | ||
required | ||
className="form-textarea neon-input" | ||
></textarea> | ||
|
||
{/* Submit Button */} | ||
<button type="submit" className="submit-button neon-button"> | ||
Send Message | ||
</button> | ||
</form> | ||
)} | ||
<div className="contact-container"> | ||
<div className="info-column"> | ||
<h2 className="info-title"><b>Contact Information</b></h2> | ||
<p> | ||
<FaMapMarkerAlt className="info-icon" size={40} /> | ||
<strong> Location:</strong><br /> Kolkata - 700121 | ||
</p> | ||
<br /> | ||
<p> | ||
<FaPhone className="info-icon" size={40} /> | ||
<strong> Phone:</strong><br /> +123 456 7890 | ||
</p> | ||
<br /> | ||
<p> | ||
<FaEnvelope className="info-icon" size={40} /> | ||
<strong> Email:</strong><br /> puskarroy600@gmail.com | ||
</p> | ||
</div> | ||
<div className="separator" /> {/* Added separator */} | ||
<div className="form-column"> | ||
{submitted ? ( | ||
<div className="success-message">Thank you for contacting us!</div> | ||
) : ( | ||
<form onSubmit={handleSubmit}> | ||
<h2 className="form-title neon-title">Contact Us</h2> | ||
<label htmlFor="name">Name:</label> | ||
<input | ||
type="text" | ||
id="name" | ||
name="name" | ||
value={formData.name} | ||
onChange={handleChange} | ||
required | ||
className="form-input neon-input" | ||
/> | ||
<label htmlFor="email">Email:</label> | ||
<input | ||
type="email" | ||
id="email" | ||
name="email" | ||
value={formData.email} | ||
onChange={handleChange} | ||
required | ||
className="form-input neon-input" | ||
/> | ||
<label htmlFor="message">Message:</label> | ||
<textarea | ||
id="message" | ||
name="message" | ||
value={formData.message} | ||
onChange={handleChange} | ||
required | ||
className="form-textarea neon-input" | ||
></textarea> | ||
<button type="submit" className="submit-button neon-button">Send Message</button> | ||
</form> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ContactForm; // Export the ContactForm component | ||
export default ContactForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters