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