"use client"; import { useState } from "react"; import { Loader2, Plus } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { createAssociation } from "@/lib/api"; import type { Association } from "@/lib/models"; export function CreateAssociationDialog({ onCreated, }: { onCreated: (association: Association) => void; }) { const [open, setOpen] = useState(false); const [creating, setCreating] = useState(false); const [name, setName] = useState(""); const [address, setAddress] = useState(""); const [vatNumber, setVatNumber] = useState(""); const [runtsId, setRuntsId] = useState(""); const reset = () => { setName(""); setAddress(""); setVatNumber(""); setRuntsId(""); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setCreating(true); try { const association = await createAssociation({ name, address, vatNumber, runtsId, isShown: true, associates: [], users: [], }); reset(); setOpen(false); onCreated(association); } catch (error) { console.error("Failed to create association:", error); alert("Impossibile creare l'associazione"); } finally { setCreating(false); } }; return ( Crea nuova associazione
setName(e.target.value)} placeholder="Associazione Sportiva Roma" required />
setAddress(e.target.value)} placeholder="Via Roma 10, Milano, 20100" required />
setVatNumber(e.target.value)} placeholder="12345678901" />
setRuntsId(e.target.value)} placeholder="RUNTS001" />
); }