mirror of
https://github.com/Since-3/since3-website.git
synced 2026-10-12 20:51:17 +00:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
"use server"
|
|
|
|
import { z } from "zod"
|
|
|
|
import {
|
|
contactSchema,
|
|
type ContactFormState,
|
|
} from "@/modules/landingPage/schema/contact-schema"
|
|
|
|
export async function submitContact(
|
|
_prevState: ContactFormState,
|
|
formData: FormData
|
|
): Promise<ContactFormState> {
|
|
// Honeypot: real people never see or fill this field
|
|
if (formData.get("website")) {
|
|
return { status: "success", message: "Danke! Wir melden uns innerhalb von zwei Werktagen." }
|
|
}
|
|
|
|
const raw = {
|
|
name: String(formData.get("name") ?? ""),
|
|
email: String(formData.get("email") ?? ""),
|
|
company: String(formData.get("company") ?? "") || undefined,
|
|
message: String(formData.get("message") ?? ""),
|
|
privacy: formData.get("privacy") ?? undefined,
|
|
}
|
|
|
|
const parsed = contactSchema.safeParse(raw)
|
|
|
|
if (!parsed.success) {
|
|
return {
|
|
status: "error",
|
|
message: "Bitte prüfe die markierten Felder.",
|
|
fieldErrors: z.flattenError(parsed.error).fieldErrors,
|
|
values: {
|
|
name: raw.name,
|
|
email: raw.email,
|
|
company: raw.company,
|
|
message: raw.message,
|
|
privacy: raw.privacy === "on",
|
|
},
|
|
}
|
|
}
|
|
|
|
// TODO: deliver the inquiry, e.g. via a mail provider (Resend, Postmark, SMTP).
|
|
// Keep personal data out of logs.
|
|
|
|
return {
|
|
status: "success",
|
|
message: "Danke! Wir melden uns innerhalb von zwei Werktagen.",
|
|
}
|
|
}
|