import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; const schema = z.object({ name: z.string().min(1, "Name ist erforderlich"), legalForm: z.string().optional(), taxId: z.string().optional(), vatId: z.string().optional(), address: z.string().min(1, "Adresse ist erforderlich"), zip: z.string().min(1, "PLZ ist erforderlich"), city: z.string().min(1, "Ort ist erforderlich"), country: z.string().optional(), email: z.string().email("Ungültige E-Mail").optional().or(z.literal("")), phone: z.string().optional(), website: z.string().optional(), bankIban: z.string().optional(), bankBic: z.string().optional(), bankName: z.string().optional(), invoicePrefix: z.string().optional(), }); type FormData = z.infer; interface CompanyFormProps { defaultValues?: Partial; onSubmit: (data: FormData) => Promise; submitLabel?: string; } function Field({ label, error, children }: { label: string; error?: string; children: React.ReactNode }) { return (
{children} {error &&

{error}

}
); } export function CompanyForm({ defaultValues, onSubmit, submitLabel = "Speichern" }: CompanyFormProps) { const { register, handleSubmit, formState: { errors, isSubmitting } } = useForm({ resolver: zodResolver(schema), defaultValues: { country: "DE", invoicePrefix: "RE", ...defaultValues }, }); return (

Stammdaten

Anschrift

Kontakt

Bankverbindung

Rechnungseinstellungen

Format: {"{Präfix}"}-{"{Jahr}"}-{"{Nummer}"} z.B. RE-2024-001

); }