Add the Kaman Cable Next.js storefront with Meshkee catalog, blog, auth, and static-image slots.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import { FormEvent, useState } from "react";
|
||||
|
||||
export default function CallbackForm() {
|
||||
const [status, setStatus] = useState<"idle" | "sending" | "ok" | "error">("idle");
|
||||
const [message, setMessage] = useState("");
|
||||
|
||||
async function onSubmit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const data = new FormData(form);
|
||||
const name = String(data.get("name") || "").trim();
|
||||
const cellNumber = String(data.get("cellNumber") || "").trim();
|
||||
setStatus("sending");
|
||||
setMessage("");
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/contact", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name,
|
||||
title: "درخواست تماس",
|
||||
cellNumber,
|
||||
text: `درخواست تماس از صفحه اصلی. شماره: ${cellNumber}`,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
setStatus("error");
|
||||
setMessage("ثبت شماره انجام نشد. لطفاً دوباره تلاش کنید.");
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus("ok");
|
||||
setMessage("شماره شما ثبت شد. بهزودی تماس میگیریم.");
|
||||
form.reset();
|
||||
} catch {
|
||||
setStatus("error");
|
||||
setMessage("ارتباط با سرور برقرار نشد.");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="callback-form" onSubmit={onSubmit}>
|
||||
<label className="sr-only" htmlFor="callback-name">
|
||||
نام
|
||||
</label>
|
||||
<input id="callback-name" name="name" type="text" required placeholder="نام" autoComplete="name" />
|
||||
<label className="sr-only" htmlFor="callback-phone">
|
||||
شماره تماس
|
||||
</label>
|
||||
<input
|
||||
id="callback-phone"
|
||||
name="cellNumber"
|
||||
type="tel"
|
||||
required
|
||||
inputMode="tel"
|
||||
placeholder="شماره تماس"
|
||||
autoComplete="tel"
|
||||
/>
|
||||
<button type="submit" className="btn btn-gold" disabled={status === "sending"}>
|
||||
{status === "sending" ? "در حال ارسال…" : "ثبت شماره"}
|
||||
</button>
|
||||
{message ? <p className={status === "ok" ? "ok" : "err"}>{message}</p> : null}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user