PageSourceSearch

https://democrata.org.br/sistema/assets/ValidarOTP-m22f7wwm.js

js democrata.org.br collected 2026-10-09 16:59:34 UTC 6,402 bytes, 1 lines download raw bytes

1import{m as P,cV as L,r as n,j as e,W as M,R as D,A as V,c as J}from"./index-DEXqc8fB.js";const K="pre_candidatura_otp_state",I="pre_candidatura_militar";function q(){var d,h;try{const g=localStorage.getItem(K);if(g)return JSON.parse(g);const s=localStorage.getItem(I);if(s){const u=JSON.parse(s);if((d=u.cadastro)!=null&&d.cpf&&((h=u.cadastro)!=null&&h.celular))return{dadosCadastro:u.cadastro,celularMascarado:"******",canal:"whatsapp"}}}catch{}}function F(){const d=P(),s=L().state||q(),[u,p]=n.useState(["","","","","",""]),[v,N]=n.useState(!1),[b,m]=n.useState(""),[x,w]=n.useState(60),[y,C]=n.useState(!1),[l,j]=n.useState(0),c=5,[S,E]=n.useState(!1),i=n.useRef([]);n.useEffect(()=>{var t;(!((t=s==null?void 0:s.dadosCadastro)!=null&&t.cpf)||!(s!=null&&s.celularMascarado))&&d("/pre-candidatura-publica")},[s,d]),n.useEffect(()=>{if(x>0){const t=setTimeout(()=>w(x-1),1e3);return()=>clearTimeout(t)}else C(!0)},[x]),n.useEffect(()=>{var t;(t=i.current[0])==null||t.focus()},[]);const R=(t,r)=>{var f;const a=r.replace(/\D/g,"").slice(-1),o=[...u];o[t]=a,p(o),m(""),a&&t<5&&((f=i.current[t+1])==null||f.focus()),a&&t===5&&o.every(_=>_!=="")&&T(o.join(""))},k=(t,r)=>{var a,o,f;r.key==="Backspace"&&!u[t]&&t>0&&((a=i.current[t-1])==null||a.focus()),r.key==="ArrowLeft"&&t>0&&((o=i.current[t-1])==null||o.focus()),r.key==="ArrowRight"&&t<5&&((f=i.current[t+1])==null||f.focus())},A=t=>{var a;t.preventDefault();const r=t.clipboardData.getData("text").replace(/\D/g,"").slice(0,6);if(r.length===6){const o=r.split("");p(o),m(""),(a=i.current[5])==null||a.focus(),T(r)}},T=async t=>{var r;if(s!=null&&s.dadosCadastro){if(l>=c){m("Limite de tentativas atingido. Solicite um novo código.");return}N(!0),m(""),j(a=>a+1);try{const a=await fetch("/api/v1/pre-candidatura-publica/validar-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cpf:s.dadosCadastro.cpf.replace(/\D/g,""),codigo:t})});if(!a.ok){const f=await a.json();throw a.status===429?(j(c),new Error("Muitas tentativas. Solicite um novo código.")):new Error(f.detail||"Código inválido")}const o=await a.json();d("/pre-candidatura-publica/criar-senha",{state:{dadosCadastro:s.dadosCadastro,tokenOTP:o.token}})}catch(a){m(a instanceof Error?a.message:"Código inválido"),p(["","","","","",""]),(r=i.current[0])==null||r.focus()}finally{N(!1)}}},O=async()=>{var t;if(!(!(s!=null&&s.dadosCadastro)||!y)){E(!0),m("");try{const r=await fetch("/api/v1/pre-candidatura-publica/solicitar-otp",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cpf:s.dadosCadastro.cpf.replace(/\D/g,""),celular:s.dadosCadastro.celular.replace(/\D/g,""),canal:s.canal})});if(!r.ok){const a=await r.json();throw new Error(a.detail||"Erro ao reenviar")}w(60),C(!1),j(0),p(["","","","","",""]),(t=i.current[0])==null||t.focus()}catch(r){m(r instanceof Error?r.message:"Erro ao reenviar")}finally{E(!1)}}};return s!=null&&s.dadosCadastro?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-blue-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"max-w-md w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 bg-gradient-to-br from-emerald-500 to-emerald-600 rounded-2xl mb-4 shadow-lg",children:e.jsx(M,{className:"w-8 h-8 text-white"})}),e.jsx("h1",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Digite o Código"}),e.jsxs("p",{className:"text-slate-600",children:["Enviamos um código de 6 dígitos para",e.jsx("br",{}),e.jsx("span",{className:"font-semibold text-slate-900",children:s.celularMascarado})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 p-8 shadow-sm",children:[e.jsx("div",{className:"flex justify-center gap-2 mb-6",children:u.map((t,r)=>e.jsx("input",{ref:a=>i.current[r]=a,type:"text",inputMode:"numeric",maxLength:1,value:t,onChange:a=>R(r,a.target.value),onKeyDown:a=>k(r,a),onPaste:A,disabled:v,className:`w-12 h-14 text-center text-2xl font-bold border-2 rounded-xl outline-none transition-all ${t?"border-emerald-500 bg-emerald-50 text-emerald-700":"border-slate-300 focus:border-blue-500"} disabled:opacity-50`},r))}),l>0&&l<c&&!b&&e.jsxs("p",{className:"mb-2 text-center text-xs text-slate-500",children:[c-l," de ",c," tentativas restantes"]}),b&&e.jsxs("div",{className:"mb-6 p-3 bg-red-50 border border-red-200 rounded-lg",children:[e.jsx("p",{className:"text-red-700 text-sm text-center",children:b}),l<c&&e.jsxs("p",{className:"text-red-500 text-xs text-center mt-1",children:[c-l," tentativa",c-l!==1?"s":""," restante",c-l!==1?"s":""]})]}),v&&e.jsxs("div",{className:"mb-6 flex items-center justify-center gap-2 text-blue-600",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-blue-600 border-t-transparent roun
1ded-full animate-spin"}),e.jsx("span",{className:"text-sm font-medium",children:"Validando..."})]}),e.jsx("div",{className:"text-center mb-6",children:y?e.jsx("button",{onClick:O,disabled:S,className:"inline-flex items-center gap-2 text-blue-600 hover:text-blue-700 font-medium disabled:opacity-50",children:S?e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-4 h-4 animate-spin"}),"Reenviando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"w-4 h-4"}),"Reenviar código"]})}):e.jsxs("p",{className:"text-slate-500 text-sm",children:["Reenviar código em"," ",e.jsxs("span",{className:"font-semibold text-slate-700",children:[x,"s"]})]})}),e.jsxs("button",{type:"button",onClick:()=>d(-1),className:"w-full py-3 border border-slate-300 text-slate-700 font-medium rounded-xl hover:bg-slate-50 flex items-center justify-center gap-2 transition-colors",children:[e.jsx(V,{className:"w-4 h-4"}),"Voltar"]})]}),e.jsx("div",{className:"mt-6 p-4 bg-blue-50 border border-blue-200 rounded-xl",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(J,{className:"w-5 h-5 text-blue-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-800",children:[e.jsx("p",{className:"font-medium mb-1",children:"Não recebeu o código?"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-blue-700",children:[e.jsx("li",{children:"Verifique se o número está correto"}),e.jsx("li",{children:"Aguarde alguns segundos para a mensagem chegar"}),e.jsx("li",{children:"Verifique a pasta de spam do WhatsApp"})]})]})]})})]})}):null}export{F 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.