'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@kit/ui/alert-dialog'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from '@kit/ui/form'; import { Input } from '@kit/ui/input'; import { Textarea } from '@kit/ui/textarea'; import { useActionWithToast } from '@kit/ui/use-action-with-toast'; import { CreateMemberSchema } from '../schema/member.schema'; import { createMember } from '../server/actions/member-actions'; interface Props { accountId: string; account: string; // slug for redirect duesCategories: Array<{ id: string; name: string; amount: number }>; } interface DuplicateEntry { field: string; message: string; id?: string; } export function CreateMemberForm({ accountId, account, duesCategories, }: Props) { const router = useRouter(); const [duplicates, setDuplicates] = useState([]); const form = useForm({ resolver: zodResolver(CreateMemberSchema), defaultValues: { accountId, firstName: '', lastName: '', email: '', phone: '', mobile: '', street: '', houseNumber: '', postalCode: '', city: '', country: 'DE', memberNumber: '', status: 'active' as const, entryDate: new Date().toISOString().split('T')[0]!, iban: '', bic: '', accountHolder: '', gdprConsent: false, notes: '', }, }); const { execute, isPending } = useActionWithToast(createMember, { successMessage: 'Mitglied erfolgreich erstellt', errorMessage: 'Fehler beim Erstellen', onSuccess: () => { router.push(`/home/${account}/members-cms`); }, onError: (_error, data) => { if (data?.validationErrors) { setDuplicates(data.validationErrors as DuplicateEntry[]); } }, }); return (
execute(data))} className="space-y-6" > Persönliche Daten ( Vorname * )} /> ( Nachname * )} /> ( Geburtsdatum )} /> ( Geschlecht )} /> Kontakt ( E-Mail )} /> ( Telefon )} /> ( Mobil )} /> Adresse ( Straße )} /> ( Hausnummer )} /> ( PLZ )} /> ( Ort )} /> Mitgliedschaft ( Mitgliedsnr. )} /> ( Status )} /> ( Eintrittsdatum )} /> {duesCategories.length > 0 && ( ( Beitragskategorie )} /> )} SEPA-Bankdaten ( IBAN field.onChange( e.target.value .toUpperCase() .replace(/[^A-Z0-9]/g, ''), ) } /> )} /> ( BIC )} /> ( Kontoinhaber )} /> {/* Guardian (Gap 4) */} Erziehungsberechtigte (Jugend) ( Name Erziehungsberechtigte/r )} /> ( Telefon )} /> ( E-Mail )} /> {/* Lifecycle flags (Gap 4) */} Mitgliedschaftsmerkmale {( [ ['isHonorary', 'Ehrenmitglied'], ['isFoundingMember', 'Gründungsmitglied'], ['isYouth', 'Jugendmitglied'], ['isRetiree', 'Rentner/Senior'], ['isProbationary', 'Probejahr'], ] as const ).map(([name, label]) => ( ( {label} )} /> ))} {/* GDPR granular (Gap 4) */} Datenschutz-Einwilligungen {( [ ['gdprConsent', 'Allgemeine Einwilligung'], ['gdprNewsletter', 'Newsletter'], ['gdprInternet', 'Internet/Homepage'], ['gdprPrint', 'Vereinszeitung'], ['gdprBirthdayInfo', 'Geburtstagsinfo'], ] as const ).map(([name, label]) => ( ( {label} )} /> ))} Sonstiges
( Anrede )} /> ( Geburtsort )} /> ( Adresszusatz )} />
( Notizen