'use client'; import { useCallback, useState } from 'react'; import { useAction } from 'next-safe-action/hooks'; import { useRouter } from 'next/navigation'; import { toast } from '@kit/ui/sonner'; import { Button } from '@kit/ui/button'; import { Input } from '@kit/ui/input'; import { Label } from '@kit/ui/label'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@kit/ui/dialog'; import { Plus } from 'lucide-react'; import { createDepartment } from '@kit/member-management/actions/member-actions'; interface CreateDepartmentDialogProps { accountId: string; } export function CreateDepartmentDialog({ accountId }: CreateDepartmentDialogProps) { const router = useRouter(); const [open, setOpen] = useState(false); const [name, setName] = useState(''); const [description, setDescription] = useState(''); const { execute, isPending } = useAction(createDepartment, { onSuccess: ({ data }) => { if (data?.success) { toast.success('Abteilung erstellt'); setOpen(false); setName(''); setDescription(''); router.refresh(); } }, onError: ({ error }) => { toast.error(error.serverError ?? 'Fehler beim Erstellen der Abteilung'); }, }); const handleSubmit = useCallback( (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) return; execute({ accountId, name: name.trim(), description: description.trim() || undefined }); }, [execute, accountId, name, description], ); return ( }> Neue Abteilung
Neue Abteilung Erstellen Sie eine neue Abteilung oder Sparte für Ihren Verein.
setName(e.target.value)} placeholder="z. B. Jugendabteilung" required minLength={1} maxLength={128} />
setDescription(e.target.value)} placeholder="Kurze Beschreibung" />
); }