diff --git a/src/routes/eventi.tsx b/src/routes/eventi.tsx index c3b9477..34b99ea 100644 --- a/src/routes/eventi.tsx +++ b/src/routes/eventi.tsx @@ -66,6 +66,7 @@ function GestioneEventi() { const elimina = useEliminaEvento(); const [bozza, setBozza] = useState(null); const [daEliminare, setDaEliminare] = useState(null); + const [confermaModifica, setConfermaModifica] = useState(false); const rosa = squadra.filter((g) => g.attivo); if (!io || !admin) { @@ -85,18 +86,31 @@ function GestioneEventi() { setBozza((b) => (b ? { ...b, ...patch } : b)); } - async function conferma() { + const modificaEsistente = bozza ? eventi.some((e) => e.id === bozza.id) : false; + + function chiediConferma() { if (!bozza) return; if (!bozza.titolo.trim()) { toast.error("Serve un titolo per l'evento"); return; } + if (modificaEsistente) { + setConfermaModifica(true); + return; + } + conferma(); + } + + async function conferma() { + if (!bozza) return; try { await salva.mutateAsync({ ...bozza, titolo: bozza.titolo.trim() }); toast.success("Evento salvato"); setBozza(null); } catch { toast.error("Non sono riuscito a salvare l'evento"); + } finally { + setConfermaModifica(false); } } @@ -272,7 +286,7 @@ function GestioneEventi() { + + + + + + + !aperto && setDaEliminare(null)}>