since3-website/modules/landingPage/schema/contact-schema.ts
2026-09-25 00:45:33 +02:00

35 lines
1.1 KiB
TypeScript

import { z } from "zod"
// Shared between the server action and the form so both validate identically.
export const contactSchema = z.object({
name: z
.string()
.trim()
.min(2, "Bitte gib deinen Namen an."),
email: z
.string()
.trim()
.pipe(z.email("Bitte gib eine gültige E-Mail-Adresse an.")),
company: z.string().trim().max(120, "Maximal 120 Zeichen.").optional(),
message: z
.string()
.trim()
.min(20, "Erzähl uns in mindestens 20 Zeichen, worum es geht.")
.max(4000, "Maximal 4000 Zeichen."),
privacy: z.literal("on", {
error: "Bitte stimme der Verarbeitung deiner Angaben zu.",
}),
})
export type ContactInput = z.infer<typeof contactSchema>
export type ContactField = keyof ContactInput
export type ContactFormState = {
status: "idle" | "success" | "error"
message?: string
fieldErrors?: Partial<Record<ContactField, string[]>>
// Echoed back so the form keeps its values after a failed submit
values?: Partial<Record<ContactField, string>>
}
export const initialContactState: ContactFormState = { status: "idle" }