-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHeroArchitectForm.tsx
More file actions
171 lines (152 loc) · 8.83 KB
/
Copy pathHeroArchitectForm.tsx
File metadata and controls
171 lines (152 loc) · 8.83 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, { useState } from 'react';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Calendar } from '@/components/ui/calendar';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Calendar as CalendarIcon, Phone, MapPin } from 'lucide-react';
import { format } from 'date-fns';
import { useToast } from '@/hooks/use-toast';
import { supabase } from '@/integrations/supabase/client';
export function HeroArchitectForm() {
const [preferredDate, setPreferredDate] = useState<Date | undefined>();
const [dateOpen, setDateOpen] = useState(false);
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [phone, setPhone] = useState('');
const [projectType, setProjectType] = useState('');
const [location, setLocation] = useState('');
const [budget, setBudget] = useState('');
const [message, setMessage] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const { toast } = useToast();
const validate = () => {
if (!name.trim()) return 'Please enter your name';
if (!phone.trim() || phone.replace(/\D/g, '').length < 10) return 'Please enter a valid 10-digit phone number';
if (!projectType) return 'Please select a project type';
return null;
};
const handleSubmit = async () => {
const errorMsg = validate();
if (errorMsg) {
toast({ title: 'Error', description: errorMsg, variant: 'destructive' });
return;
}
if (isSubmitting) return;
setIsSubmitting(true);
try {
const payload: any = {
client_name: name.trim(),
phone: phone.trim(),
project_type: projectType,
preferred_date: preferredDate ? format(preferredDate, 'yyyy-MM-dd') : null,
location: location.trim() || null,
budget: budget ? Number(budget) : null,
message: message.trim() || null,
status: 'pending',
created_at: new Date().toISOString(),
};
const { error } = await supabase.from('ArchitectRequest').insert([payload]);
if (error) throw error;
toast({ title: 'Request sent', description: 'We will contact you soon.', });
// reset
setPreferredDate(undefined);
setName('');
setPhone('');
setProjectType('');
setLocation('');
setBudget('');
setMessage('');
} catch (err: any) {
console.error('Architect request error', err);
toast({ title: 'Error', description: err?.message || 'Failed to submit request', variant: 'destructive' });
} finally {
setIsSubmitting(false);
}
};
return (
<section id="hero-form" className="hero-pattern from-primary/5 to-background py-16">
<div className="container mx-auto px-4">
<h1 className="text-4xl font-bold mb-8 text-center">Book Architect/Designer Services</h1>
<div className="max-w-4xl mx-auto bg-white p-8 rounded-2xl shadow-2xl">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-4">
<div>
<label className="text-sm font-medium text-sky-900">Full name</label>
<Input value={name} onChange={(e) => setName(e.target.value)} placeholder="Your full name" />
</div>
<div>
<label className="text-sm font-medium text-sky-900">Phone</label>
<div className="relative">
<Phone className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-500" />
<Input className="pl-10" value={phone} onChange={(e) => setPhone(e.target.value.replace(/\D/g, '').slice(0, 10))} placeholder="Phone number" />
</div>
{phone && phone.length < 10 && <p className="text-sm text-red-500">Enter 10 digits</p>}
</div>
<div>
<label className="text-sm font-medium text-sky-900">Project type</label>
<Select value={projectType} onValueChange={setProjectType}>
<SelectTrigger className="bg-white">
<SelectValue placeholder="Select project type" />
</SelectTrigger>
<SelectContent>
<SelectItem value="residential">Residential</SelectItem>
<SelectItem value="commercial">Commercial</SelectItem>
<SelectItem value="interior">Interior Design</SelectItem>
<SelectItem value="landscape">Landscape</SelectItem>
<SelectItem value="renovation">Renovation/Remodel</SelectItem>
</SelectContent>
</Select>
</div>
<div>
<label className="text-sm font-medium text-sky-900">Preferred date</label>
<Popover open={dateOpen} onOpenChange={setDateOpen}>
<PopoverTrigger asChild>
<Button variant="outline" className={`w-full justify-start text-left font-normal bg-white ${!preferredDate ? 'text-muted-foreground' : ''}`} onClick={() => setDateOpen(!dateOpen)}>
<CalendarIcon className="mr-2 h-4 w-4" />
{preferredDate ? format(preferredDate, 'PPP') : <span>Select date</span>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={preferredDate}
onSelect={(d) => { setPreferredDate(d); setDateOpen(false); }}
initialFocus
className="p-3"
disabled={(d) => d <= new Date(new Date().setHours(0, 0, 0, 0))}
/>
</PopoverContent>
</Popover>
</div>
</div>
<div className="space-y-4">
<div>
<label className="text-sm font-medium text-sky-900">Location</label>
<div className="relative">
<MapPin className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-500" />
<Input className="pl-10" value={location} onChange={(e) => setLocation(e.target.value)} placeholder="Enter your address" />
</div>
</div>
<div>
<label className="text-sm font-medium text-sky-900">Estimated budget (optional)</label>
<Input value={budget} onChange={(e) => setBudget(e.target.value.replace(/[^0-9]/g, ''))} placeholder="Budget" />
</div>
<div>
<label className="text-sm font-medium text-sky-900">Message (optional)</label>
<Textarea className="h-32" value={message} onChange={(e) => setMessage(e.target.value)} placeholder="Brief project details" />
</div>
</div>
</div>
<div className="mt-6">
<Button onClick={handleSubmit} className="w-full animate-pulse-shadow" disabled={isSubmitting}>
{isSubmitting ? 'Sending...' : 'Request Architect'}
</Button>
</div>
</div>
</div>
</section>
);
}
export default HeroArchitectForm;