PageSourceSearch

https://sentinel-365-c9d4f.web.app/assets/GrClientesPage-DtCOWvX8.js

js sentinel-365-c9d4f.web.app collected 2026-10-03 12:36:53 UTC 10,015 bytes, 1 lines download raw bytes

1import{j as e,r as m}from"./react-vendor-pafHdoJx.js";import{b as f,d as y,u as N,j as C,l as j}from"./index-Db0fDLGN.js";import{T as k,L as S,E as w}from"./shared-DHvo53EK.js";import{B as E,bc as M,L as X}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";function B({onDone:t}){const{toast:l}=N(),[r,v]=m.useState("plataforma"),[i,c]=m.useState(""),[n,x]=m.useState(""),[u,g]=m.useState(""),[p,d]=m.useState(!1),a=async()=>{d(!0);try{if(r==="plataforma"){const s=await y.delegationRequest(i.trim());l({title:s.alreadyActive?"Este cliente já delegou pra você.":"Pedido enviado — o cliente aprova com um clique (aparece no painel e no radar dele).",kind:"success"}),j("gr_client_delegation_requested",{})}else await y.grClienteCreate({nome:n.trim(),cnpj:i.trim()||void 0,contato:u.trim()||void 0}),l({title:"Cliente cadastrado. Próximo passo: vincule os motoristas dele pelo código M-XXXXX (Monitoramento) e abra as SMs em Risco · SM → Nova SM.",kind:"success"}),j("gr_client_leve_created",{});c(""),x(""),g(""),t()}catch(s){const o=(s==null?void 0:s.message)||"Falha ao cadastrar";l({title:o,kind:"error"}),/não tem conta/.test(o)&&v("leve")}finally{d(!1)}},b="px-3 py-2 rounded-lg border text-sm bg-transparent",h={borderColor:"var(--border-primary)",color:"var(--page-text)"};return e.jsxs("div",{className:"rounded-xl border p-4 mb-4",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:[e.jsxs("p",{className:"text-sm font-bold flex items-center gap-1.5",style:{color:"var(--page-text)"},children:[e.jsx(M,{size:14})," Novo cliente"]}),e.jsx("div",{className:"flex gap-2 mt-2.5",role:"radiogroup","aria-label":"Tipo de cliente",children:[["plataforma","Já usa o Sentinel"],["leve","Só o app (cliente leve)"]].map(([s,o])=>e.jsx("button",{role:"radio","aria-checked":r===s,onClick:()=>v(s),className:"px-3 py-1.5 rounded-lg text-xs font-semibold border",style:r===s?{background:"#E11D4815",color:"#E11D48",borderColor:"#E11D4840"}:{color:"var(--page-text-secondary)",borderColor:"var(--border-primary)"},children:o},s))}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-3",children:[r==="leve"&&e.jsx("input",{className:b,style:h,value:n,onChange:s=>x(s.target.value),placeholder:"Nome do cliente *","aria-label":"Nome do cliente"}),e.jsx("input",{className:b,style:h,value:i,onChange:s=>c(s.target.value),placeholder:r==="plataforma"?"CNPJ do cliente *":"CNPJ (opcional)","aria-label":"CNPJ"}),r==="leve"&&e.jsx("input",{className:b,style:h,value:u,onChange:s=>g(s.target.value),placeholder:"Contato (opcional)","aria-label":"Contato"}),e.jsx("button",{onClick:a,disabled:p||(r==="plataforma"?i.trim().length<14:n.trim().length<2),className:"px-4 py-2 rounded-lg text-xs font-bold disabled:opacity-50",style:{background:"#E11D48",color:"#fff"},children:p?e.jsx(X,{size:13,className:"animate-spin"}):r==="plataforma"?"Pedir delegação":"Cadastrar cliente"})]}),e.jsx("p",{className:"text-[11px] mt-2",style:{color:"var(--page-text-muted)"},children:r==="plataforma"?"O pedido chega pro cliente como pendência — um clique dele ativa a delegação (sm + monitor), revogável a qualquer momento.":"Cliente leve não precisa de conta: os motoristas entram pelo app (código M-XXXXX) e as SMs são abertas por você, com o nome do cliente na carteira e no laudo."})]})}function F({c:t,onChanged:l}){const{toast:r}=N(),{confirmar:v}=C(),[i,c]=m.useState(!1),[n,x]=m.useState(t.nome||""),[u,g]=m.useState(t.contato||""),[p,d]=m.useState(!1),a=async()=>{d(!0);try{await y.grClienteUpdate(t.id,{nome:n.trim(),contato:u.trim()}),r({title:"Cliente atualizado. SMs antigas mantêm o nome da época — as novas usam o novo.",kind:"success"}),c(!1),l()}catch(o){r({title:(o==null?void 0:o.message)||"Falha ao salvar",kind:"error"})}finally{d(!1)}},b=async()=>{if(await v({titulo:`Remover "${t.nome}" da carteira?`,descricao:"O histórico de SMs dele continua nos laudos.",confirmar:"Remover"})){d(!0);try{await y.grClienteDelete(t.id),r({title:"Cliente removido da carteira.",kind:"success"}),l()}catch(o){r({title:(o==null?void 0:o.message)||"Falha ao remover",kind:"error"})}finally{d(!1)}}},h="px-2 py-1 rounded-lg border text-[13px] bg-transparent",s={borderColor:"var(--border-primary)",color:"var(--page-text)"};return e.jsx("div",{className:"rounded-lg border px-3 py-2 flex items-center justify-between gap-2 flex-wrap",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:i?e.jsxs(e.Fragment,{children:[e.jsx("input",{className:h,style:s,value:n,onChange:o=>x(o.target.value),"aria-label":"Nome do cliente"}),e.jsx("input",{className:`${h} flex-1 min-w-[160px]`,style:s,value:u,onChange:o=>g(o.target.value),placeholder:"Contato","aria-label":"Contato"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:a,disabled:p||n.trim().length<2,className:"px-3 py-1 rounded-lg text-xs font-bold disabled:opacity-50",style:{background:"#10B981",color:"#fff"},children:p?"…":"Salvar"}),e.jsx("button",{onClick:()=>c(!1),className:"px-2 py-1 text-xs",style:{color:"var(--page-text-secondary)"},children:"Cancelar"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[13px] font-semibold",style:{color:"var(--page-text)"},children:[t.nome,t.cnpjMasked?` · ${t.cnpjMasked}`:""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px]",style:{color:"var(--page-text-secondary)"},children:t.contato||"motoristas via código M-XXXXX"}),e.jsx("button",{onClick:()=>{x(t.nome||""),g(t.contato||""),c(!0)},className:"text-[11px] underline",style:{color:"var(--page-text-secondary)"},"aria-label":`Editar ${t.nome}`,children:"editar"}),e.jsx("button",{onClick:b,disabled:p,className:"text-[11px] disabled:opacity-50",style:{color:"#EF4444"},"aria-label":`Remover ${t.nome}`,children:"remover"})]})]})})}function O(){var x,u,g,p,d;const t=f(()=>y.smOverview(),[]),l=f(()=>y.delegationsList(),[]),r=f(()=>y.grClientes(),[]),v=((x=t.data)==null?void 0:x.clientes)||[],i=(((u=l.data)==null?void 0:u.received)||((g=l.data)==null?void 0:g.items)||[]).filter(a=>(a.status||"active")==="active"),c=(((p=l.data)==null?void 0:p.received)||[]).filter(a=>a.status==="requested"),n=((d=r.data)==null?void 0:d.items)||[];return e.jsxs(k,{icon:E,title:"Clientes",subtitle:"Quem delegou a operação de risco pra você — e o volume de cada um.",children:[e.jsx(B,{onDone:()=>{l.refetch(),r.refetch()}}),c.length>0&&e.jsxs("div",{className:"rounded-xl border px-4 py-3 mb-4",style:{borderColor:"#F59E0B40",background:"#F59E0B12"},children:[e.jsxs("p",{className:"text-xs font-bold",style:{color:"#B45309"},children:["Aguardando aceite do cliente (",c.length,")"]}),c.map(a=>e.jsxs("p",{className:"text-[11px] mt-1",style:{color:"var(--page-text-secondary)"},children:[a.grantorName||a.grantorOrgId," — o pedido está no painel e no radar dele; um clique ativa."]},a.id))]}),n.length>0&&e.jsxs("section",{className:"mb-4",children:[e.jsxs("h2",{className:"text-xs font-bold uppercase tracking-wide mb-2",style:{color:"var(--page-text-secondary)"},children:["Clientes leves — só o app (",n.length,")"]}),e.jsx("div",{className:"space-y-1.5",children:n.map(a=>e.jsx(F,{c:a,onChanged:()=>r.refetch()},a.id))})]}),t.loading&&!t.data?e.jsx(S,{}):e.jsxs("div",{className:"space-y-4",children:[v.length===0?e.jsx(w,{text:"Nenhum cliente ainda. Peça ao embarcador/trans
1portadora uma delegação com escopo SM (Rede & Integração → Delegações) — a sua própria organização opera sem delegação."}):e.jsx("div",{className:"rounded-xl border overflow-x-auto",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[11px] uppercase tracking-wide",style:{color:"var(--page-text-secondary)"},children:[e.jsx("th",{className:"px-3 py-2.5",children:"Cliente"}),e.jsx("th",{className:"px-3 py-2.5 text-right",children:"SMs"}),e.jsx("th",{className:"px-3 py-2.5 text-right",children:"Na fila"}),e.jsx("th",{className:"px-3 py-2.5 text-right",children:"Aprovadas"}),e.jsx("th",{className:"px-3 py-2.5 text-right",children:"Negadas"})]})}),e.jsx("tbody",{children:v.map(a=>e.jsxs("tr",{className:"border-t",style:{borderColor:"var(--border-primary)"},children:[e.jsx("td",{className:"px-3 py-2 font-semibold",style:{color:"var(--page-text)"},children:a.nome||a.grantorOrgId}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",style:{color:"var(--page-text)"},children:a.total}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums font-bold",style:{color:a.fila>0?"#F59E0B":"var(--page-text-secondary)"},children:a.fila}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",style:{color:"#10B981"},children:a.aprovadas}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",style:{color:"#EF4444"},children:a.negadas})]},a.grantorOrgId))})]})}),e.jsxs("section",{children:[e.jsxs("h2",{className:"text-xs font-bold uppercase tracking-wide mb-2",style:{color:"var(--page-text-secondary)"},children:["Delegações ativas (",i.length,")"]}),i.length===0?e.jsxs("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:["Nenhuma delegação recebida — gerencie em ",e.jsx("a",{href:"/torre/config",className:"underline",children:"Rede & Integração"}),"."]}):e.jsx("div",{className:"space-y-1.5",children:i.map(a=>e.jsxs("div",{className:"rounded-lg border px-3 py-2 flex items-center justify-between gap-2",style:{borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},children:[e.jsx("p",{className:"text-[13px] font-semibold",style:{color:"var(--page-text)"},children:a.grantorName||a.grantorOrgId}),e.jsxs("p",{className:"text-[11px]",style:{color:"var(--page-text-secondary)"},children:["escopos: ",(a.scopes||[]).join(", ")||"—"]})]},a.id||a.delegationId))})]})]})]})}export{O 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.