PageSourceSearch

https://codir.pro/assets/AffiliateDashboard-DiK41tKA.js

js codir.pro collected 2026-10-02 02:06:07 UTC 11,826 bytes, 1 lines download raw bytes

1import{r as a,j as e,L as y,T as ee,W as te,C as ae,b as o,t as l}from"./index-B0sM48fE.js";import{B as v}from"./badge-61pv9H8q.js";import{B as x}from"./button-CXcf0psP.js";import{C as re}from"./circle-check-CxxoOG2b.js";import{C as se}from"./copy-DiuWMnTl.js";import{C as ie}from"./clock-B4kNyysl.js";import{f as R}from"./format-Ds46GObI.js";import{f as $}from"./fr-BMUfRRx4.js";function he(){const[u,H]=a.useState(null),[d,w]=a.useState(null),[f,U]=a.useState([]),[c,C]=a.useState([]),[K,V]=a.useState(!0),[S,A]=a.useState(!1),[h,p]=a.useState(""),[de,G]=a.useState(""),[J,g]=a.useState(!1),[F,k]=a.useState(""),[b,D]=a.useState(""),[L,E]=a.useState(!1),[M,T]=a.useState(!1);a.useEffect(()=>{async function t(){var r,m,q;try{const i=await o.auth.me();H(i);const[X,Y,z]=await Promise.all([o.entities.AffiliateApplication.filter({email:i.email}),o.entities.AffiliateTransaction.filter({affiliateEmail:i.email}),o.entities.WithdrawalRequest.filter({affiliateEmail:i.email})]);let s=X[0]||null;if(i.role==="admin"){const j=(((r=i.email)==null?void 0:r.split("@")[0])||"admin").replace(/[^a-z0-9]/gi,"").toLowerCase();if(s){if(s.status!=="accepted")try{await o.entities.AffiliateApplication.update(s.id,{status:"accepted"}),s={...s,status:"accepted"}}catch(N){console.error(N)}}else try{s=await o.entities.AffiliateApplication.create({fullName:i.full_name||i.email,email:i.email,socialNetwork:"Instagram",socialHandle:"@admin",followers:0,motivation:"Admin account",status:"accepted",affiliateCode:j})}catch(N){console.error("Failed to auto-create admin affiliate:",N)}}w(s);const Z=(s==null?void 0:s.affiliateCode)||((m=i.email)==null?void 0:m.split("@")[0])||"";k(Z),D((s==null?void 0:s.affiliateCode)||""),U(Y),C(z);const B=((q=[...z].reverse().find(j=>j.iban))==null?void 0:q.iban)||"";G(B),p(B)}catch(i){console.error("AffiliateDashboard load error:",i),l.error("Échec du chargement des données affilié")}finally{V(!1)}}t()},[]);const O=async()=>{const t=b.trim().replace(/[^a-z0-9_-]/gi,"").toLowerCase();if(!t){l.error("Code invalide");return}E(!0);try{await o.entities.AffiliateApplication.update(d.id,{affiliateCode:t}),k(t),w(r=>({...r,affiliateCode:t})),l.success("Code mis à jour ✓")}catch{l.error("Échec de la mise à jour")}finally{E(!1)}},I=a.useMemo(()=>f.reduce((t,r)=>t+(r.commission||0),0),[f]),W=a.useMemo(()=>c.filter(t=>t.status==="paid").reduce((t,r)=>t+(r.amount||0),0),[c]),n=Math.max(0,I-W),P=c.some(t=>t.status==="pending"),_=`https://codir.pro/?ref=${F}`,Q=async()=>{if(!h.trim()){l.error("IBAN requis");return}A(!0);try{await o.entities.WithdrawalRequest.create({affiliateUserId:u.id,affiliateEmail:u.email,affiliateName:u.full_name,amount:n,iban:h.trim(),status:"pending"}),l.success("Demande de retrait envoyée ✓"),C(t=>[...t,{affiliateEmail:u.email,amount:n,iban:h.trim(),status:"pending"}]),g(!1),p("")}catch{l.error("Échec de la demande")}finally{A(!1)}};return K?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(y,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):!d||d.status!=="accepted"?e.jsxs("div",{className:"max-w-md mx-auto mt-16 text-center px-4",children:[e.jsx("div",{className:"text-4xl mb-4",children:"🤝"}),e.jsx("h2",{className:"font-space font-bold text-2xl text-foreground mb-2",children:"Programme d'affiliation"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:d?"Ta candidature est en cours d'examen.":"Tu n'as pas encore de compte affilié."}),!d&&e.jsx("a",{href:"/devenir-affilie",className:"inline-block bg-primary hover:bg-primary/90 text-primary-foreground font-medium px-6 py-2.5 rounded-lg transition-all",children:"Devenir affilié"}),(d==null?void 0:d.status)==="pending"&&e.jsx(v,{variant:"outline",className:"text-orange-400 border-orange-400/50",children:"En attente de validation"})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"font-space font-bold text-2xl sm:text-3xl text-foreground mb-1",children:"Mon espace affilié"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Suis tes commissions et demande tes paiements."})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3 sm:gap-4 mb-8",children:[e.jsxs("div",{className:"bg-card border border-border/50 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(ee,{className:"h-3.5 w-3.5"})," Total gagné"]}),e.jsxs("div",{className:"text-2xl font-bold text-green-400",children:[I.toFixed(2),"€"]})]}),e.jsxs("div",{className:"bg-card border border-border/50 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(re,{className:"h-3.5 w-3.5"})," Déjà versé"]}),e.jsxs("div",{className:"text-2xl font-bold text-foreground",children:[W.toFixed(2),"€"]})]}),e.jsxs("div",{className:`border rounded-xl p-4 col-span-2 md:col-span-1 ${n>=70?"bg-primary/10 border-primary/30":"bg-card border-border/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(te,{className:"h-3.5 w-3.5"})," Portefeuille disponible"]}),e.jsxs("div",{className:`text-2xl font-bold ${n>=70?"text-primary":"text-foreground"}`,children:[n.toFixed(2),"€"]}),n<70&&e.jsx("div",{className:"text-xs text-muted-foreground mt-1",children:"Minimum 70€ pour retirer"})]})]}),e.jsxs("div",{className:"bg-card border border-border/50 rounded-xl p-4 mb-6 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Ton lien de parrainage"}),e.jsx("div",{className:"text-sm font-mono text-foreground break-all",children:_})]}),e.jsx(x,{size:"sm",variant:"outline",onClick:()=>{navigator.clipboard.writeText(_),T(!0),setTimeout(()=>T(!1),2e3)},className:`transition-all duration-300 ${M?"bg-green-500/10 border-green-500/50 text-green-400":""}`,children:M?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5 mr-1 animate-in fade-in zoom-in"})," Copié !"]}):e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1"})," Copier"]})})]}),e.jsxs("div",{className:"border-t border-border/50 pt-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-2",children:"Personnalise ton code d'affiliation"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:b,onChange:t=>D(t.target.value.replace(/[^a-z0-9_-]/gi,"").toLowerCase()),placeholder:F,className:"bg-background border border-border rounded-lg px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary w-full sm:w-48"}),e.jsx(x,{size:"sm",onClick:O,disabled:L||b===((d==null?void 0:d.affiliateCode)||""),children:L?e.jsx(y,{className:"h-3.5 w-3.5 animate-spin"}):"Enregistrer"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Lettres, chiffres et tirets uniquement."})]})]}),n>=70&&!P&&e.jsx("div",{className:"mb-6",children:J?e.jsxs("div",{className:"bg-card border border-primary/30 rounded-xl p-4 space-y-3 max-w-md",children:[e.jsxs("div",{className:"font-medium text-foreground",children:["Demande de retrait — ",n.toFixed(2),"€"]}),e.jsxs("div",{className:"bg-orange-500/10 border border-orange-500/30 rounded-lg p-3 text-xs text-orange-400",children:["⚠️ Frais de traitement : 2 % seront déduits. Tu recevras ",(n*.98).toFixed(2),"€"]}),e.jsx("input",{placeholder:"IBAN (ex. FR76 3000 6000 0112 3456 7890 189)",value:h,onChange:t=>p(t.target.value),className:"w-full bg-background border border-border rounded-lg px-3 py-2.5 text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{onClick:Q,disabled:S,className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:S?e.jsx(y,{className:"h-3.5 w-3.5 animate-spin"}):"Confirmer"}),e.jsx(x,{variant:"outline",onClick:()=>g(!1),children:"Annuler"})]})]}):e.jsxs(x,{onClick:()=>g(!0),className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:["Demander un retrait (",n.toFixed(2),"€)"]})}),P&&e.jsxs("div",{className:"mb-6 flex items-center gap-2 text-orange-400 text-sm",children:[e.jsx(ie,{className:"h-4 w-4"})," Demande de retrait en cours de traitement…"]}),c.length>0&&e.jsxs("div",{className:"mb-8",children:[e.jsx("h2",{className:"font-space font-semibold text-foreground mb-3",children:"Historique des retraits"}),e.jsx("div",{className:"bg-card border border-border/50 rounded-xl overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm min-w-[520px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/50 text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"Date"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium",children:"Demandé"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium",children:"Reçu (après frais)"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium",children:"Statut"})]})}),e.jsx("tbody",{children:c.map(t=>{var r;return e.jsxs("tr",{className:"border-b border-border/30 hover:bg-secondary/20",children:[e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:t.created_date?R(new Date(t.created_date),"dd MMM yyyy",{locale:$}):"—"}),e.jsxs("td",{className:"px-4 py-3 text-right text-foreground",children:[(r=t.amount)==null?void 0:r.toFixed(2),"€"]}),e.jsxs("td",{className:"px-4 py-3 text-right text-foreground",children:[(t.amount*.98).toFixed(2),"€"]}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx(v,{variant:"outline",className:t.
1status==="paid"?"text-green-400 border-green-400/50":"text-orange-400 border-orange-400/50",children:t.status==="paid"?"Payé":"En attente"})})]},t.id)})})]})})]}),e.jsx("h2",{className:"font-space font-semibold text-foreground mb-3",children:"Historique des commissions"}),e.jsx("div",{className:"bg-card border border-border/50 rounded-xl overflow-x-auto",children:f.length===0?e.jsx("div",{className:"text-center py-10 text-muted-foreground text-sm",children:"Aucune commission pour le moment"}):e.jsxs("table",{className:"w-full text-sm min-w-[560px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border/50 text-muted-foreground text-xs",children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:"Date"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium hidden md:table-cell",children:"Service"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium",children:"Vente"}),e.jsx("th",{className:"text-right px-4 py-3 font-medium",children:"Commission (30 %)"}),e.jsx("th",{className:"text-center px-4 py-3 font-medium",children:"Statut"})]})}),e.jsx("tbody",{children:f.map(t=>{var r,m;return e.jsxs("tr",{className:"border-b border-border/30 hover:bg-secondary/20",children:[e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:t.created_date?R(new Date(t.created_date),"dd MMM yyyy",{locale:$}):"—"}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground hidden md:table-cell",children:t.serviceKey||"—"}),e.jsxs("td",{className:"px-4 py-3 text-right text-foreground",children:[(r=t.amount)==null?void 0:r.toFixed(2),"€"]}),e.jsxs("td",{className:"px-4 py-3 text-right text-green-400 font-medium",children:[(m=t.commission)==null?void 0:m.toFixed(2),"€"]}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx(v,{variant:"outline",className:t.paid?"text-green-400 border-green-400/50":"text-blue-400 border-blue-400/50",children:t.paid?"Payé":"Confirmé"})})]},t.id)})})]})})]})}export{he 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.