PageSourceSearch

https://tournois-padel-ac-roissy.lovable.app/assets/RefereeDashboard-Dq_p9lOY.js

js tournois-padel-ac-roissy.lovable.app collected 2026-10-03 03:50:46 UTC 17,480 bytes, 1 lines download raw bytes

1import{a as Le,r,s as m,j as e,Y as Ve,B as l,L as b,g as H,t as _,v as S,O as k,w as A,y as u,X as ze,D as Y,h as X,_ as Z,i as K,a0 as Q,a1 as W,q as p}from"./index-DnLpPdJu.js";import{C as Ie,S as ve,f as Ue,A as Be}from"./tournaments-BXkCUYTe.js";import{C as Je}from"./credit-card-B_bvnvi0.js";import{C as Ge}from"./calendar-days-DAiQ26Ba.js";import{P as He}from"./plus-eYXrVnZo.js";import{C as Ye}from"./circle-alert-D-FXZe5Z.js";import{L as T}from"./loader-circle-p4PmW0Hd.js";import{S as Xe}from"./send-DeHfzYDf.js";import{S as Ze}from"./settings-Ba4C4tEC.js";import{U as Ke}from"./user-cog-Bdgszr3Q.js";import{E as Ne}from"./eye-off-DVQtZJZ0.js";import{B as we}from"./ban-DqBzqAKG.js";const Qe=()=>new Date().toLocaleDateString("en-CA"),us=()=>{var ge;const{user:c,loading:Ce,isReferee:$,isAdmin:D,isStaff:ee}=Le(),[o,ye]=r.useState([]),[M,_e]=r.useState({}),[v,se]=r.useState("all"),[N,te]=r.useState("all"),[w,ne]=r.useState("all"),[C,re]=r.useState("all"),[F,Se]=r.useState(""),[E,ke]=r.useState(""),[x,ae]=r.useState(!1),[f,le]=r.useState(null),[h,ie]=r.useState("upcoming"),[i,P]=r.useState(null),[g,O]=r.useState(null),[R,oe]=r.useState(!1),[j,q]=r.useState(null),[U,Ae]=r.useState([]),[L,ce]=r.useState(""),[B,de]=r.useState(!1),y=()=>{m.from("tournaments").select("*, registrations(status, payment_status)").gte("tournament_date",Be).order("tournament_date",{ascending:!0}).then(({data:s})=>ye(s??[])),m.rpc("get_all_tournament_counts").then(({data:s})=>{const t={};(s??[]).forEach(n=>{t[n.tournament_id]={confirmed:Number(n.confirmed??0),pending:Number(n.pending??0),waitlist:Number(n.waitlist??0)}}),_e(t)})};r.useEffect(()=>{if(!c)return;y();
1const s=m.channel(`ja-dashboard:${c.id}:${Math.random().toString(36).slice(2)}`).on("postgres_changes",{event:"*",schema:"public",table:"registrations"},()=>y()).subscribe();return()=>{m.removeChannel(s)}},[c,D]);const Te=async s=>{q(s),ce("");const{data:t,error:n}=await m.rpc("list_referees");if(n)return p.error("Impossible de charger la liste des juges-arbitres.");Ae(t??[])},$e=async()=>{if(!j||!L)return;const s=U.find(n=>n.id===L);if(!s)return;de(!0);const{error:t}=await m.from("tournaments").update({referee_id:s.id,referee_name:`${s.first_name??""} ${s.last_name??""}`.trim()||null}).eq("id",j.id);if(de(!1),t)return p.error(t.message);p.success("Tournoi transféré au nouveau juge-arbitre."),q(null),y()},ue=async(s,t)=>{le(s.id);const{error:n}=await m.from("tournaments").update({status:t}).eq("id",s.id);if(le(null),n)return p.error(n.message);p.success(t==="open"?"Tournoi mis en ligne — les joueurs peuvent maintenant s'inscrire.":"Tournoi repassé en brouillon — il n'est plus visible des joueurs."),y()},De=async()=>{if(!g)return;oe(!0);const{data:s,error:t}=await m.functions.invoke("cancel-tournament",{body:{tournament_id:g.id}});if(oe(!1),t)return p.error(t.message??"L'annulation a échoué.");const n=((s==null?void 0:s.refundedTotal)??0)/100,a=(s==null?void 0:s.emailed)??0;p.success(`Tournoi annulé. ${a} e-mail${a>1?"s":""} envoyé${a>1?"s":""}`+(n>0?` · ${n.toFixed(2).replace(".",",")} € remboursés.`:".")),O(null),y()},Me=r.useMemo(()=>{const s=new Map;return o.forEach(t=>{if(!t.referee_name)return;const n=t.referee_id??t.referee_name.trim().toLowerCase(),a=t.referee_name.trim(),d=s.get(n);(!d||/^[a-z]/.test(d)&&/^[A-ZÀ-Ý]/.test(a))&&s.set(n,a)}),Array.from(s.entries()).map(([t,n])=>({key:t,name:n})).sort((t,n)=>t.name.localeCompare(n.name))},[o]),Fe=r.useMemo(()=>{const s=new Set;o.forEach(n=>n.category&&s.add(n.category));const t=["P25","P50","P100","P250","P500"];return Array.from(s).sort((n,a)=>t.indexOf(n)-t.indexOf(a))},[o]),Ee=r.useMemo(()=>{const s=new Map;return o.forEach(t=>{if(!t.tournament_date)return;const n=t.tournament_date.slice(0,7),d=new Date(t.tournament_date).toLocaleDateString("fr-FR",{month:"long",year:"numeric"});s.set(n,d.charAt(0).toUpperCase()+d.slice(1))}),Array.from(s.entries()).sort(([t],[n])=>t.localeCompare(n))},[o]),me=s=>{var n;if(M[s.id])return M[s.id];const t={confirmed:0,pending:0,waitlist:0};return(n=s.registrations)==null||n.forEach(a=>{["pending","canceled"].includes(a.payment_status)||(a.status==="confirmed"?t.confirmed++:a.status==="pending"?t.pending++:a.status==="waitlist"&&t.waitlist++)}),t},Pe=s=>me(s).pending,xe=s=>D||s.referee_id===(c==null?void 0:c.id)||s.created_by===(c==null?void 0:c.id),fe=s=>xe(s)&&s.status!=="cancelled"?Pe(s):0,V=Qe(),z=r.useMemo(()=>o.filter(t=>{var a,d;const n=(t.tournament_date??"")<V;return!(!x&&(h==="upcoming"&&n||h==="past"&&!n)||v!=="all"&&(t.referee_id??((a=t.referee_name)==null?void 0:a.trim().toLowerCase()))!==v||w!=="all"&&t.category!==w||N!=="all"&&((d=t.tournament_date)==null?void 0:d.slice(0,7))!==N||C==="draft"&&t.status!=="draft"||C==="online"&&t.status==="draft"||F&&t.tournament_date<F||E&&t.tournament_date>E||x&&fe(t)===0)}).sort((t,n)=>{const a=(t.tournament_date??"").localeCompare(n.tournament_date??"");return h==="past"?-a:a}),[o,M,h,V,v,w,N,C,F,E,x]),J=r.useMemo(()=>o.filter(s=>(s.tournament_date??"")<V).length,[o,V]),pe=o.length-J,Oe=r.useMemo(()=>o.reduce((s,t)=>s+fe(t),0),[o,M]),he=r.useMemo(()=>o.filter(s=>s.status==="draft").length,[o]),Re=v!=="all"||N!=="all"||w!=="all"||C!=="all"||F||E||x,qe=()=>{se("all"),te("all"),ne("all"),re("all"),Se(""),ke(""),ae(!1)};return Ce?e.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Chargement…"}):c?!$&&!ee?e.jsx("div",{className:"container py-20 text-center text-muted-foreground",children:"Espace réservé aux juges-arbitres."}):e.jsxs("div",{className:"container py-10",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl md:text-4xl",children:$?"Esp
1ace juge-arbitre":"Inscriptions téléphone"}),e.jsx("p",{className:"text-muted-foreground",children:$?"Vos tournois et inscriptions à valider.":"Sélectionne un tournoi pour inscrire une paire."})]}),$&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(l,{asChild:!0,variant:"outline",className:"flex-1 md:flex-none",children:e.jsxs(b,{to:"/ja/paiements",children:[e.jsx(Je,{className:"h-4 w-4 mr-2"}),"Paiements"]})}),e.jsx(l,{asChild:!0,variant:"outline",className:"flex-1 md:flex-none",children:e.jsxs(b,{to:"/ja/planning",children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Planning global"]})}),e.jsx(l,{asChild:!0,className:"bg-court flex-1 md:flex-none",children:e.jsxs(b,{to:"/ja/tournoi/nouveau",children:[e.jsx(He,{className:"h-4 w-4 mr-2"}),"Nouveau tournoi"]})})]})]}),e.jsxs("div",{className:"inline-flex rounded-lg border bg-muted/40 p-1 mb-4",children:[e.jsxs("button",{type:"button",onClick:()=>ie("upcoming"),className:`px-4 py-1.5 text-sm font-medium rounded-md transition-colors ${h==="upcoming"?"bg-background shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:["À venir",pe>0?` · ${pe}`:""]}),e.jsxs("button",{type:"button",onClick:()=>ie("past"),className:`px-4 py-1.5 text-sm font-medium rounded-md transition-colors ${h==="past"?"bg-background shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:["Passés",J>0?` · ${J}
1`:""]})]}),e.jsxs(H,{className:"p-4 mb-6 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1 w-full sm:w-auto",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-bold",children:"Juge-arbitre"}),e.jsxs(_,{value:v,onValueChange:se,children:[e.jsx(S,{className:"w-full sm:w-[220px]",children:e.jsx(k,{})}),e.jsxs(A,{children:[e.jsx(u,{value:"all",children:"Tous les JA"}),Me.map(s=>e.jsx(u,{value:s.key,children:s.name},s.key))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-full sm:w-auto",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-bold",children:"Catégorie"}),e.jsxs(_,{value:w,onValueChange:ne,children:[e.jsx(S,{className:"w-full sm:w-[160px]",children:e.jsx(k,{})}),e.jsxs(A,{children:[e.jsx(u,{value:"all",children:"Toutes"}),Fe.map(s=>e.jsx(u,{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-full sm:w-auto",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-bold",children:"Mois"}),e.jsxs(_,{value:N,onValueChange:te,children:[e.jsx(S,{className:"w-full sm:w-[200px]",children:e.jsx(k,{})}),e.jsxs(A,{children:[e.jsx(u,{value:"all",children:"Tous les mois"}),Ee.map(([s,t])=>e.jsx(u,{value:s,children:t},s))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-full sm:w-auto",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-bold",children:"Diffusion"}),e.jsxs(_,{value:C,onValueChange:re,children:[e.jsx(S,{className:"w-full sm:w-[200px]",children:e.jsx(k,{})}),e.jsxs(A,{children:[e.jsx(u,{value:"all",children:"Tous"}),e.jsx(u,{value:"online",children:"En ligne"}),e.jsxs(u,{value:"draft",children:["Programmation (brouillons)",he>0?` · ${he}`:""]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 w-full sm:w-auto",children:[e.jsx("label",{className:"text-[11px] uppercase tracking-wide text-muted-foreground font-bold",children:"Action requise"}),e.jsxs(l,{type:"button",variant:x?"default":"outline",onClick:()=>ae(s=>!s),className:x?"bg-red-500 hover:bg-red-600 text-white w-full sm:w-auto":"w-full sm:w-auto",children:[e.jsx(Ye,{className:"h-4 w-4 mr-1.5"}),"À traiter",e.jsx("span",{className:`ml-2 text-[11px] font-bold px-1.5 py-0.5 rounded-full ${x?"bg-white/25 text-white":"bg-red-500 text-white"}`,children:Oe})]})]}),Re&&e.jsxs(l,{variant:"ghost",size:"sm",onClick:qe,children:[e.jsx(ze,{className:"h-4 w-4 mr-1"}),"Réinitialiser"]}),e.jsxs("div",{className:"w-full sm:w-auto sm:ml-auto text-sm text-muted-foreground",children:[z.length," tournoi",z.length>1?"s":""]})]}),z.length===0?e.jsx(H,{className:"p-10 text-center text-muted-foreground",children:"Aucun tournoi pour le moment."}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:z.map(s=>{var je,be;const t=me(s),n=D||ee||s.referee_id===c.id||s.created_by===c.id,a=D||s.referee_id===c.id||s.created_by===c.id,d=s.status==="draft",I=s.status==="cancelled",G=xe(s)&&!I&&t.pending>0;return e.jsxs(H,{className:`p-5 border-l-4 ${I?"border-l-destructive bg-destructive/5 opacity-90":d?"border-l-amber-400 ring-1 ring-amber-300/50 bg-amber-50/30 border-dashed":G?"border-l-amber-500 ring-1 ring-amber-300/60 bg-amber-50/40":"border-l-primary"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:`text-xs font-bold px-2 py-1 rounded border ${Ie[s.category]}`,children:s.category}),e.jsx("span",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:s.gender}),G&&e.jsxs("span",{className:"text-[10px] font-bold px-2 py-1 rounded-full bg-red-500 text-white",children:[t.pending," à valider"]}),e.jsx("span",{className:`ml-auto text-xs px-2 py-1 rounded border ${((je=ve[s.status])==null?void 0:je.cls)??""}`,children:(be=ve[s.status])==null?void 0:be.label})]}),e.jsx("h3",{className:"font-display text-xl",children:s.title}),e.jsx("div",{className:"text-sm text-muted-foreground capitalize",children:Ue(s.tournament_date)}),s.referee_name&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:["JA · ",s.referee_name]}),e.jsxs("div",{className:"mt-3 grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{className:"rounded bg-success/10 p-2",children:[e.jsx("div",{className:"font-display text-xl text-success",children:t.confirmed}),e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"Validées"})]}),e.jsxs("div",{className:`rounded p-2 ${G?"bg-amber-200":"bg-amber-100"}`,children:[e.jsx("div",{className:"font-display text-xl text-amber-900",children:t.pending}),e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"À valider"})]}),e.jsxs("div",{className:"rounded bg-muted p-2",children:[e.jsx("div",{className:"font-display text-xl",children:t.waitlist}),e.jsx("div",{className:"text-[10px] uppercase text-muted-foreground",children:"Liste d'attente"})]})]}),d&&a&&e.jsxs("div",{className:"mt-3 rounded-lg border border-amber-200 bg-amber-50 p-3 text-xs text-amber-900",children:["Ce tournoi est en ",e.jsx("b",{children:"programmation"})," : il n'est pas encore visible des joueurs. Mets-le en ligne quand le planning est validé."]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n?e.jsxs(e.Fragment,{children:[d&&a&&e.jsxs(l,{className:"flex-1 bg-success text-success-foreground hover:bg-success/90",disabled:f===s.id,onClick:()=>ue(s,"open"),children:[f===s.id?e.jsx(T,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(Xe,{className:"h-4 w-4 mr-1.5"}),"Mettre en ligne"]}),e.jsx(l,{asChild:!0,className:"flex-1 bg-court",children:e.jsx(b,{to:`/ja/tournoi/${s.id}`,children:"Gérer les inscriptions"})}),e.jsx(l,{asChild:!0,variant:"outline",size:"icon",children:e.jsx(b,{to:`/ja/tournoi/${s.id}/edit`,children:e.jsx(Ze,{className:"h-4 w-4"})})}),e.jsx(l,{variant:"outline",size:"icon",title:"Transférer à un autre juge-arbitre",onClick:()=>Te(s),children:e.jsx(Ke,{className:"h-4 w-4"})}),!d&&a&&e.jsx(l,{variant:"outline",size:"icon",title:"Repasser en brouillon (masquer aux joueurs)",disabled:f===s.id,onClick:()=>P(s),children:f===s.id?e.jsx(T,{className:"h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4"})}),!I&&a&&e.jsx(l,{variant:"outline",size:"icon",title:"Annuler le tournoi (remboursement + e-mail aux inscrits)",className:"text-destructive hover:text-destructive hover:bg-destructive/10 border-destructive/30",onClick:()=>O(s),children:e.jsx(we,{className:"h-4 w-4"})})]}):e.jsx(l,{asChild:!0,variant:"outline",className:"flex-1",children:e.jsx(b,{to:`/tournois/${s.id}`,children:"Voir le tournoi"})})})]},s.id)})}),e.jsx(Y,{open:!!j,onOpenChange:s=>!s&&q(null),children:e.jsxs(X,{children:[e.jsxs(Z,{children:[e.jsx(K,{children:"Transférer le tournoi"}),e.jsxs(Q,{children:["Donne la gestion de ",e.jsx("strong",{children:j==null?void 0:j.title})," à un autre juge-arbitre. Il pourra alors gérer les inscriptions, poules et résultats."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Nouveau juge-arbitre"}),e.jsxs(_,{value:L,onValueChange:ce,children:[e.jsx(S,{children:e.jsx(k,{placeholder:"Choisir un juge-arbitre"})}),e.jsx(A,{children:U.length===0?e.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"Aucun autre juge-arbitre disponible."}):U.map(s=>e.jsx(u,{value:s.id,children:`${s.first_name??""} ${s.last_name??""}`.trim()||"Sans nom"},s.id))})]})]}),e.jsxs(W,{children:[e.jsx(l,{variant:"outline",onClick:()=>q(null),disabled:B,children:"Annuler"}),e.jsxs(l,{onClick:$e,disabled:B||!L,children:[B&&e.jsx(T,{className:"h-4 w-4 mr-1.5 animate-spin"}),"Transférer"]})]})]})}),e.jsx(Y,{open:!!i,onOpenChange:s=>!s&&P(null),children:e.jsxs(X,{children:[e.jsxs(Z,{children:[e.jsx(K,{children:"Masquer ce tournoi aux joueurs ?"}),e.jsxs(Q,{className:"space-y-2",children:[e.jsxs("span",{className:"block",children:[e.jsx("strong",{children:i==null?void 0:i.title})," va repasser en ",e.jsx("strong",{children:"brouillon (programmation)"})," : il ne sera plus visible des joueurs et personne ne pourra s'y inscrire tant que tu ne l'auras pas remis en ligne."]}),(((ge=i==null?void 0:i.registrations)==null?void 0:ge.filter(s=>!["pending","canceled"].includes(s.payment_status)&&(s.status==="confirmed"||s.status==="pending")).length)??0)>0&&e.jsx("span",{className:"block rounded-md bg-amber-50 border border-amber-200 p-2 text-amber-900",children:"⚠️ Ce tournoi a dé
1jà des inscriptions. Elles ne sont pas supprimées, mais les joueurs ne verront plus le tournoi pendant qu'il est masqué."})]})]}),e.jsxs(W,{children:[e.jsx(l,{variant:"outline",onClick:()=>P(null),disabled:f===(i==null?void 0:i.id),children:"Annuler"}),e.jsxs(l,{variant:"destructive",disabled:f===(i==null?void 0:i.id),onClick:async()=>{await ue(i,"draft"),P(null)},children:[f===(i==null?void 0:i.id)?e.jsx(T,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4 mr-1.5"}),"Masquer aux joueurs"]})]})]})}),e.jsx(Y,{open:!!g,onOpenChange:s=>!s&&!R&&O(null),children:e.jsxs(X,{children:[e.jsxs(Z,{children:[e.jsx(K,{children:"Annuler ce tournoi ?"}),e.jsxs(Q,{className:"space-y-2",children:[e.jsxs("span",{className:"block",children:[e.jsx("strong",{children:g==null?void 0:g.title})," sera marqué ",e.jsx("strong",{children:"Annulé"})," et retiré des joueurs. Cette action est ",e.jsx("strong",{children:"définitive"}),"."]}),e.jsxs("span",{className:"block rounded-md bg-destructive/5 border border-destructive/30 p-2 text-destructive",children:["💸 Toutes les parts déjà réglées seront ",e.jsx("strong",{children:"remboursées automatiquement"})," (annulation à l'initiative du club, jour J compris).",e.jsx("br",{}),"✉️ Un e-mail d'excuses + une notification seront envoyés à ",e.jsx("strong",{children:"tous les inscrits"})," (sauf les paires déjà désinscrites)."]})]})]}),e.jsxs(W,{children:[e.jsx(l,{variant:"outline",onClick:()=>O(null),disabled:R,children:"Retour"}),e.jsxs(l,{variant:"destructive",onClick:De,disabled:R,children:[R?e.jsx(T,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(we,{className:"h-4 w-4 mr-1.5"}),"Annuler le tournoi"]})]})]})})]}):e.jsx(Ve,{to:"/auth"})};export{us as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.