further fixes
This commit is contained in:
40
app/page.tsx
40
app/page.tsx
@@ -18,6 +18,7 @@ export default function Page() {
|
||||
const [mailboxes, setMailboxes] = useState(10);
|
||||
const [formErrors, setFormErrors] = useState({ name: "", email: "" });
|
||||
const [formStatus, setFormStatus] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const storedTheme = window.localStorage.getItem("bes-theme");
|
||||
@@ -112,7 +113,7 @@ export default function Page() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleAssessmentSubmit = (event: FormEvent<HTMLFormElement>) => {
|
||||
const handleAssessmentSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const formData = new FormData(form);
|
||||
@@ -139,8 +140,40 @@ export default function Page() {
|
||||
return;
|
||||
}
|
||||
|
||||
setFormStatus("Thanks. We'll review your mailbox count and current provider before we reply.");
|
||||
form.reset();
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/assessment", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
email,
|
||||
mailboxes: formData.get("mailboxes") ?? "",
|
||||
provider: formData.get("provider") ?? "",
|
||||
message: formData.get("message") ?? "",
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
setFormStatus("Thanks. We'll review your mailbox count and current provider before we reply.");
|
||||
form.reset();
|
||||
} else {
|
||||
const data = await response.json().catch(() => null);
|
||||
if (data?.fields) {
|
||||
setFormErrors({
|
||||
name: data.fields.name ?? "",
|
||||
email: data.fields.email ?? "",
|
||||
});
|
||||
} else {
|
||||
setFormStatus(data?.error ?? "Something went wrong. Please try again or call us.");
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
setFormStatus("Network error. Please check your connection and try again.");
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -167,6 +200,7 @@ export default function Page() {
|
||||
<AssessmentSection
|
||||
formErrors={formErrors}
|
||||
formStatus={formStatus}
|
||||
isSubmitting={isSubmitting}
|
||||
onAssessmentSubmit={handleAssessmentSubmit}
|
||||
/>
|
||||
</main>
|
||||
|
||||
Reference in New Issue
Block a user