2026-10-19 08:12:02 +02:00
|
|
|
import { useEventiVisibili } from "@/lib/eventi-visibili";
|
2026-09-14 08:57:24 +02:00
|
|
|
import { useEffect, useState } from "react";
|
2026-09-06 10:21:14 +02:00
|
|
|
import { createFileRoute } from "@tanstack/react-router";
|
2026-09-14 08:57:24 +02:00
|
|
|
import { CalendarPlus, ChevronLeft, ChevronRight, Loader2, Pencil, Trash2, X } from "lucide-react";
|
2026-08-06 08:36:47 +02:00
|
|
|
import { toast } from "sonner";
|
2026-09-24 14:10:11 +02:00
|
|
|
import { AnimatePresence, motion } from "motion/react";
|
2026-08-06 08:36:47 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
2026-09-14 08:57:24 +02:00
|
|
|
import { Campo, Card, classiInput, PageHeader, Section } from "@/components/crapp/ui-bits";
|
2026-09-07 09:11:11 +02:00
|
|
|
import {
|
|
|
|
|
Drawer,
|
|
|
|
|
DrawerClose,
|
|
|
|
|
DrawerContent,
|
|
|
|
|
DrawerDescription,
|
|
|
|
|
DrawerFooter,
|
|
|
|
|
DrawerHeader,
|
|
|
|
|
DrawerTitle,
|
|
|
|
|
} from "@/components/ui/drawer";
|
2026-09-03 10:17:03 +02:00
|
|
|
import { formatData } from "@/lib/crapp-data";
|
2026-09-14 08:57:24 +02:00
|
|
|
import { giorniDelMese, giorniIT, mesiIT, pad2, useMeseNav } from "@/lib/calendario";
|
2026-09-24 14:54:35 +02:00
|
|
|
import { inRosa, nomeCompleto, useGiocatoriSquadra } from "@/lib/giocatori-squadra";
|
2026-08-06 08:36:47 +02:00
|
|
|
import {
|
|
|
|
|
categoriaEvento,
|
|
|
|
|
daCategoria,
|
|
|
|
|
eventoVuoto,
|
|
|
|
|
useEliminaEvento,
|
|
|
|
|
useSalvaEvento,
|
|
|
|
|
type CategoriaEvento,
|
|
|
|
|
type Evento,
|
|
|
|
|
} from "@/lib/eventi";
|
2026-09-08 10:00:52 +02:00
|
|
|
import { useGiocatoreBase } from "@/lib/user-store";
|
2026-09-24 14:54:35 +02:00
|
|
|
import { usePuoGestireEventi } from "@/lib/ruoli";
|
2026-09-24 14:10:11 +02:00
|
|
|
import { molla, proietta } from "@/lib/molla";
|
|
|
|
|
import { useMotoRidotto } from "@/lib/motion";
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
export const Route = createFileRoute("/eventi")({
|
|
|
|
|
head: () => ({
|
|
|
|
|
meta: [
|
|
|
|
|
{ title: "Gestione eventi — CrAPP" },
|
|
|
|
|
{
|
|
|
|
|
name: "description",
|
|
|
|
|
content:
|
|
|
|
|
"Area riservata ai referenti CRAP Volley: crea, modifica ed elimina allenamenti, partite ed eventi di squadra.",
|
|
|
|
|
},
|
|
|
|
|
{ property: "og:title", content: "Gestione eventi — CrAPP" },
|
|
|
|
|
{
|
|
|
|
|
property: "og:description",
|
|
|
|
|
content: "Crea e modifica il calendario della squadra e scegli i convocati.",
|
|
|
|
|
},
|
|
|
|
|
{ property: "og:type", content: "website" },
|
|
|
|
|
{ name: "twitter:card", content: "summary" },
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
component: GestioneEventi,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const tipi: Array<{ id: CategoriaEvento; label: string }> = [
|
|
|
|
|
{ id: "allenamento", label: "Allenamento" },
|
|
|
|
|
{ id: "partita", label: "Partita" },
|
|
|
|
|
{ id: "amichevole", label: "Amichevole" },
|
|
|
|
|
{ id: "evento", label: "Evento" },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function GestioneEventi() {
|
2026-09-24 14:54:35 +02:00
|
|
|
// Solo verità (`!io`, gate admin o allenatore): `useGiocatoreBase` basta, niente statistiche.
|
2026-09-08 10:00:52 +02:00
|
|
|
const io = useGiocatoreBase();
|
2026-09-24 14:54:35 +02:00
|
|
|
// Admin o allenatore (DD-034): la RLS di `eventi_app` (M21) dice lo stesso.
|
|
|
|
|
const puoGestire = usePuoGestireEventi();
|
2026-10-19 08:12:02 +02:00
|
|
|
const { eventi, isPending, isError, error, refetch } = useEventiVisibili();
|
2026-09-03 10:17:03 +02:00
|
|
|
const { righe: squadra } = useGiocatoriSquadra();
|
2026-08-06 08:36:47 +02:00
|
|
|
const salva = useSalvaEvento();
|
|
|
|
|
const elimina = useEliminaEvento();
|
|
|
|
|
const [bozza, setBozza] = useState<Evento | null>(null);
|
2026-09-07 09:11:11 +02:00
|
|
|
const [daEliminare, setDaEliminare] = useState<Evento | null>(null);
|
2026-09-14 07:50:54 +02:00
|
|
|
const [confermaModifica, setConfermaModifica] = useState(false);
|
2026-09-24 14:10:11 +02:00
|
|
|
const [cambiaGiorno, setCambiaGiorno] = useState(false);
|
2026-09-24 14:54:35 +02:00
|
|
|
const rosa = squadra.filter(inRosa);
|
2026-08-06 08:36:47 +02:00
|
|
|
|
2026-09-14 08:57:24 +02:00
|
|
|
// SSR-safe: la data di oggi arriva solo dopo il mount.
|
|
|
|
|
const [oggi, setOggi] = useState<{ anno: number; mese: number; giorno: number } | null>(null);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const d = new Date();
|
|
|
|
|
setOggi({ anno: d.getFullYear(), mese: d.getMonth(), giorno: d.getDate() });
|
|
|
|
|
}, []);
|
|
|
|
|
const [giornoSelezionato, setGiornoSelezionato] = useState<string | null>(null);
|
2026-09-24 14:10:11 +02:00
|
|
|
const ridotto = useMotoRidotto();
|
|
|
|
|
const { anno, mese, direzione, precedente, successivo } = useMeseNav();
|
2026-09-14 08:57:24 +02:00
|
|
|
const { giorni, offsetLunedi } = giorniDelMese(anno, mese);
|
|
|
|
|
|
2026-09-24 14:54:35 +02:00
|
|
|
if (!io || !puoGestire) {
|
2026-08-06 08:36:47 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<PageHeader titolo="Gestione eventi" sottotitolo="Area riservata" />
|
|
|
|
|
<div className="px-5">
|
2026-10-06 11:50:28 +02:00
|
|
|
<p className="rounded-3xl bg-card p-5 text-center text-[15px] text-muted-foreground shadow-card">
|
2026-08-06 08:36:47 +02:00
|
|
|
Solo i referenti della squadra possono creare o modificare gli eventi.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function aggiorna(patch: Partial<Evento>) {
|
|
|
|
|
setBozza((b) => (b ? { ...b, ...patch } : b));
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 07:50:54 +02:00
|
|
|
const modificaEsistente = bozza ? eventi.some((e) => e.id === bozza.id) : false;
|
|
|
|
|
|
|
|
|
|
function chiediConferma() {
|
2026-08-06 08:36:47 +02:00
|
|
|
if (!bozza) return;
|
|
|
|
|
if (!bozza.titolo.trim()) {
|
|
|
|
|
toast.error("Serve un titolo per l'evento");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-09-14 07:50:54 +02:00
|
|
|
if (modificaEsistente) {
|
|
|
|
|
setConfermaModifica(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
conferma();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function conferma() {
|
|
|
|
|
if (!bozza) return;
|
2026-08-06 08:36:47 +02:00
|
|
|
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");
|
2026-09-14 07:50:54 +02:00
|
|
|
} finally {
|
|
|
|
|
setConfermaModifica(false);
|
2026-08-06 08:36:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function rimuovi(id: string) {
|
|
|
|
|
try {
|
|
|
|
|
await elimina.mutateAsync(id);
|
|
|
|
|
toast.success("Evento eliminato");
|
|
|
|
|
if (bozza?.id === id) setBozza(null);
|
|
|
|
|
} catch {
|
|
|
|
|
toast.error("Non sono riuscito a eliminare l'evento");
|
2026-09-07 09:11:11 +02:00
|
|
|
} finally {
|
|
|
|
|
setDaEliminare(null);
|
2026-08-06 08:36:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 08:57:24 +02:00
|
|
|
const mesePrefix = `${anno}-${pad2(mese + 1)}`;
|
|
|
|
|
const eventiPerGiorno = new Map<number, Evento[]>();
|
|
|
|
|
for (const e of eventi) {
|
|
|
|
|
if (!e.data.startsWith(mesePrefix)) continue;
|
|
|
|
|
const g = Number(e.data.slice(8, 10));
|
|
|
|
|
const lista = eventiPerGiorno.get(g) ?? [];
|
|
|
|
|
lista.push(e);
|
|
|
|
|
eventiPerGiorno.set(g, lista);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function apriGiorno(giorno: number) {
|
|
|
|
|
setGiornoSelezionato(`${mesePrefix}-${pad2(giorno)}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function nuovoNelGiorno() {
|
|
|
|
|
if (!giornoSelezionato) return;
|
|
|
|
|
setBozza({ ...eventoVuoto(), data: giornoSelezionato });
|
2026-09-24 14:10:11 +02:00
|
|
|
setCambiaGiorno(false);
|
2026-09-14 08:57:24 +02:00
|
|
|
setGiornoSelezionato(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function modificaDalGiorno(e: Evento) {
|
|
|
|
|
setBozza(e);
|
2026-09-24 14:10:11 +02:00
|
|
|
setCambiaGiorno(false);
|
2026-09-14 08:57:24 +02:00
|
|
|
setGiornoSelezionato(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function eliminaDalGiorno(e: Evento) {
|
|
|
|
|
setDaEliminare(e);
|
|
|
|
|
setGiornoSelezionato(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const eventiGiornoSelezionato = giornoSelezionato
|
|
|
|
|
? eventi.filter((e) => e.data === giornoSelezionato)
|
|
|
|
|
: [];
|
|
|
|
|
|
2026-08-06 08:36:47 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<PageHeader titolo="Gestione eventi" sottotitolo={`${eventi.length} eventi in calendario`} />
|
|
|
|
|
|
2026-09-14 08:57:24 +02:00
|
|
|
<Section titolo="Calendario">
|
|
|
|
|
<Card>
|
|
|
|
|
<div className="mb-3 flex items-center justify-between">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={precedente}
|
|
|
|
|
className="grid h-11 w-11 place-items-center rounded-full bg-secondary text-foreground active:scale-95"
|
|
|
|
|
aria-label="Mese precedente"
|
|
|
|
|
>
|
|
|
|
|
<ChevronLeft className="h-5 w-5" />
|
|
|
|
|
</button>
|
|
|
|
|
<span className="font-display-sm text-xl uppercase">
|
|
|
|
|
{mesiIT[mese]} {anno}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={successivo}
|
|
|
|
|
className="grid h-11 w-11 place-items-center rounded-full bg-secondary text-foreground active:scale-95"
|
|
|
|
|
aria-label="Mese successivo"
|
|
|
|
|
>
|
|
|
|
|
<ChevronRight className="h-5 w-5" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-10-06 11:50:28 +02:00
|
|
|
<div className="grid grid-cols-7 gap-1 text-center text-[13px] font-bold text-muted-foreground">
|
2026-09-14 08:57:24 +02:00
|
|
|
{giorniIT.map((g, i) => (
|
|
|
|
|
<span key={i}>{g}</span>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-09-24 14:10:11 +02:00
|
|
|
{/* Swipe tra mesi con la stessa fisica di `/calendario` (vedi il commento lì). */}
|
|
|
|
|
<div className="relative -mx-1 mt-1 overflow-hidden p-1">
|
|
|
|
|
<AnimatePresence initial={false} mode="popLayout" custom={direzione}>
|
|
|
|
|
<motion.div
|
|
|
|
|
key={mesePrefix}
|
|
|
|
|
custom={direzione}
|
|
|
|
|
drag={ridotto ? false : "x"}
|
|
|
|
|
dragConstraints={{ left: 0, right: 0 }}
|
|
|
|
|
dragElastic={0.18}
|
|
|
|
|
dragMomentum={false}
|
|
|
|
|
onDragEnd={(_, info) => {
|
|
|
|
|
const arrivo = info.offset.x + proietta(info.velocity.x);
|
|
|
|
|
if (arrivo < -60) successivo();
|
|
|
|
|
else if (arrivo > 60) precedente();
|
|
|
|
|
}}
|
|
|
|
|
initial={ridotto ? { opacity: 0 } : { opacity: 0, x: direzione * 48 }}
|
|
|
|
|
animate={{ opacity: 1, x: 0 }}
|
|
|
|
|
exit={ridotto ? { opacity: 0 } : { opacity: 0, x: direzione * -48 }}
|
|
|
|
|
transition={ridotto ? { duration: 0.2 } : molla.foglio}
|
|
|
|
|
className="grid touch-pan-y grid-cols-7 gap-1"
|
|
|
|
|
>
|
|
|
|
|
{Array.from({ length: offsetLunedi }).map((_, i) => (
|
|
|
|
|
<span key={`v${i}`} />
|
|
|
|
|
))}
|
|
|
|
|
{Array.from({ length: giorni }).map((_, i) => {
|
|
|
|
|
const giorno = i + 1;
|
|
|
|
|
const eventiGiorno = eventiPerGiorno.get(giorno) ?? [];
|
|
|
|
|
const haEventi = eventiGiorno.length > 0;
|
|
|
|
|
const isOggi =
|
|
|
|
|
!!oggi && oggi.anno === anno && oggi.mese === mese && oggi.giorno === giorno;
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
key={giorno}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => apriGiorno(giorno)}
|
|
|
|
|
className={cn(
|
2026-10-06 11:50:28 +02:00
|
|
|
"relative grid aspect-square place-items-center rounded-xl text-[15px] font-semibold transition-transform active:scale-90",
|
2026-09-24 14:10:11 +02:00
|
|
|
haEventi
|
|
|
|
|
? "bg-accent text-accent-foreground"
|
|
|
|
|
: "bg-secondary text-foreground",
|
|
|
|
|
isOggi && "ring-2 ring-foreground ring-offset-1 ring-offset-card",
|
|
|
|
|
)}
|
|
|
|
|
aria-label={`${giorno} ${mesiIT[mese]}${haEventi ? `: ${eventiGiorno.length} ${eventiGiorno.length === 1 ? "evento" : "eventi"}` : ", nessun evento"}`}
|
|
|
|
|
aria-current={isOggi ? "date" : undefined}
|
|
|
|
|
>
|
|
|
|
|
{giorno}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</motion.div>
|
|
|
|
|
</AnimatePresence>
|
2026-09-14 08:57:24 +02:00
|
|
|
</div>
|
2026-09-24 14:10:11 +02:00
|
|
|
{isPending ? (
|
2026-10-06 11:50:28 +02:00
|
|
|
<p aria-busy="true" className="mt-2 text-[13px] text-muted-foreground">
|
2026-09-24 14:10:11 +02:00
|
|
|
Carico gli eventi…
|
|
|
|
|
</p>
|
|
|
|
|
) : isError ? (
|
2026-10-06 11:50:28 +02:00
|
|
|
<div className="mt-3 space-y-2 text-center text-[15px]">
|
2026-09-24 14:10:11 +02:00
|
|
|
<p className="text-destructive">
|
|
|
|
|
Non sono riuscito a caricare gli eventi
|
|
|
|
|
{error instanceof Error ? `: ${error.message}` : ""}.
|
|
|
|
|
</p>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => refetch()}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="rounded-2xl bg-secondary px-4 py-2 text-[13px] font-bold uppercase"
|
2026-09-24 14:10:11 +02:00
|
|
|
>
|
|
|
|
|
Riprova
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
2026-10-06 11:50:28 +02:00
|
|
|
<p className="mt-2 text-[13px] text-muted-foreground">
|
2026-09-24 14:10:11 +02:00
|
|
|
Scorri a destra o sinistra per cambiare mese. Tocca un giorno per aggiungere,
|
|
|
|
|
modificare o eliminare.
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2026-09-14 08:57:24 +02:00
|
|
|
</Card>
|
|
|
|
|
</Section>
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
{bozza ? (
|
2026-09-01 13:38:33 +02:00
|
|
|
<Section
|
|
|
|
|
titolo={eventi.some((e) => e.id === bozza.id) ? "Modifica evento" : "Nuovo evento"}
|
|
|
|
|
>
|
2026-08-06 08:36:47 +02:00
|
|
|
<div className="space-y-3 rounded-3xl bg-card p-4 shadow-card">
|
|
|
|
|
<div className="grid grid-cols-4 gap-1 rounded-full bg-secondary p-1">
|
|
|
|
|
{tipi.map((t) => (
|
|
|
|
|
<button
|
|
|
|
|
key={t.id}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => aggiorna(daCategoria(t.id))}
|
|
|
|
|
className={cn(
|
2026-10-06 11:50:28 +02:00
|
|
|
"rounded-full py-2 text-[13px] font-bold uppercase transition-colors",
|
2026-08-06 08:36:47 +02:00
|
|
|
categoriaEvento(bozza) === t.id
|
|
|
|
|
? "bg-card shadow-card text-foreground"
|
|
|
|
|
: "text-muted-foreground",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{t.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Campo label="Titolo">
|
|
|
|
|
<input
|
|
|
|
|
value={bozza.titolo}
|
|
|
|
|
maxLength={80}
|
|
|
|
|
onChange={(e) => aggiorna({ titolo: e.target.value })}
|
2026-09-05 23:41:20 +02:00
|
|
|
className={classiInput}
|
2026-08-06 08:36:47 +02:00
|
|
|
/>
|
|
|
|
|
</Campo>
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
2026-09-24 14:10:11 +02:00
|
|
|
{/* Il giorno arriva già dal calendario: si mostra e basta, il campo data
|
|
|
|
|
compare solo per spostare l'evento. */}
|
|
|
|
|
{cambiaGiorno ? (
|
|
|
|
|
<Campo label="Giorno">
|
|
|
|
|
<input
|
|
|
|
|
type="date"
|
|
|
|
|
value={bozza.data}
|
|
|
|
|
onChange={(e) => aggiorna({ data: e.target.value })}
|
|
|
|
|
className={classiInput}
|
|
|
|
|
/>
|
|
|
|
|
</Campo>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="min-w-0">
|
2026-10-06 11:50:28 +02:00
|
|
|
<span className="text-[13px] font-bold uppercase tracking-wide text-muted-foreground">
|
2026-09-24 14:10:11 +02:00
|
|
|
Giorno
|
|
|
|
|
</span>
|
|
|
|
|
<div className="mt-1 flex h-10 items-center justify-between gap-1">
|
2026-10-06 11:50:28 +02:00
|
|
|
<span className="truncate text-[15px] font-semibold">
|
|
|
|
|
{formatData(bozza.data)}
|
|
|
|
|
</span>
|
2026-09-24 14:10:11 +02:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setCambiaGiorno(true)}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="shrink-0 rounded-full px-2 py-1 text-[13px] font-bold uppercase text-accent active:scale-95"
|
2026-09-24 14:10:11 +02:00
|
|
|
>
|
|
|
|
|
Cambia
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-08-06 08:36:47 +02:00
|
|
|
<Campo label="Ora">
|
|
|
|
|
<input
|
|
|
|
|
type="time"
|
|
|
|
|
value={bozza.ora}
|
|
|
|
|
onChange={(e) => aggiorna({ ora: e.target.value })}
|
2026-09-05 23:41:20 +02:00
|
|
|
className={classiInput}
|
2026-08-06 08:36:47 +02:00
|
|
|
/>
|
|
|
|
|
</Campo>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Campo label="Luogo">
|
|
|
|
|
<input
|
|
|
|
|
value={bozza.luogo}
|
|
|
|
|
maxLength={80}
|
|
|
|
|
onChange={(e) => aggiorna({ luogo: e.target.value })}
|
2026-09-05 23:41:20 +02:00
|
|
|
className={classiInput}
|
2026-08-06 08:36:47 +02:00
|
|
|
/>
|
|
|
|
|
</Campo>
|
|
|
|
|
|
|
|
|
|
<Campo label="Note">
|
|
|
|
|
<textarea
|
|
|
|
|
value={bozza.note}
|
|
|
|
|
maxLength={300}
|
|
|
|
|
rows={2}
|
|
|
|
|
onChange={(e) => aggiorna({ note: e.target.value })}
|
2026-09-06 11:07:15 +02:00
|
|
|
className={cn(classiInput, "h-auto")}
|
2026-08-06 08:36:47 +02:00
|
|
|
/>
|
|
|
|
|
</Campo>
|
|
|
|
|
|
|
|
|
|
{bozza.tipo === "partita" ? (
|
|
|
|
|
<>
|
|
|
|
|
<Campo label="Dove si gioca">
|
|
|
|
|
<div className="flex rounded-full bg-secondary p-1">
|
|
|
|
|
{[
|
|
|
|
|
{ casa: true, label: "In casa" },
|
|
|
|
|
{ casa: false, label: "Fuori casa" },
|
|
|
|
|
].map((o) => (
|
|
|
|
|
<button
|
|
|
|
|
key={o.label}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => aggiorna({ casa: o.casa })}
|
|
|
|
|
className={cn(
|
2026-10-06 11:50:28 +02:00
|
|
|
"flex-1 rounded-full py-2 text-[13px] font-bold uppercase transition-colors",
|
2026-08-06 08:36:47 +02:00
|
|
|
bozza.casa === o.casa
|
|
|
|
|
? "bg-card shadow-card text-foreground"
|
|
|
|
|
: "text-muted-foreground",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{o.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</Campo>
|
|
|
|
|
<div className="flex flex-wrap gap-2">
|
|
|
|
|
<Interruttore
|
|
|
|
|
attivo={bozza.pagelleChiuse}
|
|
|
|
|
onClick={() => aggiorna({ pagelleChiuse: !bozza.pagelleChiuse })}
|
|
|
|
|
label="Pagelle chiuse"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
<Campo
|
|
|
|
|
label={`Convocati (${bozza.convocati.length === 0 ? "tutta la rosa" : bozza.convocati.length})`}
|
|
|
|
|
>
|
|
|
|
|
<div className="grid grid-cols-2 gap-1.5">
|
2026-09-03 10:17:03 +02:00
|
|
|
{rosa.map((g) => {
|
2026-08-06 08:36:47 +02:00
|
|
|
const scelto = bozza.convocati.includes(g.id);
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
key={g.id}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
aggiorna({
|
|
|
|
|
convocati: scelto
|
|
|
|
|
? bozza.convocati.filter((x) => x !== g.id)
|
|
|
|
|
: [...bozza.convocati, g.id],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
className={cn(
|
2026-10-06 11:50:28 +02:00
|
|
|
"truncate rounded-xl px-2.5 py-2 text-left text-[13px] font-semibold transition-colors",
|
2026-09-01 13:38:33 +02:00
|
|
|
scelto
|
|
|
|
|
? "bg-accent text-accent-foreground"
|
|
|
|
|
: "bg-secondary text-muted-foreground",
|
2026-08-06 08:36:47 +02:00
|
|
|
)}
|
|
|
|
|
>
|
2026-09-03 10:17:03 +02:00
|
|
|
{nomeCompleto(g)}
|
2026-08-06 08:36:47 +02:00
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</Campo>
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2 pt-1">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setBozza(null)}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="flex-1 rounded-2xl bg-secondary py-3 text-[15px] font-bold uppercase"
|
2026-08-06 08:36:47 +02:00
|
|
|
>
|
|
|
|
|
Annulla
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-09-14 07:50:54 +02:00
|
|
|
onClick={chiediConferma}
|
2026-08-06 08:36:47 +02:00
|
|
|
disabled={salva.isPending}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="flex flex-1 items-center justify-center gap-2 rounded-2xl bg-accent-grad py-3 text-[15px] font-bold uppercase text-accent-foreground shadow-pop disabled:opacity-50"
|
2026-08-06 08:36:47 +02:00
|
|
|
>
|
|
|
|
|
{salva.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null} Salva
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Section>
|
|
|
|
|
) : null}
|
|
|
|
|
|
2026-09-14 08:57:24 +02:00
|
|
|
<Drawer
|
|
|
|
|
open={!!giornoSelezionato}
|
|
|
|
|
onOpenChange={(aperto) => !aperto && setGiornoSelezionato(null)}
|
|
|
|
|
>
|
|
|
|
|
<DrawerContent className="rounded-t-[24px] border-border bg-background px-4 pb-6 pt-2">
|
|
|
|
|
<DrawerHeader className="relative px-0 pb-2 text-left">
|
|
|
|
|
<DrawerTitle className="font-display-lg text-2xl uppercase">
|
|
|
|
|
{giornoSelezionato ? formatData(giornoSelezionato) : "Giorno"}
|
|
|
|
|
</DrawerTitle>
|
|
|
|
|
<DrawerClose className="absolute right-0 top-0 grid h-11 w-11 place-items-center rounded-full bg-secondary text-foreground transition-transform active:scale-90">
|
|
|
|
|
<X className="h-4 w-4" />
|
|
|
|
|
<span className="sr-only">Chiudi</span>
|
|
|
|
|
</DrawerClose>
|
|
|
|
|
</DrawerHeader>
|
|
|
|
|
<div className="max-h-[50vh] space-y-2 overflow-y-auto py-2">
|
|
|
|
|
{eventiGiornoSelezionato.length > 0 ? (
|
|
|
|
|
eventiGiornoSelezionato.map((e) => (
|
|
|
|
|
<div
|
|
|
|
|
key={e.id}
|
|
|
|
|
className="flex items-center gap-2 rounded-2xl bg-card p-3 shadow-card"
|
|
|
|
|
>
|
|
|
|
|
<div className="min-w-0 flex-1">
|
2026-10-06 11:50:28 +02:00
|
|
|
<p className="truncate text-[15px] font-bold leading-tight">{e.titolo}</p>
|
|
|
|
|
<p className="text-[13px] text-muted-foreground">
|
2026-09-14 08:57:24 +02:00
|
|
|
{e.ora} · {e.luogo || "luogo da definire"}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => modificaDalGiorno(e)}
|
|
|
|
|
className="grid h-10 w-10 shrink-0 place-items-center rounded-xl bg-secondary text-foreground active:scale-95"
|
|
|
|
|
aria-label={`Modifica ${e.titolo}`}
|
|
|
|
|
>
|
|
|
|
|
<Pencil className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => eliminaDalGiorno(e)}
|
|
|
|
|
className="grid h-10 w-10 shrink-0 place-items-center rounded-xl bg-destructive/10 text-destructive active:scale-95"
|
|
|
|
|
aria-label={`Elimina ${e.titolo}`}
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
2026-10-06 11:50:28 +02:00
|
|
|
<p className="rounded-2xl bg-card p-4 text-center text-[15px] text-muted-foreground shadow-card">
|
2026-09-14 08:57:24 +02:00
|
|
|
Nessun evento in programma
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={nuovoNelGiorno}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="premi mt-1 flex w-full items-center justify-center gap-2 rounded-2xl bg-accent-grad py-3 text-[15px] font-bold uppercase text-accent-foreground shadow-pop"
|
2026-09-14 08:57:24 +02:00
|
|
|
>
|
|
|
|
|
<CalendarPlus className="h-4 w-4" /> Nuovo evento in questo giorno
|
|
|
|
|
</button>
|
|
|
|
|
</DrawerContent>
|
|
|
|
|
</Drawer>
|
|
|
|
|
|
2026-09-14 07:50:54 +02:00
|
|
|
<Drawer
|
|
|
|
|
open={confermaModifica}
|
|
|
|
|
onOpenChange={(aperto) => !aperto && setConfermaModifica(false)}
|
|
|
|
|
>
|
|
|
|
|
<DrawerContent>
|
|
|
|
|
<DrawerHeader>
|
|
|
|
|
<DrawerTitle>Salvare le modifiche?</DrawerTitle>
|
|
|
|
|
<DrawerDescription>
|
|
|
|
|
{bozza ? `Aggiorni l'evento "${bozza.titolo.trim() || "senza titolo"}".` : ""}
|
|
|
|
|
</DrawerDescription>
|
|
|
|
|
</DrawerHeader>
|
|
|
|
|
<DrawerFooter>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={conferma}
|
|
|
|
|
disabled={salva.isPending}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="flex w-full items-center justify-center gap-2 rounded-2xl bg-accent-grad py-3 text-[15px] font-bold uppercase text-accent-foreground shadow-pop disabled:opacity-50"
|
2026-09-14 07:50:54 +02:00
|
|
|
>
|
|
|
|
|
{salva.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null} Conferma
|
|
|
|
|
</button>
|
|
|
|
|
<DrawerClose asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-10-06 11:50:28 +02:00
|
|
|
className="w-full rounded-2xl bg-secondary py-3 text-[15px] font-bold uppercase text-foreground"
|
2026-09-14 07:50:54 +02:00
|
|
|
>
|
|
|
|
|
Annulla
|
|
|
|
|
</button>
|
|
|
|
|
</DrawerClose>
|
|
|
|
|
</DrawerFooter>
|
|
|
|
|
</DrawerContent>
|
|
|
|
|
</Drawer>
|
|
|
|
|
|
2026-09-07 09:11:11 +02:00
|
|
|
<Drawer open={!!daEliminare} onOpenChange={(aperto) => !aperto && setDaEliminare(null)}>
|
|
|
|
|
<DrawerContent>
|
|
|
|
|
<DrawerHeader>
|
|
|
|
|
<DrawerTitle>Eliminare questo evento?</DrawerTitle>
|
|
|
|
|
<DrawerDescription>
|
|
|
|
|
{daEliminare ? `"${daEliminare.titolo}" — l'operazione non si può annullare.` : ""}
|
|
|
|
|
</DrawerDescription>
|
|
|
|
|
</DrawerHeader>
|
|
|
|
|
<DrawerFooter>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => daEliminare && rimuovi(daEliminare.id)}
|
|
|
|
|
disabled={elimina.isPending}
|
2026-10-06 11:50:28 +02:00
|
|
|
className="flex w-full items-center justify-center gap-2 rounded-2xl bg-destructive py-3 text-[15px] font-bold uppercase text-destructive-foreground disabled:opacity-50"
|
2026-09-07 09:11:11 +02:00
|
|
|
>
|
|
|
|
|
{elimina.isPending ? <Loader2 className="h-4 w-4 animate-spin" /> : null} Elimina
|
|
|
|
|
</button>
|
|
|
|
|
<DrawerClose asChild>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-10-06 11:50:28 +02:00
|
|
|
className="w-full rounded-2xl bg-secondary py-3 text-[15px] font-bold uppercase text-foreground"
|
2026-09-07 09:11:11 +02:00
|
|
|
>
|
|
|
|
|
Annulla
|
|
|
|
|
</button>
|
|
|
|
|
</DrawerClose>
|
|
|
|
|
</DrawerFooter>
|
|
|
|
|
</DrawerContent>
|
|
|
|
|
</Drawer>
|
2026-08-06 08:36:47 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Interruttore({
|
|
|
|
|
attivo,
|
|
|
|
|
onClick,
|
|
|
|
|
label,
|
|
|
|
|
}: {
|
|
|
|
|
attivo: boolean;
|
|
|
|
|
onClick: () => void;
|
|
|
|
|
label: string;
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
className={cn(
|
2026-10-06 11:50:28 +02:00
|
|
|
"rounded-full px-3 py-1.5 text-[13px] font-bold uppercase transition-colors",
|
2026-08-06 08:36:47 +02:00
|
|
|
attivo ? "bg-accent text-accent-foreground" : "bg-secondary text-muted-foreground",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{label}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|