Repository navigation
Expand file tree
/
Copy pathInquiryModal.js
More file actions
193 lines (174 loc) · 8.97 KB
/
Copy pathInquiryModal.js
File metadata and controls
193 lines (174 loc) · 8.97 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
'use client';
import { useEffect, useRef, useState } from 'react';
export default function InquiryModal({ config, onClose }) {
const [submitted, setSubmitted] = useState(false);
const [loading, setLoading] = useState(false);
const [errorMsg, setErrorMsg] = useState('');
const [formData, setFormData] = useState({ name: '', email: '', company: '', scope: '' });
const requestKey = useRef(null);
const updateField = (field, value) => {
requestKey.current = null;
setFormData((current) => ({ ...current, [field]: value }));
};
useEffect(() => {
const handleKeyDown = (event) => {
if (event.key === 'Escape' && !loading) onClose();
};
document.addEventListener('keydown', handleKeyDown);
const previousOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
return () => {
document.removeEventListener('keydown', handleKeyDown);
document.body.style.overflow = previousOverflow;
};
}, [loading, onClose]);
if (!config) return null;
const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);
setErrorMsg('');
try {
requestKey.current ||= crypto.randomUUID();
const response = await fetch('/api/inquiries', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Idempotency-Key': requestKey.current,
},
body: JSON.stringify({
projectType: config.title || 'General Custom Scope',
scope: formData.scope,
company: formData.company,
name: formData.name,
email: formData.email,
}),
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.error || 'The inquiry could not be submitted.');
}
requestKey.current = null;
setSubmitted(true);
} catch (err) {
console.error('Error submitting inquiry:', err);
setErrorMsg('Failed to submit inquiry. Please try again.');
} finally {
setLoading(false);
}
};
return (
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4" onMouseDown={(event) => { if (event.target === event.currentTarget && !loading) onClose(); }}>
<div role="dialog" aria-modal="true" aria-labelledby="inquiry-title" className="bg-white dark:bg-bg-surface-dark text-slate-900 dark:text-foreground border border-slate-200 dark:border-white/10 shadow-2xl p-6 md:p-8 rounded-2xl relative w-full max-w-lg z-50">
<button
onClick={onClose}
aria-label="Close inquiry form"
className="absolute top-4 right-4 w-9 h-9 rounded-lg border border-slate-200 dark:border-white/10 bg-white dark:bg-bg-surface-dark text-slate-900 dark:text-foreground font-semibold flex items-center justify-center hover:bg-slate-100 dark:hover:bg-white/10 cursor-pointer"
>
✕
</button>
{!submitted ? (
<div>
<span className="text-xs font-semibold tracking-wider text-black bg-accent-soft px-2.5 py-1 border border-slate-200 inline-block mb-4 shadow-card-sm">
Direct Consultation Channel
</span>
<h2 id="inquiry-title" className="font-display font-semibold text-2xl text-slate-900 dark:text-foreground mb-2 tracking-tight">
{config.title || 'Initiate Client Inquiry'}
</h2>
<p className="text-xs text-black dark:text-zinc-400 font-semibold leading-relaxed mb-6">
Share a few details so our delivery team can understand what you need and recommend a practical next step.
</p>
<form onSubmit={handleSubmit} className="space-y-4 text-xs font-semibold ">
<div>
<label htmlFor="inquiry-name" className="block text-slate-900 dark:text-foreground mb-1">Full Name *</label>
<input
id="inquiry-name"
required
type="text"
placeholder="e.g. Alex Sterling"
value={formData.name}
onChange={e => updateField('name', e.target.value)}
className="w-full px-3.5 py-2.5 rounded-lg bg-white dark:bg-zinc-900 border border-slate-200 dark:border-white/10 text-xs text-slate-900 dark:text-foreground focus:outline-none shadow-sm dark:shadow-sm focus:bg-accent-soft focus:text-black focus:border-slate-200 transition-colors duration-200"
/>
</div>
<div>
<label htmlFor="inquiry-email" className="block text-slate-900 dark:text-foreground mb-1">Work Email *</label>
<input
id="inquiry-email"
required
type="email"
placeholder="alex@company.com"
value={formData.email}
onChange={e => updateField('email', e.target.value)}
className="w-full px-3.5 py-2.5 rounded-lg bg-white dark:bg-zinc-900 border border-slate-200 dark:border-white/10 text-xs text-slate-900 dark:text-foreground focus:outline-none shadow-sm dark:shadow-sm focus:bg-accent-soft focus:text-black focus:border-slate-200 transition-colors duration-200"
/>
</div>
<div>
<label htmlFor="inquiry-company" className="block text-slate-900 dark:text-foreground mb-1">Company / Organization</label>
<input
id="inquiry-company"
type="text"
placeholder="e.g. Vanguard Labs"
value={formData.company}
onChange={e => updateField('company', e.target.value)}
className="w-full px-3.5 py-2.5 rounded-lg bg-white dark:bg-zinc-900 border border-slate-200 dark:border-white/10 text-xs text-slate-900 dark:text-foreground focus:outline-none shadow-sm dark:shadow-sm focus:bg-accent-soft focus:text-black focus:border-slate-200 transition-colors duration-200"
/>
</div>
<div>
<label htmlFor="inquiry-scope" className="block text-slate-900 dark:text-foreground mb-1">Project Scope & Requirements</label>
<textarea
id="inquiry-scope"
rows={3}
required
minLength={10}
maxLength={5000}
placeholder="Detail your technology requirements, timeframe, or desired features..."
value={formData.scope}
onChange={e => updateField('scope', e.target.value)}
className="w-full px-3.5 py-2.5 rounded-lg bg-white dark:bg-zinc-900 border border-slate-200 dark:border-white/10 text-xs text-slate-900 dark:text-foreground focus:outline-none shadow-sm dark:shadow-sm focus:bg-accent-soft focus:text-black focus:border-slate-200 transition-colors duration-200"
></textarea>
</div>
{errorMsg && (
<div className="p-3 bg-red-100 border border-red-650 text-red-650 text-xs font-semibold">
{errorMsg}
</div>
)}
<div className="pt-2 flex justify-end gap-3">
<button
type="button"
onClick={onClose}
disabled={loading}
className="btn-secondary-invert text-xs py-2.5 px-4 cursor-pointer"
>
Cancel
</button>
<button
type="submit"
disabled={loading}
className="btn-primary-invert text-xs py-2.5 px-5 flex items-center gap-2 cursor-pointer"
>
{loading && <span className="w-3.5 h-3.5 border border-t-transparent border-[#F7F7F8] rounded-full animate-spin"></span>}
<span>Submit Inquiry</span>
</button>
</div>
</form>
</div>
) : (
<div className="text-center py-6 space-y-4">
<div className="w-12 h-12 border border-slate-200 dark:border-white/10 text-slate-900 dark:text-foreground bg-accent-soft mx-auto flex items-center justify-center font-semibold text-2xl shadow-card-sm">
✓
</div>
<h3 className="font-display font-semibold text-2xl text-slate-900 dark:text-foreground">
Inquiry Received
</h3>
<p className="text-xs text-black dark:text-zinc-400 font-semibold max-w-sm mx-auto leading-relaxed">
Thank you, <span className="font-semibold text-slate-900 dark:text-foreground">{formData.name}</span>. Our team has received your request and will follow up at <span className="font-semibold text-brand-600 dark:text-brand-400">{formData.email}</span> within 24–48 business hours.
</p>
<button onClick={onClose} className="btn-primary-invert text-xs py-2 px-6 cursor-pointer">
Close Window
</button>
</div>
)}
</div>
</div>
);
}