Spaces:
Build error
Build error
File size: 5,213 Bytes
54c7479 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import { useState } from 'react';
import { Send, CheckCircle, Loader2 } from 'lucide-react';
export default function ContactForm() {
const [formData, setFormData] = useState({ name: '', email: '', message: '' });
const [status, setStatus] = useState('idle'); // idle, loading, success, error
const handleSubmit = async (e) => {
e.preventDefault();
setStatus('loading');
try {
const response = await fetch('/api/contact', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
if (response.ok) {
setStatus('success');
setFormData({ name: '', email: '', message: '' });
} else {
setStatus('error');
}
} catch (error) {
setStatus('error');
}
};
return (
<section id="contact" className="py-24 relative overflow-hidden">
<div className="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
<div className="glass-panel p-8 md:p-12">
<div className="text-center mb-10">
<h2 className="text-3xl font-bold mb-4">Initialize Connection</h2>
<p className="text-gray-400">Have questions about our robotics? Send a transmission.</p>
</div>
{status === 'success' ? (
<div className="text-center py-12 animate-fade-in">
<div className="inline-flex items-center justify-center w-16 h-16 rounded-full bg-green-500/20 text-green-500 mb-4">
<CheckCircle className="h-8 w-8" />
</div>
<h3 className="text-2xl font-bold mb-2">Transmission Received</h3>
<p className="text-gray-400">Our team will respond within 24 cycles.</p>
<button
onClick={() => setStatus('idle')}
className="mt-6 text-primary hover:text-white underline"
>
Send another message
</button>
</div>
) : (
<form onSubmit={handleSubmit} className="space-y-6">
<div>
<label htmlFor="name" className="block text-sm font-medium text-gray-300 mb-2">
Designation (Name)
</label>
<input
type="text"
id="name"
required
className="w-full bg-black/30 border border-white/10 rounded-lg px-4 py-3 text-white focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-colors"
placeholder="John Doe"
value={formData.name}
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
/>
</div>
<div>
<label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-2">
Frequency (Email)
</label>
<input
type="email"
id="email"
required
className="w-full bg-black/30 border border-white/10 rounded-lg px-4 py-3 text-white focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-colors"
placeholder="john@example.com"
value={formData.email}
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
/>
</div>
<div>
<label htmlFor="message" className="block text-sm font-medium text-gray-300 mb-2">
Data Packet (Message)
</label>
<textarea
id="message"
required
rows={4}
className="w-full bg-black/30 border border-white/10 rounded-lg px-4 py-3 text-white focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-colors"
placeholder="How can we help you?"
value={formData.message}
onChange={(e) => setFormData({ ...formData, message: e.target.value })}
/>
</div>
<button
type="submit"
disabled={status === 'loading'}
className="w-full bg-primary text-dark font-bold py-4 rounded-lg hover:bg-white transition-all flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed"
>
{status === 'loading' ? (
<>
<Loader2 className="h-5 w-5 animate-spin" />
<span>Transmitting...</span>
</>
) : (
<>
<Send className="h-5 w-5" />
<span>Send Transmission</span>
</>
)}
</button>
{status === 'error' && (
<p className="text-red-400 text-center text-sm mt-2">
Transmission failed. Please check your connection and try again.
</p>
)}
</form>
)}
</div>
</div>
</section>
);
} |