PageSourceSearch

https://radreport.com.br/assets/CreditsTab-DJ9I1bnY.js

js radreport.com.br collected 2026-09-24 14:37:14 UTC 4,939 bytes, 1 lines download raw bytes

1import{u as I,j as e}from"./vendor-query-skQMsM6X.js";import{r as c}from"./vendor-react-DyYvSSk1.js";import{I as w,p as i,at as B,aQ as O,ak as m,ab as S,am as $,an as F,ao as H,ap as L,az as P,as as Q,b as f,c as g,X as A}from"./index-BGwtrXIa.js";import{T as q,a as G,b as h,c as x,d as K,e as t}from"./table-DnRDtd-j.js";import{U as W}from"./UserSubscriptionModal-ChNexcSj.js";import{Y as X,aR as Y,ag as J,bN as V,O as Z}from"./vendor-ui-CCmu0bzQ.js";import"./vendor-supabase-BfoV2C50.js";import"./pt-BR-0bEujIJO.js";function le(){const[j,T]=c.useState(""),[a,l]=c.useState(null),[d,u]=c.useState(""),[v,_]=c.useState(!1),[C,N]=c.useState(null),k=async()=>{try{const{data:s}=await f.from("user_ai_balance").select("user_id, balance, plan_type, monthly_limit").order("balance",{ascending:!1}),r=(s==null?void 0:s.map(n=>n.user_id))||[],{data:o}=await f.from("profiles").select("id, full_name").in("id",r);return(s||[]).map(n=>{var b;return{id:n.user_id,full_name:((b=o==null?void 0:o.find(z=>z.id===n.user_id))==null?void 0:b.full_name)||null,ai_balance:n.balance,plan_type:n.plan_type,monthly_limit:n.monthly_limit}})}catch(s){throw A.error("Error fetching credits:",s),g.error("Erro ao carregar créditos"),s}},{data:D=[],isLoading:E,refetch:p}=I({queryKey:["admin-users-credits"],queryFn:k,staleTime:6e4,refetchOnWindowFocus:!1}),U=async()=>{if(!(!a||!d)){_(!0);try{const s=parseInt(d),r=a.action==="remove"?-s:s,o=`Ajuste manual via admin (${a.action==="add"?"+":"-"}${s})`,{data:R,error:n}=await f.rpc("admin_adjust_credits",{p_user_id:a.user.id,p_amount:r,p_description:o});if(n)throw n;g.success(`Créditos ${a.action==="add"?"adicionados":"removidos"} com sucesso`),l(null),u(""),p()}catch(s){console.error("Error adjusting credits (full):",s),A.error("Error adjusting credits:",s);const r=(s==null?void 0:s.message)||"Erro desconhecido";g.error(`Erro ao ajustar créditos: ${r}`)}finally{_(!1)}}},y=D.filter(s=>{var r;return j?(r=s.full_name)==null?void 0:r.toLowerCase().includes(j.toLowerCase()):!0});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(X,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(w,{placeholder:"Buscar usuário...",value:j,onChange:s=>T(s.target.value),className:"pl-9"})]}),e.jsx(i,{variant:"outline",size:"icon",onClick:()=>{p()},children:e.jsx(Y,{className:"h-4 w-4"})})]}),e.jsx(B,{children:e.jsx(O,{className:"h-[500px]",children:e.jsxs(q,{children:[e.jsx(G,{children:e.jsxs(h,{children:[e.jsx(x,{children:"Usuário"}),e.jsx(x,{children:"Plano"}),e.jsx(x,{className:"text-center",children:"Créditos AI"}),e.jsx(x,{className:"text-right",children:"Ações"})]})}),e.jsx(K,{children:E?[...Array(5)].map((s,r)=>e.jsxs(h,{children:[e.jsx(t,{children:e.jsx(m,{className:"h-6 w-32"})}),e.jsx(t,{children:e.jsx(m,{className:"h-5 w-16"})}),e.jsx(t,{children:e.jsx(m,{className:"h-6 w-12 mx-auto"})}),e.jsx(t,{children:e.jsx(m,{className:"h-8 w-20 ml-auto"})})]},r)):y.length===0?e.jsx(h,{children:e.jsx(t,{colSpan:4,className:"text-center py-8 text-muted-foreground",children:"Nenhum usuário encontrado"})}):y.map(s=>e.jsxs(h,{children:[e.jsx(t,{className:"font-medium",children:s.full_name||"Sem nome"}),e.jsx(t,{children:e.jsx(S,{variant:"outline",className:"capitalize",children:s.plan_type})}),e.jsx(t,{className:"text-center",children:e.jsx(S,{variant:"secondary",className:"text-lg px-3",children:s.ai_balance||0})}),e.jsx(t,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(i,{variant:"outline",size:"sm",onClick:()=>l({user:s,action:"add"}),title:"Adicionar créditos",children:e.jsx(J,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"sm",onClick:()=>l({user:s,action:"remove"}),title:"Remover créditos",children:e.jsx(V,{className:"h-4 w-4"})}),e.jsx(i,{variant:"outline",size:"sm",onClick:()=>N(s),title:"Gerenciar assinatura",children:e.jsx(Z,{className:"h-4 w-4"})})]})})]},s.id))})]})})}),e.jsx($,{open:!!a,onOpenChange:()=>{l(null),u("")}
1,children:e.jsxs(F,{children:[e.jsxs(H,{children:[e.jsxs(L,{children:[(a==null?void 0:a.action)==="add"?"Adicionar":"Remover"," Créditos"]}),e.jsxs(P,{children:["Usuário: ",(a==null?void 0:a.user.full_name)||"Sem nome",e.jsx("br",{}),"Saldo atual: ",(a==null?void 0:a.user.ai_balance)||0," créditos"]})]}),e.jsx("div",{className:"py-4",children:e.jsx(w,{type:"number",placeholder:"Quantidade de créditos",value:d,onChange:s=>u(s.target.value),min:1})}),e.jsxs(Q,{children:[e.jsx(i,{variant:"outline",onClick:()=>{l(null),u("")},children:"Cancelar"}),e.jsx(i,{onClick:U,disabled:!d||v,variant:(a==null?void 0:a.action)==="remove"?"destructive":"default",children:v?"Processando...":(a==null?void 0:a.action)==="add"?"Adicionar":"Remover"})]})]})}),e.jsx(W,{user:C,open:!!C,onOpenChange:s=>!s&&N(null),onSaved:p})]})}export{le 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.