PageSourceSearch

https://plataforma.bizzu.ai/assets/GestaoAfiliadosPage-Yj0SDeEg.js

js bizzu.ai collected 2026-10-05 15:09:13 UTC 11,929 bytes, 1 lines download raw bytes

1import{r as o,j as e,m as R,L as S}from"./index-DJx_SGrm.js";import{l as E,f as y,a as I,b as k,c as D,r as V}from"./afiliadoApi-DobX99pG.js";const A=100;function w(t){const l=Number(String(t).replace(",","."));return Number.isFinite(l)?Math.round(l*A):NaN}function b({label:t,hint:l,children:a}){return e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-widest text-ds-text-tertiary",children:t}),a,l&&e.jsx("span",{className:"text-[11px] text-ds-text-tertiary",children:l})]})}const h="rounded-[var(--ds-radius-control)] border border-ds-border bg-ds-surface px-3 py-2 text-[14px] text-ds-text-primary outline-none focus:border-ds-accent";function T({onCriado:t,onCancelar:l}){const[a,v]=o.useState({nome:"",email:"",senha:"",couponCode:"",whatsapp:"",comissaoReais:"20",carenciaDias:"7"}),[c,g]=o.useState(null),[x,m]=o.useState(!1),n=d=>i=>v(p=>({...p,[d]:i.target.value})),u=async d=>{d.preventDefault(),g(null);const i=w(a.comissaoReais);if(!Number.isInteger(i)||i<0){g("Comissão inválida.");return}m(!0);try{await D({nome:a.nome,email:a.email,senha:a.senha,couponCode:a.couponCode,whatsapp:a.whatsapp||null,comissaoCentavos:i,carenciaDias:Number(a.carenciaDias)||7}),t()}catch(p){g((p==null?void 0:p.message)??"Falha ao cadastrar."),m(!1)}};return e.jsxs("form",{onSubmit:u,className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4 flex flex-col gap-3",children:[e.jsx("p",{className:"text-[13px] font-semibold text-ds-text-primary",children:"Novo afiliado"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:[e.jsx(b,{label:"Nome",children:e.jsx("input",{className:h,value:a.nome,onChange:n("nome"),required:!0})}),e.jsx(b,{label:"E-mail (login)",children:e.jsx("input",{className:h,type:"email",value:a.email,onChange:n("email"),required:!0})}),e.jsx(b,{label:"Senha",hint:"Mín. 8, com maiúscula, número e símbolo",children:e.jsx("input",{className:h,value:a.senha,onChange:n("senha"),required:!0})}),e.jsx(b,{label:"Cupom",hint:"Precisa existir no Stripe (ex.: ISA30)",children:e.jsx("input",{className:`${h} uppercase`,value:a.couponCode,onChange:d=>v(i=>({...i,couponCode:d.target.value.toUpperCase()})),required:!0})}),e.jsx(b,{label:"Comissão por venda (R$)",children:e.jsx("input",{className:h,value:a.comissaoReais,onChange:n("comissaoReais"),inputMode:"decimal"})}),e.jsx(b,{label:"Carência (dias)",hint:"Janela de reembolso do aluno",children:e.jsx("input",{className:h,value:a.carenciaDias,onChange:n("carenciaDias"),inputMode:"numeric"})}),e.jsx(b,{label:"WhatsApp (opcional)",children:e.jsx("input",{className:h,value:a.whatsapp,onChange:n("whatsapp")})})]}),c&&e.jsx("p",{className:"text-[12px] text-ds-danger-text",children:c}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(R,{type:"submit",disabled:x,className:"text-[13px]",children:x?"Cadastrando…":"Cadastrar"}),e.jsx("button",{type:"button",onClick:l,className:"rounded-[var(--ds-radius-control)] border border-ds-border px-4 py-2 text-[13px] text-ds-text-tertiary",children:"Cancelar"})]})]})}function F({afiliado:t,onRegistrado:l,onCancelar:a}){const v=(t.resumo.comissaoAReceberCentavos/A).toFixed(2),[c,g]=o.useState(v),[x,m]=o.useState(""),[n,u]=o.useState(null),[d,i]=o.useState(!1),p=t.comissaoCentavos>0?Math.round(t.resumo.comissaoAReceberCentavos/t.comissaoCentavos):null,C=async f=>{f.preventDefault(),u(null);const j=w(c);if(!Number.isInteger(j)||j<=0){u("Valor inválido.");return}i(!0);try{await V(t.id,{valorCentavos:j,vendasQtd:p,referencia:x||null}),l()}catch(N){u((N==null?void 0:N.message)??"Falha ao registrar."),i(!1)}};return e.jsxs("form",{onSubmit:C,className:"mt-2 rounded-[var(--ds-radius-card)] border border-ds-border-subtle bg-ds-canvas p-3 flex flex-wrap items-end gap-3",children:[e.jsx(b,{label:"Valor pago (R$)",children:e.jsx("input",{className:h,value:c,onChange:f=>g(f.target.value),inputMode:"decimal"})}),e.jsx(b,{label:"Referência (opcional)",children:e.jsx("input",{className:h,value:x,onChange:f=>m(f.target.value),placeholder:"agosto/2026"})}),e.jsx("button",{type:"submit",disabled:d,className:"rounded-[var(--ds-radius-control)] border border-ds-success-border bg-ds-success-surface px-4 py-2 text-[13px] font-semibold text-ds-success-text disabled:opacity-60",children:d?"Salvando…":"Registrar pagamento"}),e.jsx("button",{type:"button",onClick:a,className:"rounded-[var(--ds-radius-control)] border border-ds-border px-3 py-2 text-[13px] text-ds-text-tertiary",children:"Fechar"}),n&&e.jsx("p",{className:"w-full text-[12px] text-ds-danger-text",children:n})]})}function M(){const[t,l]=o.useState([]),[a,v]=o.useState(!0),[c,g]=o.useState(null),[x,m]=o.useState(!1),[n,u]=o.useState(null),d=o.useCallback(async()=>{v(!0),g(null);try{l(await E())}catch(s){g((s==null?void 0:s.message)??"Falha ao carregar.")}finally{v(!1)}},[]);o.useEffect(()=>{d()},[d]);const i=async s=>{const r=s.status==="ACTIVE"?"INACTIVE":"ACTIVE";await k(s.id,{status:r}),d()},p=t.reduce((s,r)=>s+r.resumo.comissaoAReceberCentavos,0),C=t.reduce((s,r)=>s+r.resumo.vendasTotais-r.resumo.vendasReembolsadas,0),f=t.reduce((s,r)=>s+r.resumo.receitaGeradaCentavos,0),j=t.reduce((s,r)=>s+r.funil.digitaram,0),N=t.reduce((s,r)=>s+r.funil.compraram,0);return e.jsxs("div",{className:"flex flex-col gap-4 max-w-[1100px]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-ds-text-primary",children:"Afiliados"}),e.jsxs("p",{className:"text-[12px] text-ds-text-tertiary mt-0.5",children:["Cada afiliado tem login próprio em ",e.jsx("code",{className:"text-ds-accent-text",children:"/afiliado"})," e vê só as vendas do cupom dele."]})]}),!x&&e.jsx(R,{type:"button",onClick:()=>m(!0),className:"text-[13px]",children:"+ Novo afiliado"})]}),x&&e.jsx(T,{onCriado:()=>{m(!1),d()},onCancelar:()=>m(!1)}),!a&&!c&&t.length>0&&e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-ds-text-tertiary mb-1",children:"A pagar agora"}),e.jsx("p",{className:"text-2xl font-bold text-ds-text-primary",children:y(p)})]}),e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-ds-text-tertiary mb-1",children:"Digitaram cupom"}),e.jsx("p",{className:"text-2xl font-bold text-ds-text-primary tabular-nums",children:j}),e.jsxs("p",{className:"text-[11px] text-ds-text-tertiary mt-0.5",children:[N," assinaram",j>0&&` · ${Math.round(N/j*100)}%`]})]}),e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-ds-text-tertiary mb-1",children:"Vendas por afiliados"}),e.jsx("p",{className:"text-2xl font-bold text-ds-text-primary",children:C})]}),e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-widest text-ds-text-tertiary mb-1",children:"Receita gerada"}),e.jsx("p",{className:"text-2xl font-bold text-ds-text-primary",children:y(f)})]})]}),a&&e.jsx(S,{}),!a&&c&&e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-danger-border bg-ds-panel p-4",children:[e.jsx("p",{className:"text-[13px] text-ds-danger-text",children:c}),e.jsx("button",{type:"button",onClick:d,className:"mt-3 rounded-[var(--ds-radius-control)] border border-ds-border px-3 py-2 text-[13px] text-ds-text-primary",children:"Tentar de novo"})]}),!a&&!c&&t.length===0&&!x&&e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-8 text-center",children:[e.jsx("p",{className:"text-[13px] text-ds-text-tertiary",children:"Nenhum afiliado cadastrado. Crie o cupom no Stripe e cadastre o influenciad
1or aqui."}),e.jsx(R,{type:"button",onClick:()=>m(!0),className:"mt-4 text-[14px]",children:"+ Cadastrar primeiro afiliado"})]}),!a&&!c&&t.map(s=>e.jsxs("div",{className:"rounded-[var(--ds-radius-card)] border border-ds-border bg-ds-panel p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-[15px] font-semibold text-ds-text-primary",children:[s.nome,e.jsx("span",{className:`ml-2 rounded-full px-2 py-0.5 text-[10px] font-bold uppercase ${s.status==="ACTIVE"?"bg-ds-success-surface text-ds-success-text":"bg-ds-surface-hover text-ds-text-tertiary"}`,children:s.status==="ACTIVE"?"ativo":"inativo"})]}),e.jsxs("p",{className:"text-[12px] text-ds-text-tertiary mt-0.5",children:[s.email,s.whatsapp?` · ${s.whatsapp}`:""]}),e.jsxs("p",{className:"text-[12px] text-ds-text-tertiary mt-0.5",children:["Cupom ",e.jsx("strong",{className:"text-ds-accent-text",children:s.couponCode})," · ",y(s.comissaoCentavos),"/venda · carência ",s.carenciaDias,"d ·"," ",s.ultimoAcessoEm?`último acesso ${I(s.ultimoAcessoEm)}`:"nunca acessou"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>u(n===s.id?null:s.id),className:"rounded-[var(--ds-radius-control)] border border-ds-border px-3 py-2 text-[12px] font-semibold text-ds-text-primary",children:"Registrar pagamento"}),e.jsx("button",{type:"button",onClick:()=>i(s),className:"rounded-[var(--ds-radius-control)] border border-ds-border px-3 py-2 text-[12px] text-ds-text-tertiary",children:s.status==="ACTIVE"?"Desativar":"Reativar"})]})]}),e.jsx("div",{className:"mt-3 grid gap-2 sm:grid-cols-5 text-center",children:[{l:"Confirmadas",v:s.resumo.vendasTotais-s.resumo.vendasReembolsadas},{l:"Liberadas",v:s.resumo.vendasLiberadas},{l:"Em carência",v:s.resumo.vendasEmCarencia},{l:"Reembolsadas",v:s.resumo.vendasReembolsadas},{l:"A pagar",v:y(s.resumo.comissaoAReceberCentavos),destaque:!0}].map(r=>e.jsxs("div",{className:"rounded-[var(--ds-radius-control)] border border-ds-border-subtle bg-ds-canvas px-2 py-2",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-ds-text-tertiary",children:r.l}),e.jsx("p",{className:`text-[15px] font-bold ${r.destaque?"text-ds-success-text":"text-ds-text-primary"}`,children:r.v})]},r.l))}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 rounded-[var(--ds-radius-control)] border border-ds-border-subtle bg-ds-canvas px-3 py-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-ds-text-tertiary",children:"Pessoas"}),e.jsxs("span",{className:"text-[12px] text-ds-text-secondary",children:[e.jsx("strong",{className:"text-ds-text-primary tabular-nums",children:s.funil.digitaram})," digitaram"]}),e.jsx("span",{className:"text-ds-text-tertiary",children:"→"}),e.jsxs("span",{className:"text-[12px] text-ds-text-secondary",children:[e.jsx("strong",{className:"text-ds-text-primary tabular-nums",children:s.funil.cupomAceito})," aplicaram"]}),e.jsx("span",{className:"text-ds-text-tertiary",children:"→"}),e.jsxs("span",{className:"text-[12px] text-ds-text-secondary",children:[e.jsx("strong",{className:"text-ds-success-text tabular-nums",children:s.funil.compraram})," assinaram"]}),s.funil.digitaram>0&&e.jsxs("span",{className:"text-[11px] text-ds-text-tertiary",children:["(",Math.round(s.funil.compraram/s.funil.digitaram*100),"% de conversão)"]}),s.funil.soRecusados>0&&e.jsxs("span",{className:"text-[11px] text-ds-warning-text",children:[s.funil.soRecusados," só levaram recusa"]})]}),n===s.id&&e.jsx(F,{afiliado:s,onRegistrado:()=>{u(null),d()},onCancelar:()=>u(null)})]},s.id))]})}export{M as GestaoAfiliadosPage,M 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.