PageSourceSearch

https://www.instagem.ai/assets/AdminDirect-CMMxhQbc.js

js instagem.ai collected 2026-10-05 12:05:33 UTC 10,771 bytes, 6 lines download raw bytes

1import{D as z,a as F,r as h,j as e,C as l,g as c,h as d,k as w,l as o,c as b,aa as Y,ab as H,ac as W,ad as q,ae as G,ak as J,aW as K,T as Q,W as B}from"./main-DX7XzkoU.js";import{S as j}from"./skeleton-DN2cjZOe.js";import{B as v}from"./badge-BOGaWzi1.js";import{C as X}from"./chevron-left-B_lb0x5L.js";import{C as Z}from"./chevron-right-D27HfhtL.js";import{E as ee}from"./eye-DTdVPMB0.js";import{U as se}from"./user-plus-CFqzcP75.js";import{D as te}from"./dollar-sign-CCKaWTsS.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ae=z("ShoppingCart",[["circle",{cx:"8",cy:"21",r:"1",key:"jimo8o"}],["circle",{cx:"19",cy:"21",r:"1",key:"13723u"}],["path",{d:"M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12",key:"9zh506"}]]);function me(){var L,$;const C=F(),[T,_]=h.useState(!0),[m,P]=h.useState(null),[S,p]=h.useState(null),[u,V]=h.useState(()=>{const s=new Date;return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}`}),M=30,D=50,i=h.useMemo(()=>{const s=[],r=new Date;for(let a=0;a<12;a++){const n=new Date(r.getFullYear(),r.getMonth()-a,1),y=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}`,g=n.toLocaleDateString("pt-BR",{month:"long",year:"numeric"});s.push({value:y,label:g.charAt(0).toUpperCase()+g.slice(1)})}return s},[]),f=async s=>{var r,a;_(!0),p(null);try{const{data:{user:n}}=await B.auth.getUser();if(!n){C("/login");return}const y=s??u,{data:g,error:N}=await B.rpc("get_direct_commission_data",{p_limit:50,p_month:y});if(N){if(console.error("RPC error:",N),(r=N.message)!=null&&r.includes("Access denied")||(a=N.message)!=null&&a.includes("Admin privileges")){p("Acesso negado. Você precisa ser administrador."),C("/dashboard");return}p("Erro ao carregar dados. Tente novamente.");return}P(g)}catch(n){console.error("Error fetching direct metrics:",n),p("Erro ao carregar dados. Tente novamente.")}finally{_(!1)}};h.useEffect(()=>{f()},[]);const R=s=>{V(s),f(s)},k=s=>{const a=i.findIndex(n=>n.value===u)-s;a>=0&&a<i.length&&R(i[a].value)},x=s=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(s),I=s=>s?new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"-",U=s=>{if(!s)return"-";const r=s.includes("-annual"),a=s.replace("-annual","");return`${a.charAt(0).toUpperCase()+a.slice(1)} ${r?"(Anual)":"(Mensal)"}`},O=s=>s!=null&&s.includes("-annual")?"default":"secondary",t=m==null?void 0:m.metrics,A=(m==null?void 0:m.recent_sales)??[],E=t!=null&&t.reference_month?new Date(t.reference_month+"-01").toLocaleDateString("pt-BR",{month:"long",year:"numeric"}):"";return T?e.jsx("div",{className:"min-h-screen bg-background p-4 md:p-6 space-y-6",children:e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsx(j,{className:"h-8 w-64 mb-2"}),e.jsx(j,{className:"h-4 w-96 mb-6"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-6",children:[1,2,3,4].map(s=>e.jsx(j,{className:"h-32 w-full rounded-lg"},s))}),e.jsx(j,{className:"h-40 w-full rounded-lg mb-4"}),e.jsx(j,{className:"h-64 w-full rounded-lg"})]})}):S?e.jsx("div",{className:"min-h-screen bg-background p-4 md:p-6 flex items-center justify-center",children:e.jsxs(l,{className:"max-w-md w-full",children:[e.jsxs(c,{children:[e.jsx(d,{className:"text-destructive",children:"Erro"}),e.jsx(w,{children:S})]}),e.jsx(o,{children:e.jsx(b,{onClick:()=>f(),children:"Tentar novamente"})})]})}):e.jsx("div",{className:"min-h-screen bg-background p-4 md:p-6",children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl font-bold tracking-tight",children:"Comissionamento Direct"}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:["Vendas do source ",e.jsx(v,{variant:"outline",className:"ml-1",children:"direct"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>
6k(-1),disabled:u===((L=i[i.length-1])==null?void 0:L.value),children:e.jsx(X,{className:"h-4 w-4"})}),e.jsxs(Y,{value:u,onValueChange:R,children:[e.jsx(H,{className:"w-[180px] h-8",children:e.jsx(W,{})}),e.jsx(q,{children:i.map(s=>e.jsx(G,{value:s.value,children:s.label},s.value))})]}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>k(1),disabled:u===(($=i[0])==null?void 0:$.value),children:e.jsx(Z,{className:"h-4 w-4"})}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>f(),className:"gap-2 ml-2",children:[e.jsx(J,{className:"h-4 w-4"}),"Atualizar"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(l,{children:[e.jsxs(c,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium text-muted-foreground",children:"Acessos"}),e.jsx(ee,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:((t==null?void 0:t.page_views)??0).toLocaleString("pt-BR")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Page views no mês"})]})]}),e.jsxs(l,{children:[e.jsxs(c,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium text-muted-foreground",children:"Cadastros"}),e.jsx(se,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:((t==null?void 0:t.signups)??0).toLocaleString("pt-BR")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Novos cadastros no mês"})]})]}),e.jsxs(l,{children:[e.jsxs(c,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium text-muted-foreground",children:"Compras Mensais"}),e.jsx(ae,{className:"h-4 w-4 text-blue-500"})]}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(t==null?void 0:t.monthly_purchases)??0}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["× R$",M," = ",e.jsx("span",{className:"font-semibold text-green-600",children:x((t==null?void 0:t.commission_monthly_brl)??0)})]})]})]}),e.jsxs(l,{children:[e.jsxs(c,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(d,{className:"text-sm font-medium text-muted-foreground",children:"Compras Anuais"}),e.jsx(K,{className:"h-4 w-4 text-purple-500"})]}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:(t==null?void 0:t.annual_purchases)??0}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["× R$",D," = ",e.jsx("span",{className:"font-semibold text-green-600",children:x((t==null?void 0:t.commission_annual_brl)??0)})]})]})]})]}),e.jsxs(l,{className:"border-green-200 bg-green-50/50 dark:bg-green-950/20 dark:border-green-900",children:[e.jsxs(c,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx(d,{className:"text-lg font-semibold",children:"Comissão Total do Mês"}),e.jsx(w,{children:E})]}),e.jsx(te,{className:"h-6 w-6 text-green-600"})]}),e.jsxs(o,{children:[e.jsx("div",{className:"text-3xl md:text-4xl font-bold text-green-600",children:x((t==null?void 0:t.commission_total_brl)??0)}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:gap-4 mt-3 text-sm text-muted-foreground",children:[e.jsxs("span",{children:[(t==null?void 0:t.monthly_purchases)??0," mensal × R$",M," = ",x((t==null?void 0:t.commission_monthly_brl)??0)]}),e.jsx("span",{className:"hidden sm:inline text-muted-foreground/50",children:"|"}),e.jsxs("span",{children:[(t==null?void 0:t.annual_purchases)??0," anual × R$",D," = ",x((t==null?void 0:t.commission_annual_brl)??0)]})]})]})]}),e.jsxs(l,{children:[e.jsx(c,{children:e.jsxs(d,{className:"text-lg flex items-center gap-2",children:[e.jsx(Q,{className:"h-5 w-5"}),"Plano de Comissionamento"]})}),e.jsx(o,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Tipo de Venda"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Comissão por Venda"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Descrição"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"border-b",children:[e.jsx("td",{className:"py-3 px-3",children:e.jsx(v,{variant:"secondary",children:"Mensal"})}),e.jsx("td",{className:"py-3 px-3 font-semibold text-green-600",children:"R$ 30,00"}),e.jsx("td",{className:"py-3 px-3 text-muted-foreground",children:"Para cada assinatura mensal (Starter, Pro, Elite) vinda do source direct"})]}),e.jsxs("tr",{children:[e.jsx("td",{className:"py-3 px-3",children:e.jsx(v,{variant:"default",children:"Anual"})}),e.jsx("td",{className:"py-3 px-3 font-semibold text-green-600",children:"R$ 50,00"}),e.jsx("td",{className:"py-3 px-3 text-muted-foreground",children:"Para cada assinatura anual vinda do source direct"})]})]})]})})})]}),e.jsxs(l,{children:[e.jsxs(c,{children:[e.jsx(d,{className:"text-lg",children:"Vendas do Mês"}),e.jsxs(w,{children:["Vendas do source direct em ",E]})]}),e.jsx(o,{children:A.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"Nenhuma venda encontrada para o source direct."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Email"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Plano"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Comissão"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"Data da Compra"}),e.jsx("th",{className:"text-left py-2 px-3 font-medium",children:"LTV"})]})}),e.jsx("tbody",{children:A.map(s=>e.jsxs("tr",{className:"border-b last:border-b-0 hover:bg-muted/50",children:[e.jsx("td",{className:"py-3 px-3 font-mono text-xs",children:s.email}),e.jsx("td",{className:"py-3 px-3",children:e.jsx(v,{variant:O(s.plan_slug),children:U(s.plan_slug)})}),e.jsx("td",{className:"py-3 px-3 font-semibold text-green-600",children:x(s.commission_brl)}),e.jsx("td",{className:"py-3 px-3 text-muted-foreground",children:I(s.subscribed_at)}),e.jsx("td",{className:"py-3 px-3",children:x(Number(s.ltv_brl)||0)})]},s.id))})]})})})]})]})})}export{me 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.