Skip to content

Commit a2c8487

Browse files
committed
fix(contact): implement working email functionality for contact form
- Add mailto link functionality to send messages via email client - Implement loading states and form validation - Add success/error status messages with auto-dismiss - Disable form fields during submission - Reset form after successful submission - Improve user experience with proper feedback
1 parent 608ef81 commit a2c8487

1 file changed

Lines changed: 65 additions & 4 deletions

File tree

src/components/Contact.tsx

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,51 @@ const Contact: React.FC = () => {
88
email: '',
99
message: '',
1010
});
11+
const [isSubmitting, setIsSubmitting] = useState(false);
12+
const [submitStatus, setSubmitStatus] = useState<'idle' | 'success' | 'error'>('idle');
1113

1214
const handleSubmit = (e: React.FormEvent) => {
1315
e.preventDefault();
14-
// Handle form submission logic here
15-
console.log('Form submitted:', formData);
16+
setIsSubmitting(true);
17+
setSubmitStatus('idle');
18+
19+
try {
20+
// Create email content
21+
const subject = `Portfolio Contact from ${formData.name}`;
22+
const body = `Name: ${formData.name}\nEmail: ${formData.email}\n\nMessage:\n${formData.message}`;
23+
24+
// Create mailto link
25+
const mailtoLink = `mailto:davidsyagustin@gmail.com?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
26+
27+
// Open default email client
28+
window.open(mailtoLink, '_blank');
29+
30+
// Show success message
31+
setSubmitStatus('success');
32+
33+
// Reset form
34+
setFormData({
35+
name: '',
36+
email: '',
37+
message: '',
38+
});
39+
40+
// Reset status after 3 seconds
41+
setTimeout(() => {
42+
setSubmitStatus('idle');
43+
}, 3000);
44+
45+
} catch (error) {
46+
console.error('Error sending message:', error);
47+
setSubmitStatus('error');
48+
49+
// Reset error status after 3 seconds
50+
setTimeout(() => {
51+
setSubmitStatus('idle');
52+
}, 3000);
53+
} finally {
54+
setIsSubmitting(false);
55+
}
1656
};
1757

1858
const handleChange = (
@@ -93,6 +133,7 @@ const Contact: React.FC = () => {
93133
onChange={handleChange}
94134
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
95135
required
136+
disabled={isSubmitting}
96137
/>
97138
</div>
98139
<div>
@@ -110,6 +151,7 @@ const Contact: React.FC = () => {
110151
onChange={handleChange}
111152
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
112153
required
154+
disabled={isSubmitting}
113155
/>
114156
</div>
115157
<div>
@@ -127,10 +169,29 @@ const Contact: React.FC = () => {
127169
rows={5}
128170
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
129171
required
172+
disabled={isSubmitting}
130173
/>
131174
</div>
132-
<button type="submit" className="w-full btn btn-primary">
133-
Send Message
175+
176+
{/* Status Messages */}
177+
{submitStatus === 'success' && (
178+
<div className="p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg">
179+
✅ Message sent successfully! Your email client should open with the message ready to send.
180+
</div>
181+
)}
182+
183+
{submitStatus === 'error' && (
184+
<div className="p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg">
185+
❌ There was an error sending your message. Please try again or email me directly at davidsyagustin@gmail.com
186+
</div>
187+
)}
188+
189+
<button
190+
type="submit"
191+
className={`w-full btn btn-primary ${isSubmitting ? 'opacity-50 cursor-not-allowed' : ''}`}
192+
disabled={isSubmitting}
193+
>
194+
{isSubmitting ? 'Sending...' : 'Send Message'}
134195
</button>
135196
</form>
136197
</div>

0 commit comments

Comments
 (0)