PageSourceSearch

https://espacoolinda.com.br/assets/Distribution-BqlGLJg6.js

js espacoolinda.com.br collected 2026-09-30 06:37:32 UTC 12,904 bytes, 1 lines download raw bytes

1import{r as o,a6 as G,h as u,j as e,N,k as d,m as c,l as y,n as C,G as w,f as q,y as T,z as F,A as I,E as P,F as U,B,P as M,i as H}from"./index-qbwSSzHC.js";import{C as W,B as g,T as R,U as $,A as V}from"./AdminLayout-BOf1U8tc.js";import{S as O}from"./switch-DFPZOATq.js";import{T as S}from"./trending-up-DKsWu--3.js";import{U as _}from"./users-CkGBsrnp.js";import{S as D}from"./shield-BJJhQ9We.js";import{E as Q}from"./eye-Be9c5Zmk.js";import"./index-BPMNJrzz.js";import"./file-text-Dr5UXAuB.js";import"./circle-BapBo3O2.js";import"./circle-check-CitXkSz3.js";import"./mail-dEG3_Pc0.js";import"./building-2-B9VXW2nx.js";import"./chevron-right-E4ulpjwd.js";import"./popover-JzxPM3bN.js";import"./index-IZjEkk41.js";import"./arrow-left-DvifoaTV.js";import"./arrow-right-Cg-SBf0Q.js";import"./house-pazqF5aZ.js";const J=()=>{const[a,r]=o.useState(null),[t,x]=o.useState([]),[n,A]=o.useState(!0),[h,l]=o.useState(!1),{toast:p}=G();o.useEffect(()=>{k(),f()},[]);const k=async()=>{try{const{data:s,error:i}=await u.from("lead_distribution_config").select("*").limit(1).maybeSingle();if(i)throw i;s&&r(s)}catch(s){console.error("Error fetching config:",s),p({title:"Erro ao carregar configuração",description:"Não foi possível carregar a configuração de distribuição.",variant:"destructive"})}finally{A(!1)}},f=async()=>{try{const{data:s,error:i}=await u.rpc("get_users_with_roles");if(i)throw i;const L=(await Promise.all(s.map(async m=>{const{count:v}=await u.from("leads").select("*",{count:"exact",head:!0}).eq("assigned_to",m.id).is("deleted_at",null);return{user_id:m.id,email:m.email,lead_count:v||0,roles:m.roles}}))).filter(m=>m.roles.some(v=>["vendedor","sales"].includes(v)));x(L)}catch(s){console.error("Error fetching stats:",s)}},E=async()=>{if(a){l(!0);try{const{error:s}=await u.from("lead_distribution_config").update({is_active:a.is_active,distribution_method:a.distribution_method,eligible_roles:a.eligible_roles,updated_at:new Date().toISOString()}).eq("id",a.id);if(s)throw s;p({title:"Configuração salva",description:"As configurações de distribuição foram atualizadas com sucesso."}),f()}catch(s){console.error("Error saving config:",s),p({title:"Erro ao salvar",description:"Não foi possível salvar as configurações.",variant:"destructive"})}finally{l(!1)}}};if(n)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-primary"})});if(!a)return e.jsx(d,{children:e.jsx(c,{className:"p-6",children:e.jsx("p",{className:"text-muted-foreground",children:"Nenhuma configuração encontrada."})})});const b=t.reduce((s,i)=>s+i.lead_count,0),z=t.length>0?(b/t.length).toFixed(1):"0";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(d,{className:"border-yellow-400/30",children:[e.jsxs(y,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400"}),"Configuração de Distribuição Automática"]}),e.jsx(w,{children:"Configure como os novos leads serão automaticamente atribuídos aos vendedores"})]}),e.jsxs(c,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-2 border-yellow-400/50 rounded-lg bg-yellow-400/5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(q,{htmlFor:"active",className:"text-base font-semibold",children:"Distribuição Automática"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ativar atribuição automática de leads para vendedores"})]}),e.jsx(O,{id:"active",checked:a.is_active,onCheckedChange:s=>r({...a,is_active:s}),className:"data-[state=unchecked]:border-2 data-[state=unchecked]:border-yellow-400"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"method",children:"Método de Distribuição"}),e.jsxs(T,{value:a.distribution_method,onValueChange:s=>r({...a,distribution_method:s}),disabled:!a.is_active,children:[e.jsx(F,{id:"method",children:e.jsx(I,{})}),e.jsx(P,{children:e.jsx(U,{value:"round_robin",children:"Round Robin (Distribuição Equilibrada)"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Round Robin distribui os leads igualmente entre os vendedores disponíveis"})]}),e.jsxs(B,{onClick:E,disabled:h,children:[h&&e.jsx(N,{className:"mr-2 h-4 w-4 animate-spin"}),"Salvar Configuração"]})]})]}),e.jsxs(d,{children:[e.jsxs(y,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-5 w-5"}),"Estatísticas de Distribuição"]}),e.jsx(w,{children:"Visualize como os leads estão distribuídos entre os vendedores"})]}),e.jsxs(c,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3 mb-6",children:[e.jsx(d,{children:e.jsxs(c,{className:"pt-6",children:[e.jsx("div",{className:"text-2xl font-bold",children:t.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Vendedores Ativos"})]})}),e.jsx(d,{children:e.jsxs(c,{className:"pt-6",children:[e.jsx("div",{className:"text-2xl font-bold",children:b}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total de Leads"})]})}),e.jsx(d,{children:e.jsxs(c,{className:"pt-6",children:[e.jsx("div",{className:"text-2xl font-bold",children:z}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Média por Vendedor"})]})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(_,{className:"h-4 w-4"}),e.jsx("h4",{className:"font-semibold",children:"Leads por Vendedor"})]}),t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum vendedor cadastrado no sistema."}):t.sort((s,i)=>i.lead_count-s.lead_count).map(s=>{const i=b>0?(s.lead_count/b*100).toFixed(1):"0";return e.jsxs("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:s.email}),e.jsx("div",{className:"flex gap-1",children:s.roles.map(j=>e.jsx(g,{variant:"secondary",className:"text-xs",children:j},j))})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-2xl font-bold",children:s.lead_count}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i,"%"]})]})]}
1,s.user_id)})]})]})]})]})},K=()=>{const a=[{name:"Admin",icon:D,color:"text-red-600 dark:text-red-400",bgColor:"bg-red-50 dark:bg-red-950/20",description:"Acesso total ao sistema",permissions:["Gerenciar usuários e atribuir roles","Visualizar e editar todos os leads","Configurar distribuição automática","Acessar todas as funcionalidades","Gerenciar integrações e configurações"]},{name:"Direção",icon:R,color:"text-purple-600 dark:text-purple-400",bgColor:"bg-purple-50 dark:bg-purple-950/20",description:"Visão estratégica completa",permissions:["Visualizar todos os leads e eventos","Acompanhar performance de toda a equipe","Ver métricas e relatórios consolidados","Monitorar trabalho de gerentes e vendedores","Acesso a dashboard executivo"]},{name:"Gerência",icon:$,color:"text-blue-600 dark:text-blue-400",bgColor:"bg-blue-50 dark:bg-blue-950/20",description:"Gestão de equipes de vendas",permissions:["Visualizar leads da sua equipe","Gerenciar vendedores e SDRs","Acompanhar agendamentos e propostas","Criar e editar leads","Ver métricas da equipe"]},{name:"Gestor",icon:_,color:"text-cyan-600 dark:text-cyan-400",bgColor:"bg-cyan-50 dark:bg-cyan-950/20",description:"Coordenação operacional",permissions:["Visualizar e gerenciar leads","Acompanhar atividades da equipe","Criar propostas e agendamentos","Ver métricas operacionais"]},{name:"Sales",icon:S,color:"text-green-600 dark:text-green-400",bgColor:"bg-green-50 dark:bg-green-950/20",description:"Equipe de vendas",permissions:["Gerenciar leads atribuídos","Criar e editar propostas","Agendar visitas e eventos","Confirmar eventos","Receber leads via distribuição automática"]},{name:"SDR",icon:M,color:"text-orange-600 dark:text-orange-400",bgColor:"bg-orange-50 dark:bg-orange-950/20",description:"Pré-vendas e qualificação",permissions:["Criar e qualificar novos leads","Fazer primeiro contato","Agendar visitas","Ver leads ativos","Receber leads via distribuição automática"]},{name:"Vendedor",icon:R,color:"text-indigo-600 dark:text-indigo-400",bgColor:"bg-indigo-50 dark:bg-indigo-950/20",description:"Fechamento de vendas",permissions:["Gerenciar leads atribuídos","Criar e editar vendas","Acompanhar propostas","Gerenciar eventos confirmados","Receber leads via distribuição automática"]},{name:"Viewer",icon:Q,color:"text-gray-600 dark:text-gray-400",bgColor:"bg-gray-50 dark:bg-gray-950/20",description:"Apenas visualização",permissions:["Visualizar leads ativos","Sem permissões de edição","Acesso somente leitura"]}];return e.jsxs(d,{children:[e.jsxs(y,{children:[e.jsxs(C,{className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-5 w-5"}),"Hierarquia de Roles e Permissões"]}),e.jsx(w,{children:"Entenda como funcionam as permissões e a hierarquia de acesso no sistema"})]}),e.jsx(c,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-yellow-400/10 border border-yellow-400/30 rounded-lg",children:[e.jsxs("h3",{className:"font-semibold mb-2 flex items-center gap-2",children:[e.jsx(S,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-400"}),"Distribuição Automática de Leads"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Quando ativada, os novos leads são automaticamente distribuídos para:"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(g,{variant:"secondary",children:"Sales"}),e.jsx(g,{variant:"secondary",children:"Vendedor"}),e.jsx(g,{variant:"secondary",children:"SDR"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"A distribuição usa o método Round Robin, garantindo uma divisão equilibrada entre os vendedores ativos."})]}),e.jsx("div",{className:"grid gap-3",children:a.map(r=>{const t=r.icon;return e.jsx("div",{className:`p-4 border rounded-lg ${r.bgColor} border-opacity-30`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-background",children:e.jsx(t,{className:`h-5 w-5 ${r.color}`})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-semibold",children:r.name}),e.jsx(g,{variant:"outline",className:"text-xs",children:r.description})]}),e.jsx("ul",{className:"space-y-1 text-sm text-muted-foreground",children:r.permissions.map((x,n)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary mt-0.5",children:"•"}),e.jsx("span",{children:x})]},n))})]})]})},r.name)})}),e.jsxs("div",{className:"p-4 bg-blue-400/10 border border-blue-400/30 rounded-lg mt-6",children:[e.jsx("h3",{className:"font-semibold mb-2",children:"Fluxo de Trabalho Típico"}),e.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"1. SDR:"})," Recebe e qualifica novos leads, faz primeiro contato e agenda visitas."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"2. Vendedor/Sales:"})," Conduz a visita, cria proposta comercial e fecha a venda."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"3. Gestor/Gerência:"})," Acompanha o progresso, remove bloqueios e apoia a equipe."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"4. Direção:"})," Monitora métricas gerais, performance da equipe e resultados estratég
1icos."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"5. Admin:"})," Gerencia usuários, configurações do sistema e permissões."]})]})]})]})})]})},ge=()=>{const a=H(),[r,t]=o.useState(!1),[x,n]=o.useState(!0);return o.useEffect(()=>{(async()=>{const{data:{session:h}}=await u.auth.getSession();if(!h){n(!1),a("/login");return}const{data:l}=await u.from("user_roles").select("role").eq("user_id",h.user.id),p=["admin","direcao","gerencia","gestor"];if(!(l==null?void 0:l.some(f=>p.includes(f.role)))){n(!1),a("/admin");return}t(!0),n(!1)})()},[a]),x?e.jsx(V,{children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-primary"})})}):r?e.jsx(V,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold tracking-tight text-foreground flex items-center gap-2",children:[e.jsx(_,{className:"h-8 w-8"}),"Distribuição de Leads"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Configure e monitore a distribuição automática de leads entre sua equipe de vendas"})]}),e.jsx(J,{}),e.jsx(K,{})]})}):null};export{ge 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.