Eventi visibili solo ai convocati; «Rosa e presenze» filtrata sui convocati
- «Rosa e presenze» (allenamento, partita, evento) elenca, conta e solleciti solo i convocati invece di tutta la rosa; il riquadro «La tua risposta» sparisce per i non convocati. - Calendario, Home e elenco eventi mostrano un evento con convocati solo a chi è convocato; admin e allenatori lo vedono sempre, `convocati` vuoto = tutti (eventoVisibile). - Filtro solo lato interfaccia: la RLS di eventi_app non cambia. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3bf07049e9
commit
5ca081a6af
11 files changed
+81
-11
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import { eventoVisibile, useEventi } from "./eventi";
|
||||
import { usePuoGestireEventi } from "./ruoli";
|
||||
import { useGiocatoreId } from "./user-store";
|
||||
|
||||
/** Gli eventi che l'utente corrente può vedere (calendario, home, elenco). */
|
||||
export function useEventiVisibili() {
|
||||
const { eventi, ...resto } = useEventi();
|
||||
const giocatoreId = useGiocatoreId();
|
||||
const vedeTutto = usePuoGestireEventi();
|
||||
return {
|
||||
...resto,
|
||||
eventi: eventi.filter((e) => eventoVisibile(e, giocatoreId, vedeTutto)),
|
||||
};
|
||||
}
|
||||
@@ -90,6 +90,19 @@ export function useEventi() {
|
||||
return { ...query, eventi: query.data ?? [] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Chi vede un evento: i convocati; se `convocati` è vuoto, tutta la rosa. Chi gestisce gli
|
||||
* eventi (admin e allenatori) li vede sempre, convocato o no.
|
||||
*/
|
||||
export function eventoVisibile(
|
||||
evento: Pick<Evento, "convocati">,
|
||||
giocatoreId: string | null,
|
||||
vedeTutto: boolean,
|
||||
): boolean {
|
||||
if (vedeTutto || evento.convocati.length === 0) return true;
|
||||
return giocatoreId !== null && evento.convocati.includes(giocatoreId);
|
||||
}
|
||||
|
||||
export function useEvento(id: string) {
|
||||
const { eventi, ...resto } = useEventi();
|
||||
return { ...resto, evento: eventi.find((e) => e.id === id) ?? null };
|
||||
|
||||
Reference in new issue
Block a user