1import{j as e,a8 as I,ab as v,F as x,x as _,aB as w,n as c,ar as S,ac as B,y as C,z as h,a7 as b}from"./mui-CRsYZxVY.js";import{b as k,r as T}from"./vendor-Dwao9eNC.js";import{y as D,z as d,eS as F,ek as W,bc as q,C as N,D as p,el as O,b3 as R,F as L,u as z,w as A,b as K,T as M}from"./index-TALscxEc.js";import{b as V}from"./listaDeBancos-DVgYDDAw.js";import{L as $}from"./lab-DSem1Osk.js";import{a as U,b as J}from"./query-8ViTdhdk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};r.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new r.Error().stack;a&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[a]="92ca8319-6e1d-4323-bc7a-bec80a29eacd",r._sentryDebugIdIdentifier="sentry-dbid-92ca8319-6e1d-4323-bc7a-bec80a29eacd")})()}catch{}const P=r=>r&&r.normalize("NFD").replace(/[\u0300-\u036f]/g,"").trim().toUpperCase(),Q=D().shape({tipo_chave:d().required(),valor_chave:d().required("Informe a chave Pix").typeError("You must specify a number").when("tipo_chave",{is:"cpf",then:r=>r.test("cpf","O CPF informado não é válido",a=>F.isValid(a))}).when("tipo_chave",{is:"cnpj",then:r=>r.test("cnpj","O CNPJ informado não é válido",a=>W.isValid(a))}).when("tipo_chave",{is:"telefone",then:r=>r.test("telefone","O Telefone informado não é válido",a=>(a==null?void 0:a.length)===15)}).when("tipo_chave",{is:"aleatorio",then:r=>r.test("aleatorio","A chave informada não é válida",a=>(a==null?void 0:a.length)===36)}).when("tipo_chave",{is:"email",then:r=>r.email("O email informado não é válido").required()}),banco:d(),nome_recebedor:d().required("Digite o nome do recebedor").max(25,"O nome do recebedor deve ter no máximo 25 caracteres").transform(P),cidade:d().required("Digite a cidade do recebedor").max(15,"O nome da cidade deve ter no máximo 15 caracteres").transform(P)}),Y={cpf:"999.999.999-99",cnpj:"99.999.999/9999-99",telefone:"(99) 99999-9999",aleatorio:"********-****-****-****-************",email:""};function H({onSubmit:r,error:a,onFormReady:i}){const{isDesktop:t,drawerWidth:m}=q(),{control:s,handleSubmit:f,watch:u,register:g,setError:j,formState:{errors:o,isSubmitting:E}}=N({resolver:L(Q),defaultValues:{tipo_chave:"cpf",valor_chave:""}});k.useEffect(()=>{i&&i(j)},[i,j]);const y=u("tipo_chave");return e.jsxs("form",{onSubmit:f(r),children:[e.jsx(I,{}),e.jsxs(v,{spacing:3,children:[e.jsxs(x,{fullWidth:!0,error:!!o.banco,children:[e.jsx(_,{id:"bank-label",children:"Instituição financeira"}),e.jsx(p,{name:"banco",control:s,render:({field:n})=>e.jsxs(w,{...n,labelId:"bank-label",label:"Instituição financeira",children:[V.map(l=>e.jsx(c,{value:l.id,children:e.jsxs(v,{direction:"row",alignItems:"center",children:[e.jsx(S,{sx:{minWidth:36},children:e.jsx("img",{src:new URL(`${l.logo}`,import.meta.url).href,alt:l.nome,style:{width:18,height:18,marginRight:10}})}),e.jsx(B,{children:l.nome})]})},l.id)),e.jsx(c,{value:"outro",children:"Outro"})]})}),o.banco&&e.jsx(C,{children:o.banco.message})]}),e.jsxs(x,{fullWidth:!0,error:!!o.tipo_chave,children:[e.jsx(_,{children:"Tipo de chave Pix*"}),e.jsx(p,{name:"tipo_chave",control:s,render:({field:n})=>e.jsxs(w,{...n,label:"Tipo de chave Pix*",children:[e.jsx(c,{value:"cpf",children:"CPF"}),e.jsx(c,{value:"cnpj",children:"CNPJ"}),e.jsx(c,{value:"telefone",children:"Telefone"}),e.jsx(c,{value:"aleatorio",children:"Chave aleatória"}),e.jsx(c,{value:"email",children:"Email"})]})}),o.tipo_chave&&e.jsx(C,{children:o.tipo_chave.message})]}),e.jsx(x,{fullWidth:!0,error:!!o.valor_chave,children:e.jsx(p,{name:"valor_chave",control:s,render:({field:n})=>y!=="email"?e.jsx(O,{mask:Y[y],maskChar:null,onChange:n.onChange,value:n.value,onBlur:n.onBlur,children:l=>e.jsx(h,{...l,label:"Chave Pix*",fullWidth:!0,variant:"outlined",error:!!o.valor_chave,helperText:o.valor_chave?o.valor_chave.message:""})}):e.jsx(h,{...n,label:"Chave Pix*",fullWidth:!0,variant:"outlined",error:!!o.valor_chave,helperText:o.valor_chave?o.valor_chave.message:""})})}),e.jsx(h,{label:"Nome do recebedor*",fullWidth:!0,variant:"outlined",...g("nome_recebedor"),error:!!o.nome_recebedor,helperText:o.nome_recebedor?o.nome_recebedor.message:""}),e.jsx(h,{label:"Cidade*",fullWidth:!0,variant:"outlined",...g("cidade"),error:!!o.cidade,helperText:o.cidade?o.cidade.message:""}),a&&e.jsx(R,{severity:"error",children:a})]}),e.jsx(b,{sx:{position:"fixed",bottom:0,left:t?`${m}px`:0,right:0,p:2,pb:"calc(1rem + var(--safe-area-inset-bottom, 0px))",bgcolor:"white",borderTop:"1px solid",borderColor:"divider",zIndex:1300},children:e.jsx($,{type:"submit",variant:"contained",color:"primary",loading:E,size:"large",fullWidth:!0,sx:{py:1.5,textTransform:"none",fontWeight:600,fontSize:"1rem"},children:"Adicionar chave Pix"})})]})}const G=async(r,a)=>{if(!a)throw new Error("User must be logged in to create a Pix key.");const{data:i,error:t}=await A.from("chave_pix").insert({...r,user_id:a}).single();if(t)throw t.message.includes("unique_user_id_valor_chave")||t.message.includes("duplicate key value violates unique constraint")?new Error("Você já cadastrou uma chave Pix com este valor"):new Error(t.message);return i},X=()=>{const r=U(),{user:a}=z(),i=a==null?void 0:a.id;return J({mutationFn:t=>G(t,i),onSuccess:()=>{r.invalidateQueries({queryKey:["pixKeys"]})}})},se=()=>{const r=K(),[a,i]=T.useState(""),t=T.useRef(null),m=X();return e.jsxs(b,{sx:{overflow:"auto"},children:[e.jsx(M,{title:"Nova chave Pix",navigateBack:!0}),e.jsx(b,{sx:{px:2,py:2,pb:10,display:"flex",flexDirection:"column"},children:e.jsx(v,{spacing:2,children:e.jsx(H,{onSubmit:async s=>{try{await m.mutateAsync(s),i(""),t.current&&t.current("valor_chave",{message:""}),r(-1)}catch(f){const u=f.message||"Ocorreu um erro ao criar a chave Pix";i(u),t.current&&t.current("valor_chave",{type:"manual",message:u})}},error:a,onFormReady:s=>{t.current=s}})})})]})};export{se 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.