Add owner portal, i18n, contact API, and region/footer assets
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
type ContactBody = {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
mobile?: string;
|
||||
subject?: string;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const token = process.env.TEABLE_API_TOKEN;
|
||||
const tableId = process.env.TEABLE_TABLE_ID;
|
||||
|
||||
if (!token || !tableId) {
|
||||
return NextResponse.json(
|
||||
{ error: "Server is not configured for submissions." },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
let body: ContactBody;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Invalid request body." }, { status: 400 });
|
||||
}
|
||||
|
||||
const firstName = (body.firstName ?? "").trim();
|
||||
const lastName = (body.lastName ?? "").trim();
|
||||
const email = (body.email ?? "").trim();
|
||||
const mobile = (body.mobile ?? "").trim();
|
||||
const subject = (body.subject ?? "").trim();
|
||||
const message = (body.message ?? "").trim();
|
||||
|
||||
const name = `${firstName} ${lastName}`.trim();
|
||||
|
||||
if (!name || !email || !message) {
|
||||
return NextResponse.json(
|
||||
{ error: "Name, email and message are required." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// The Teable table is job-application shaped; map contact details onto the
|
||||
// free-text fields that fit. Subject + mobile are folded into why_role so no
|
||||
// information is lost.
|
||||
const why_role = [
|
||||
subject && `Subject: ${subject}`,
|
||||
mobile && `Mobile: ${mobile}`,
|
||||
message,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n");
|
||||
|
||||
const res = await fetch(
|
||||
`https://app.teable.ai/api/table/${tableId}/record`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
fieldKeyType: "name",
|
||||
records: [{ fields: { name, email, why_role } }],
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const detail = await res.text();
|
||||
console.error("Teable error:", res.status, detail);
|
||||
return NextResponse.json(
|
||||
{ error: "Could not save your message. Please try again." },
|
||||
{ status: 502 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
}
|
||||
Reference in New Issue
Block a user