2 lines
7.7 KiB
JavaScript
2 lines
7.7 KiB
JavaScript
import{j as e}from"./query-vendor-BLVqILA6.js";import{d as I,r as a}from"./router-vendor-D4by-_6Z.js";import{s as m}from"./index-doec96Hx.js";import{u as U}from"./useInviteCode-BxOSdQOT.js";import{N as B}from"./NeuralNetworkBackground-CER-dIFD.js";import{B as O,$ as D,a2 as f,a0 as b,aq as V,p as F,c as j,ar as L}from"./ui-vendor-CyRvbSfR.js";import"./react-vendor-CqRd3GwO.js";import"./supabase-vendor-CnnNSQLo.js";import"./state-vendor-DHadhBU5.js";const $=()=>{const i=I(),{loading:o,validarConvite:w,usarConvite:N}=U(),[r,v]=a.useState(""),[l,c]=a.useState("input"),[d,u]=a.useState(null),[x,n]=a.useState(""),[y,C]=a.useState(""),[k,z]=a.useState("");a.useEffect(()=>{(async()=>{const{data:{user:t}}=await m.auth.getUser();if(!t){i("/login");return}z(t.id),C(t.user_metadata?.full_name||t.user_metadata?.nome||t.email?.split("@")[0]||"Usuário");const{data:p}=await m.from("usuarios").select("organizacao_id").eq("id",t.id).single();p&&p.organizacao_id&&i("/dashboard")})()},[i]);const h=async()=>{if(!r.trim()){n("Digite o código de convite.");return}n("");const s=await w(r);s.success?(u({organizacao_nome:s.organizacao_nome||"Organização",organizacao_id:s.organizacao_id||"",role:s.role||"usuario"}),c("confirm")):n(s.error||"Código inválido.")},S=async()=>{const s=await N(r,k);s.success?(c("success"),setTimeout(()=>{i("/dashboard"),window.location.reload()},2e3)):(n(s.error||"Erro ao ingressar na organização."),c("error"))},_=async()=>{await m.auth.signOut(),i("/login")},g=()=>{c("input"),u(null),n("")},E=s=>({admin:"Administrador",engenheiro:"Engenheiro",mestre_obra:"Mestre de Obra",usuario:"Usuário"})[s]||s;return e.jsxs("div",{className:"min-h-screen relative flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 overflow-hidden",children:[e.jsx(B,{}),e.jsxs("div",{className:"relative z-10 max-w-lg w-full space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"bg-white/10 backdrop-blur-md rounded-2xl shadow-lg border border-white/20 p-6 inline-block mb-4",children:e.jsx(O,{className:"w-16 h-16 text-blue-300 mx-auto"})}),e.jsxs("h1",{className:"text-3xl font-bold text-white mb-2",children:["Bem-vindo, ",y,"!"]}),e.jsx("p",{className:"text-blue-200 text-lg",children:"Para acessar o sistema, informe o código de convite da sua organização."})]}),e.jsxs("div",{className:"bg-white/10 backdrop-blur-md rounded-2xl shadow-2xl border border-white/20 p-8 transition-all duration-300",children:[l==="input"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(D,{className:"w-6 h-6 text-yellow-300"}),e.jsx("h2",{className:"text-xl font-semibold text-white",children:"Código de Convite"})]}),e.jsx("p",{className:"text-blue-200 text-sm",children:"Solicite o código de convite ao administrador da sua organização. O código é composto por 8 caracteres alfanuméricos."}),x&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-red-500/20 border border-red-400/30 rounded-xl",children:[e.jsx(f,{className:"w-5 h-5 text-red-300 flex-shrink-0"}),e.jsx("p",{className:"text-red-200 text-sm",children:x})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Digite o código"}),e.jsx("input",{type:"text",value:r,onChange:s=>v(s.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8)),placeholder:"Ex: A1B2C3D4",maxLength:8,className:"w-full px-4 py-4 bg-white/10 border border-white/20 rounded-xl text-white text-center text-2xl font-mono tracking-[0.3em] placeholder-blue-200/50 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-transparent backdrop-blur-sm transition-all duration-200 uppercase",onKeyDown:s=>s.key==="Enter"&&h(),autoFocus:!0})]}),e.jsx("button",{onClick:h,disabled:o||r.length<4,className:"w-full flex items-center justify-center gap-2 bg-gradient-to-r from-blue-500 to-purple-600 text-white py-3 px-6 rounded-xl hover:from-blue-600 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 shadow-lg hover:shadow-xl font-semibold",children:o?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"w-5 h-5 animate-spin"}),"Verificando..."]}):e.jsxs(e.Fragment,{children:["Verificar Código",e.jsx(V,{className:"w-5 h-5"})]})})]}),l==="confirm"&&d&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(F,{className:"w-6 h-6 text-green-300"}),e.jsx("h2",{className:"text-xl font-semibold text-white",children:"Confirmar Ingresso"})]}),e.jsxs("div",{className:"p-4 bg-green-500/10 border border-green-400/30 rounded-xl space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-green-200 text-sm",children:"Organização:"}),e.jsx("span",{className:"text-white font-semibold text-lg",children:d.organizacao_nome})]}),e.jsx("div",{className:"h-px bg-green-400/20"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-green-200 text-sm",children:"Seu cargo será:"}),e.jsx("span",{className:"text-white font-medium",children:E(d.role)})]}),e.jsx("div",{className:"h-px bg-green-400/20"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-green-200 text-sm",children:"Código:"}),e.jsx("span",{className:"text-white font-mono",children:r})]})]}),e.jsx("p",{className:"text-blue-200 text-sm text-center",children:"Deseja ingressar nesta organização?"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:g,disabled:o,className:"flex-1 py-3 px-4 bg-white/10 border border-white/20 text-white rounded-xl hover:bg-white/20 transition-all duration-200 font-medium",children:"Voltar"}),e.jsx("button",{onClick:S,disabled:o,className:"flex-1 flex items-center justify-center gap-2 bg-gradient-to-r from-green-500 to-emerald-600 text-white py-3 px-4 rounded-xl hover:from-green-600 hover:to-emerald-700 transition-all duration-200 font-semibold shadow-lg",children:o?e.jsxs(e.Fragment,{children:[e.jsx(b,{className:"w-5 h-5 animate-spin"}),"Ingressando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"w-5 h-5"}),"Confirmar"]})})]})]}),l==="success"&&e.jsxs("div",{className:"text-center space-y-4 py-4",children:[e.jsx(j,{className:"w-20 h-20 text-green-400 mx-auto animate-bounce"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:"Bem-vindo à equipe!"}),e.jsxs("p",{className:"text-green-200",children:["Você ingressou na organização ",e.jsx("strong",{children:d?.organizacao_nome})," com sucesso!"]}),e.jsx("p",{className:"text-blue-200 text-sm",children:"Redirecionando para o painel..."}),e.jsx("div",{className:"w-full bg-white/10 rounded-full h-2 overflow-hidden",children:e.jsx("div",{className:"bg-green-400 h-2 rounded-full animate-pulse w-2/3"})})]}),l==="error"&&e.jsxs("div",{className:"text-center space-y-4 py-4",children:[e.jsx(f,{className:"w-20 h-20 text-red-400 mx-auto"}),e.jsx("h2",{className:"text-2xl font-bold text-white",children:"Erro ao Ingressar"}),e.jsx("p",{className:"text-red-200",children:x}),e.jsx("button",{onClick:g,className:"mt-4 py-3 px-6 bg-white/10 border border-white/20 text-white rounded-xl hover:bg-white/20 transition-all duration-200 font-medium",children:"Tentar Novamente"})]})]}),e.jsx("div",{className:"text-center",children:e.jsxs("button",{onClick:_,className:"inline-flex items-center gap-2 text-blue-200 hover:text-white transition-colors duration-200 text-sm",children:[e.jsx(L,{className:"w-4 h-4"}),"Sair e usar outra conta"]})}),e.jsx("div",{className:"text-center text-sm text-gray-300",children:e.jsx("p",{className:"italic",children:"Desenvolvido por TrackSteel"})})]})]})};export{$ as default};
|