PageSourceSearch

https://porto-digital-nps.vercel.app/assets/Team-D_-Tl7O0.js

js porto-digital-nps.vercel.app collected 2026-10-03 07:31:37 UTC 17,194 bytes, 11 lines download raw bytes

1import{r as o,j as e}from"./vendor-react-Cn0q0KTy.js";import{c as Q,ac as be,d as ve,L as D,a4 as he,k as fe,m as ye,X as je,I as Ne,ad as we,ae as W,i as Ce,af as p}from"./index-L7pYYori.js";import{T as ke}from"./Toast-hQ6KgjvK.js";import{P as Se}from"./plus-DQe6f3gE.js";import{S as Ae}from"./search-BZ4oLcoz.js";import{C as ze}from"./circle-x-b7c1h5EN.js";import{B as K}from"./ban-C1f6yMeh.js";import{P as Re}from"./pen-line-CE61jmyw.js";import{T as Ee}from"./trash-2-CEqc86eE.js";import{S as Ie}from"./save-BG5nBx53.js";import"./vendor-supabase-B9q_TACa.js";/**
2 * @license lucide-react v0.559.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 Le=[["path",{d:"M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16",key:"jecpp"}],["rect",{width:"20",height:"14",x:"2",y:"6",rx:"2",key:"i6l2r4"}]],Me=Q("briefcase",Le);/**
7 * @license lucide-react v0.559.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Oe=[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]],Y=Q("crown",Oe),Pe={"Master Admin":3,Admin:2,Colaborador:1},T=n=>Pe[n]||0,De=({role:n})=>{const g={"Master Admin":{bg:"bg-amber-50 text-amber-700 border-amber-200",icon:e.jsx(Y,{size:10})},Admin:{bg:"bg-purple-50 text-purple-700 border-purple-100",icon:e.jsx(W,{size:10})},Colaborador:{bg:"bg-blue-50 text-blue-700 border-blue-100",icon:e.jsx(Me,{size:10})}},b=g[n]||g.Colaborador;return e.jsxs("span",{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-lg text-[10px] font-bold uppercase tracking-tight border ${b.bg}`,children:[b.icon," ",n]})},Te=({role:n})=>n==="Master Admin"?e.jsx("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center bg-amber-100 text-amber-700",children:e.jsx(Y,{size:16})}):n==="Admin"?e.jsx("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center bg-purple-100 text-purple-700",children:e.jsx(W,{size:16})}):e.jsx("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center bg-blue-100 text-blue-700",children:e.jsx(Ce,{size:16})}),Qe=()=>{const{admins:n,loading:g,addAdminUser:b,updateAdminUser:Z,deleteAdminUser:ee,resendAdminInvite:U,revokeAdminInvite:_}=be(),{currentUser:i,activeUnit:se}=ve(),[C,te]=o.useState(""),[k,$]=o.useState(null),a=(s,r="success")=>$({message:s,type:r}
11),[ae,d]=o.useState(!1),[q,x]=o.useState(!1),[re,F]=o.useState(!1),[v,V]=o.useState(null),[B,G]=o.useState(null),[oe,h]=o.useState(null),[S,X]=o.useState(new Set),[ie,f]=o.useState(null),[ne,u]=o.useState(!1),[t,H]=o.useState(null),[y,A]=o.useState(""),[j,z]=o.useState(""),[N,R]=o.useState("Colaborador"),[E,I]=o.useState(!0),L=(i==null?void 0:i.role)||"Colaborador",M=T(L),m=L==="Master Admin",c=M>=2,O=m,le=n.filter(s=>s.name.toLowerCase().includes(C.toLowerCase())||s.email.toLowerCase().includes(C.toLowerCase())),de=()=>{if(!c){a("Apenas administradores podem cadastrar novos usuários.","error");return}H(null),A(""),z(""),R("Colaborador"),I(!0),d(!0),u(!1)},ce=s=>{if(!c&&s.email!==(i==null?void 0:i.email)){a("Você não tem permissão para editar outros usuários.","error");return}H(s),A(s.name),z(s.email),R(s.role),I(s.active),d(!0),u(!1)},xe=()=>m?[{value:"Colaborador",label:"Colaborador (Operacional)"},{value:"Admin",label:"Administrador (Gestão)"},{value:"Master Admin",label:"Master Admin (Controle Total)"}]:L==="Admin"?[{value:"Colaborador",label:"Colaborador (Operacional)"},{value:"Admin",label:"Administrador (Gestão)"}]:[{value:"Colaborador",label:"Colaborador (Operacional)"}],me=async s=>
11{if(s.preventDefault(),!(!y||!j)){if(T(N)>M){a("Você não pode atribuir um nível de acesso superior ao seu.","error");return}if(x(!0),t){if(!m&&T(t.role)>=M&&t.email!==(i==null?void 0:i.email)){x(!1),a("Você não pode editar usuários do mesmo nível ou superior.","error");return}const r=j.toLowerCase().trim(),l=t.status==="Pending"&&r!==t.email.toLowerCase().trim();if(l&&!(await _(t.id)).success){x(!1),a("Não foi possível invalidar o convite anterior; o e-mail não foi alterado. Tente novamente.","error");return}const w=await Z({...t,name:y,email:r,role:N,active:E});if(x(!1),w)if(d(!1),l){const P=await U(t.id);a(P.success?"E-mail corrigido. O convite anterior foi invalidado e um novo link foi enviado.":'E-mail corrigido e convite anterior invalidado, mas o novo envio falhou. Use "Reenviar convite".',P.success?"success":"error")}else a("Usuário atualizado com sucesso!","success");else a(l?"Erro ao atualizar usuário. O convite anterior já foi invalidado — reenvie o convite após corrigir.":"Erro ao atualizar usuário.","error")}else try{const r=await b({name:y,email:j.toLowerCase().trim(),role:N,unit_id:se.id});x(!1),r.success?(d(!1),a(r.notice?`Convite enviado por e-mail. O link de ativação chega direto ao convidado. ${p(r.notice).message}`:"Convite enviado por e-mail. O link de ativação chega direto ao convidado.","success")):a(p(r.reason).message,"error")}catch{x(!1),a("Erro de conexão ao tentar convidar.","error")}}},J=async s=>{V(s.id),h(null),f(null);try{const r=await U(s.id);r.success?(X(l=>{if(!l.has(s.id))return l;const w=new Set(l);return w.delete(s.id),w}),a(r.notice?`Novo convite enviado; o link anterior foi invalidado. ${p(r.notice).message}`:"Novo convite enviado; o link anterior foi invalidado.","success")):a(p(r.reason).message,"error")}catch{a("Erro de conexão ao reenviar.","error")}finally{V(null)}},ue=async s=>{G(s.id);try{const r=await _(s.id);r.success?(X(l=>new Set(l).add(s.id)),a("Convite revogado. O link enviado deixou de funcionar.","success")):a(p(r.reason).message,"error")}catch{a("Erro de conexão ao revogar.","error")}finally{G(null),h(null)}},pe=s=>{s.preventDefault(),s.stopPropagation(),O&&u(!0)},ge=async s=>{if(s.preventDefault(),s.stopPropagation(),!(!t||!O)){F(!0);try{await ee(t)?(d(!1),a("Usuário excluído com sucesso.","success")):(a("Erro ao excluir. Verifique suas permissões.","error"),u(!1))}catch{a("Erro de conexão.","error")}finally{F(!1)}}};return g?e.jsx("div",{className:"flex justify-center p-10",children:e.jsx(D,{className:"animate-spin text-primary",size:48})}):e.jsxs("div",{className:"space-y-6",children:[k&&e.jsx(ke,{message:k.message,type:k.type,onClose:()=>$(null)}),e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Gestão da Equipe"}),e.jsx("p",{className:"text-gray-500",children:"Convide novos membros e gerencie acessos."})]}),c&&e.jsxs("button",{onClick:de,className:"bg-primary text-white px-4 py-2 rounded-xl font-medium hover:bg-blue-700 hover:shadow-xl hover:shadow-primary/30 transition-all flex items-center gap-2 shadow-lg shadow-primary/25 active:scale-[0.98]",children:[e.jsx(Se,{size:18}),"Novo Usuário"]})]}),e.jsx("div",{className:"bg-white p-4 rounded-2xl shadow-sm border border-gray-100 flex flex-col md:flex-row gap-4",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400",size:20}),e.jsx("input",{type:"text",placeholder:"Buscar por Nome ou E-mail...",className:"w-full pl-10 pr-4 py-2 border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary bg-white text-gray-900 transition-all",value:C,onChange:s=>te(s.target.value)})]})}),e.jsx("div",{className:"bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-gray-400 font-bold uppercase text-[10px] tracking-widest",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4",children:"Nome"}),e.jsx("th",{className:"px-6 py-4",children:"E-mail"}),e.jsx("th",{className:"px-6 py-4",children:"Função"}),m&&e.jsx("th",{className:"px-6 py-4",children:"Unidade"}),e.jsx("th",{className:"px-6 py-4",children:"Status"}),e.jsx("th",{className:"px-6 py-4 text-right",children:"Ações"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:le.map(s=>e.jsxs("tr",{className:"hover:bg-gray-50 group",children:[e.jsxs("td",{className:"px-6 py-4 font-medium text-gray-900 flex items-center gap-3",children:[e.jsx(Te,{role:s.role}),s.name]}),e.jsx("td",{className:"px-6 py-4 text-gray-600 font-medium",children:s.email}),e.jsx("td",{className:"px-6 py-4",children:e.jsx(De,{role:s.role})}),m&&e.jsx("td",{className:"px-6 py-4",children:e.jsx("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-lg text-[10px] font-bold uppercase tracking-tight border bg-gray-50 text-gray-600 border-gray-200",children:s.unit_name||"N/A"})}),e.jsx("td",{className:"px-6 py-4",children:s.status==="Pending"?e.jsxs("span",{className:"flex items-center gap-1 text-amber-600 text-[10px] font-bold uppercase tracking-widest bg-amber-50 px-3 py-1.5 rounded-lg w-fit border border-amber-100",children:[e.jsx(he,{size:12})," Pendente"]}):s.active?e.jsxs("span",{className:"flex items-center gap-1 text-green-600 text-[10px] font-bold uppercase tracking-widest bg-green-50 px-3 py-1.5 rounded-lg w-fit border border-green-100",children:[e.jsx(fe,{size:12})," Ativo"]}):e.jsxs("span",{className:"flex items-center gap-1 text-gray-500 text-[10px] font-bold uppercase tracking-widest bg-gray-100 px-3 py-1.5 rounded-lg w-fit border border-gray-200",children:[e.jsx(ze,{size:12})," Inativo"]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[s.status==="Pending"&&c&&(oe===s.id?e.jsxs("div",{className:"flex items-center gap-2 text-xs",role:"group","aria-label":"Confirmar revogação do convite",children:[e.jsx("span",{className:"text-red-600",children:"Revogar convite?"}),e.jsx("button",{type:"button",disabled:B===s.id,onClick:()=>ue(s),className:"bg-red-600 text-white px-2.5 py-1 rounded-lg hover:bg-red-700 font-medium transition-all disabled:opacity-60",children:B===s.id?"Revogando...":"Sim, revogar"}),e.jsx("button",{type:"button",onClick:()=>h(null),className:"text-gray-400 hover:text-gray-600 transition-colors",children:"Cancelar"})]}):ie===s.id?e.jsxs("div",{className:"flex items-center gap-2 text-xs",role:"group","aria-label":"Confirmar reenvio de convite revogado",children:[e.jsx("span",{className:"text-amber-600",children:"Convite revogado. Reenviar mesmo assim?"}),e.jsx("button",{type:"button",disabled:v===s.id,onClick:()=>{f(null),J(s)},className:"bg-amber-600 text-white px-2.5 py-1 rounded-lg hover:bg-amber-700 font-medium transition-all disabled:opacity-60",children:v===s.id?"Reenviando...":"Sim, reenviar"}),e.jsx("button",{type:"button",onClick:()=>f(null),className:"text-gray-400 hover:text-gray-600 transition-colors",children:"Cancelar"})]}):e.jsxs(e.Fragment,{children:[S.has(s.id)&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg text-[10px] font-bold uppercase tracking-tight border bg-red-50 text-red-600 border-red-200",title:"Convite revogado nesta sessão",children:[e.jsx(K,{size:10})," Revogado"]}),e.jsx("button",{type:"button",disabled:v===s.id,onClick:()=>{S.has(s.id)?f(s.id):J(s)},title:S.has(s.id)?"Convite revogado — reenviar exige confirmação":"Reenviar convite por e-mail","aria-label":`Reenviar convite para ${s.name}`,className:"p-2 text-gray-400 hover:text-primary hover:bg-blue-50 rounded-xl transition-all disabled:opacity-60",children:v===s.id?e.jsx(D,{size:16,className:"animate-spin"}):e.jsx(ye,{size:16})}),e.jsx("button",{type:"button",onClick:()=>h(s.id),title:"Revogar convite","aria-label":`Revogar convite de ${s.name}`,className:"p-2 text-gray-400 hover:text-red-600 hover:bg-red-50 rounded-xl transition-all",children:e.jsx(K,{size:16})})]})),(c||s.email===(i==null?void 0:i.email))&&e.jsx("button",{onClick:()=>ce(s),className:"p-2 text-gray-400 hover:text-primary hover:bg-blue-50 rounded-xl transition-all",children:e.jsx(Re,{size:16})})]})})]},s.id))})]})})}),ae&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4 animate-fade-in",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-md overflow-hidden animate-slide-up",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:t?"Editar Usuário":"Convidar Equipe"}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:"Segurança e níveis de acesso"})]}),e.jsx("button",{onClick:()=>d(!1),className:"p-1.5 hover:bg-gray-100 rounded-lg text-gray-400 hover:text-gray-600 transition-all",children:e.jsx(je,{size:18})})]}),e.jsxs("form",{onSubmit:me,className:"px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"team-invite-name",className:"block text-xs text-gray-500 mb-1.5",children:"Nome completo"}),e.jsx("input",{id:"team-invite-name",type:"text",required:!0,className:"w-full px-3.5 py-2.5 border border-gray-200 rounded-xl focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none bg-white text-sm text-gray-900 transition-all",value:y,onChange:s=>A(s.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"team-invite-email",className:"block text-xs text-gray-500 mb-1.5",children:"E-mail corporativo"}),e.jsx("input",{id:"team-invite-email",type:"email",required:!0,disabled:!!t&&t.status==="Active",className:`w-full px-3.5 py-2.5 border border-gray-200 rounded-xl focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none text-sm text-gray-900 transition-all ${t&&t.status==="Active"?"bg-gray-50 text-gray-400 cursor-not-allowed":"bg-white"}`,value:j,onChange:s=>
11z(s.target.value)}),t&&t.status==="Pending"&&e.jsxs("p",{className:"text-[11px] text-amber-600 mt-1 flex items-center gap-1",children:[e.jsx(Ne,{size:10})," E-mail pode ser corrigido enquanto o convite estiver pendente."]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"team-invite-role",className:"block text-xs text-gray-500 mb-1.5",children:"Nível de acesso"}),e.jsx("select",{id:"team-invite-role",disabled:!c,className:"w-full px-3.5 py-2.5 border border-gray-200 rounded-xl focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none bg-white text-sm text-gray-900 transition-all disabled:bg-gray-50 disabled:text-gray-400",value:N,onChange:s=>R(s.target.value),children:xe().map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),t&&m&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"team-invite-unit",className:"block text-xs text-gray-500 mb-1.5",children:"Unidade"}),e.jsx("input",{id:"team-invite-unit",type:"text",readOnly:!0,className:"w-full px-3.5 py-2.5 border border-gray-200 rounded-xl bg-gray-50 text-sm text-gray-400 cursor-not-allowed outline-none",value:t.unit_name||"N/A"})]}),t&&c&&e.jsxs("label",{className:`flex items-center gap-3 px-4 py-3 rounded-xl border transition-all cursor-pointer ${E?"bg-primary/5 border-primary/20 text-primary":"bg-gray-50 border-gray-100 text-gray-400"}`,children:[e.jsx("input",{type:"checkbox",checked:E,onChange:s=>I(s.target.checked),className:"w-4 h-4 text-primary rounded border-gray-300 focus:ring-primary/30 transition-all"}),e.jsx("span",{className:"text-sm font-medium",children:"Usuário ativo no sistema"})]}),e.jsxs("div",{className:"pt-4 border-t border-gray-100 mt-2",children:[t&&O&&t.email!==(i==null?void 0:i.email)&&e.jsx("div",{className:"mb-4",children:ne?e.jsxs("div",{className:"flex items-center gap-3 text-sm animate-fade-in",children:[e.jsx("span",{className:"text-red-600 text-xs",children:"Confirmar exclusão?"}),e.jsx("button",{type:"button",onClick:ge,disabled:re,className:"bg-red-600 text-white text-xs px-3 py-1 rounded-lg hover:bg-red-700 font-medium transition-all",children:"Sim, excluir"}),e.jsx("button",{type:"button",onClick:s=>{s.preventDefault(),u(!1)},className:"text-gray-400 text-xs hover:text-gray-600 transition-colors",children:"Cancelar"})]}):e.jsxs("button",{type:"button",onClick:pe,className:"text-red-400 hover:text-red-600 text-xs flex items-center gap-1.5 transition-colors",children:[e.jsx(Ee,{size:14})," Excluir usuário"]})}),e.jsxs("div",{className:"flex gap-3 justify-end",children:[e.jsx("button",{type:"button",onClick:()=>d(!1),className:"px-5 py-2.5 text-gray-500 text-sm hover:bg-gray-100 rounded-xl transition-all",children:"Cancelar"}),e.jsxs("button",{type:"submit",disabled:q,className:"px-6 py-2.5 bg-primary text-white rounded-xl hover:bg-blue-700 text-sm font-medium transition-all shadow-sm hover:shadow-md flex items-center gap-2 active:scale-[0.98]",children:[q?e.jsx(D,{size:16,className:"animate-spin"}):t?e.jsx(Ie,{size:16}):e.jsx(we,{size:16}),t?"Salvar":"Convidar"]})]})]})]})]})})]})};export{Qe 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.